ó
[³XMc           @   sÖ  d  Z  d d l Z d d l Z d d l Z d d l Z y d d l Z d d l Z Wn e k
 ro d Z Z n Xd d l
 m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ  d e j f d „  ƒ  YZ! d e j f d „  ƒ  YZ" d d3 d „  ƒ  YZ# d e j f d „  ƒ  YZ$ d e j f d  „  ƒ  YZ% d! e j& f d" „  ƒ  YZ' d# e j& f d$ „  ƒ  YZ( d% e' f d& „  ƒ  YZ) d' e* f d( „  ƒ  YZ+ d) e* f d* „  ƒ  YZ, d+ e j f d, „  ƒ  YZ- d- e j f d. „  ƒ  YZ. d/ e j f d0 „  ƒ  YZ/ d1 e j f d2 „  ƒ  YZ0 d S(4   s#   
Tests for L{twisted.python.util}.
iÿÿÿÿN(   t   unittest(   t   util(   t   reactor(   t   IReactorProcess(   t   ProcessProtocol(   t   Deferred(   t   ProcessDone(   t   MockOSt   UtilTestCasec           B   s‰   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k rT d e _
 n  d „  Z d „  Z e d k r~ d	 e _
 n  d
 „  Z RS(   c         C   sY   d d d d d d d d d d d g } |  j  t j | ƒ d d d d d d d g ƒ d  S(   Nt   ai   t   abi   i   i   i   (   t   assertEqualsR   t   uniquify(   t   selft   l(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testUniq   s    'c         C   s|   |  j  t j t t d d ƒ ƒ |  j t j t t d d ƒ ƒ y t j t t d d ƒ Wn t k
 rk n Xt j d ‚ d  S(   Ni   i    s,   util.raises didn't raise when it should have(	   t
   failUnlessR   t   raisest   ZeroDivisionErrort   divmodt   failIft	   TypeErrorR    t   FailTest(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt
   testRaises#   s    c            s§   ‡  f d †  } d  g ˆ  _ d ˆ  _ ˆ  j t j | d d ƒ d ƒ ˆ  j ˆ  j d ƒ d  t t g ˆ  _ d ˆ  _ ˆ  j t j | d d ƒ d ƒ ˆ  j ˆ  j d ƒ d  S(   Nc            sG   ˆ  j  d 7_  ˆ  j j ƒ  } | d  k	 r? | t j d ƒ ‚ n  |  | S(   Ni   s   Interrupted system call!(   t   callst
   exceptionst   popt   Nonet   errnot   EINTR(   R	   t   bt   exc(   R   (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   f/   s
    i    i   i   i   i   (   R   R   R   R   R   t   untilConcludest   OSErrort   IOError(   R   R    (    (   R   sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testUninterruptably.   s    		c         C   s_   d d d d d g } xC | D]; \ } } t  j | ƒ } |  j | | d | | | f ƒ q Wd S(   sK   
        Test the various kinds of inputs L{nameToLabel} supports.
        R    t   Ft   fot   Fot   foot   Foot   fooBars   Foo Bart	   fooBarBazs   Foo Bar Bazs   nameToLabel(%r) == %r != %rN(   R    R%   (   R&   R'   (   s   foos   Foo(   R*   s   Foo Bar(   R+   s   Foo Bar Baz(   R   t   nameToLabelR   (   R   t   nameDatat   inpt   outt   got(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testNameToLabel@   s    	c         C   s   |  j  t j d ƒ d ƒ d S(   s†   
        When L{uidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        t   100id   N(   t   assertEqualR   t   uidFromString(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_uidFromNumericStringR   s    c         C   s8   t  j t j ƒ  ƒ } |  j t j | j ƒ | j ƒ d S(   s†   
        When L{uidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        N(	   t   pwdt   getpwuidt   ost   getuidR3   R   R4   t   pw_namet   pw_uid(   R   t   pwent(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_uidFromUsernameStringZ   s    s0   Username/UID conversion requires the pwd module.c         C   s   |  j  t j d ƒ d ƒ d S(   s†   
        When L{gidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        R2   id   N(   R3   R   t   gidFromString(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_gidFromNumericStringf   s    c         C   s8   t  j t j ƒ  ƒ } |  j t j | j ƒ | j ƒ d S(   s†   
        When L{gidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        N(	   t   grpt   getgrgidR8   t   getgidR3   R   R>   t   gr_namet   gr_gid(   R   t   grent(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_gidFromGroupnameStringn   s    s2   Group Name/GID conversion requires the grp module.c         C   s~   t  j d d d d d i  ƒ |  j d |  j g ƒ } |  j | d d d	 ƒ |  j | d d
 t ƒ |  j t | ƒ d ƒ d S(   sR   
        Calling L{moduleMovedForSplit} results in a deprecation warning.
        R(   t   bart   bazt   quuxt   corget   offendingFunctionsi    t   messages4   moduleMovedForSplit is deprecated since Twisted 9.0.t   categoryi   N(   R   t   moduleMovedForSplitt   flushWarningst#   test_moduleMovedForSplitDeprecationR   t   DeprecationWarningt   len(   R   t   warnings(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRP   z   s    	N(   t   __name__t
   __module__R   R   R$   R1   R5   R=   R6   R   t   skipR?   RF   R@   RP   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR      s   								t   SwitchUIDTestc           B   se   e  Z d  Z e e d d	 ƒ d	 k r- d Z n  d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(
   s&   
    Tests for L{util.switchUID}.
    R9   s   getuid/setuid not availablec         C   sE   t  ƒ  |  _ |  j t d |  j ƒ |  j t d |  j ƒ g  |  _ d  S(   NR8   t
   initgroups(   R   t   mockost   patchR   RX   t   initgroupsCalls(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   setUp’   s    c         C   s   |  j  j | | f ƒ d S(   sK   
        Save L{util.initgroups} calls in C{self.initgroupsCalls}.
        N(   R[   t   append(   R   t   uidt   gid(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRX   ™   s    c         C   sC   t  j d d ƒ |  j |  j d g ƒ |  j |  j j d g ƒ d S(   sn   
        L{util.switchUID} calls L{util.initgroups} and then C{os.setuid} with
        the given uid.
        ià.  t   setuidN(   ià.  N(   s   setuidià.  (   R   t	   switchUIDR   R   R[   RY   t   actions(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_uid    s    c         C   sF   t  j d d t ƒ |  j |  j d g ƒ |  j |  j j d g ƒ d S(   sš   
        L{util.switchUID} calls L{util.initgroups} and then C{os.seteuid} with
        the given uid if the C{euid} parameter is set to C{True}.
        ià.  N(   ià.  N(   R   Ra   R   t   TrueR   R[   RY   t   seteuidCalls(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt	   test_euidª   s    c         C   s¯   |  j  j ƒ  } t j | d ƒ |  j |  j g  ƒ |  j |  j  j g  ƒ |  j t j g ƒ } |  j t	 | ƒ d ƒ |  j
 d | | d d ƒ |  j
 d | | d d ƒ d S(   sž   
        If the current uid is the same as the uid passed to L{util.switchUID},
        then initgroups does not get called, but a warning is issued.
        i   s&   tried to drop privileges and setuid %ii    RL   s   but uid is already %iN(   RY   R9   R   Ra   R   R   R[   Rb   RO   RR   t   assertIn(   R   R^   RS   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_currentUID´   s    c         C   s²   |  j  j ƒ  } t j | d t ƒ |  j |  j g  ƒ |  j |  j  j g  ƒ |  j	 t j g ƒ } |  j t
 | ƒ d ƒ |  j d | | d d ƒ |  j d | | d d ƒ d S(   s    
        If the current euid is the same as the euid passed to L{util.switchUID},
        then initgroups does not get called, but a warning is issued.
        i   s'   tried to drop privileges and seteuid %ii    RL   s   but euid is already %iN(   RY   t   geteuidR   Ra   R   Rd   R   R[   Re   RO   RR   Rg   (   R   t   euidRS   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_currentEUIDÄ   s    N(   RT   RU   t   __doc__t   getattrR8   R   RV   R\   RX   Rc   Rf   Rh   Rk   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRW   ‰   s   				
	
	t   TestMergeFunctionMetadatac           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s-   
    Tests for L{mergeFunctionMetadata}.
    c            sk   t  ƒ  ‰ t  ƒ  ‰  ‡ f d †  } d ‡  f d † } t j | | ƒ } |  j | d d d
 d d ƒˆ  ƒ d	 S(   st   
        After merging C{foo}'s data into C{bar}, the returned function behaves
        as if it is C{bar}.
        c              s   ˆ  S(   N(    (    (   t
   foo_object(    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR(   â   s    i
   c            s   | \ } } ˆ  S(   N(    (   t   xt   yt   .2t   ct   dt   eR	   R   (   t
   bar_object(    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRG   å   s    	i   i   i   i   RI   N(   i   i   (   t   objectR   t   mergeFunctionMetadatat   assertIdentical(   R   R(   RG   RH   (    (   Rv   Ro   sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt)   test_mergedFunctionBehavesLikeMergeTargetÚ   s    		c         C   sG   d „  } d „  } d | _  t j | | ƒ } |  j | j  | j  ƒ d S(   sd   
        Merging C{foo} into C{bar} returns a function with C{foo}'s
        C{__module__}.
        c           S   s   d  S(   N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR(   ñ   s    c           S   s   d  S(   N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRG   ô   s    s   somewhere.elseN(   RU   R   Rx   R3   (   R   R(   RG   RH   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_moduleIsMergedì   s
    			c         C   s>   d „  } d „  } t  j | | ƒ } |  j | j | j ƒ d S(   sX   
        Merging C{foo} into C{bar} returns a function with C{foo}'s docstring.
        c           S   s   d S(   s&   
            This is foo.
            N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR(     s    c           S   s   d S(   s&   
            This is bar.
            N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRG     s    N(   R   Rx   R3   Rl   (   R   R(   RG   RH   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_docstringIsMergedü   s    		c         C   s>   d „  } d „  } t  j | | ƒ } |  j | j | j ƒ d S(   sS   
        Merging C{foo} into C{bar} returns a function with C{foo}'s name.
        c           S   s   d  S(   N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR(     s    c           S   s   d  S(   N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRG     s    N(   R   Rx   R3   RT   (   R   R(   RG   RH   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_nameIsMerged  s    		c         C   sŽ   d „  } d | _  d | _ d „  } d | _ d | _ t j | | ƒ } |  j | j  | j  ƒ |  j | j | j ƒ |  j | j | j ƒ d S(   sv   
        Merging C{foo} into C{bar} returns a function with C{bar}'s
        dictionary, updated by C{foo}'s.
        c           S   s   d  S(   N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR(   $  s    i   i   c           S   s   d  S(   N(    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRG   )  s    i   i   N(   R	   R   Rs   R   Rx   R3   (   R   R(   RG   RH   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_instanceDictionaryIsMerged  s    						(   RT   RU   Rl   Rz   R{   R|   R}   R~   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRn   Õ   s   				t   OrderedDictTestc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s  t  j ƒ  } d | d <d | d <d | d <d | d <|  j t | ƒ d ƒ |  j | j ƒ  d d d d g ƒ | d =|  j t | ƒ d ƒ |  j | i d d 6d d 6d d 6ƒ |  j | j ƒ  d d d g ƒ |  j t | j ƒ  ƒ d	 d
 d g ƒ | j ƒ  } |  j | d ƒ d  S(   NR   R	   i   i   iá  iÒ  s'   {'a': 'b', 'b': 'a', 3: 12, 1234: 4321}s    {'a': 'b', 'b': 'a', 1234: 4321}(   R	   R   (   R   R	   (   iÒ  iá  (   iÒ  iá  (	   R   t   OrderedDictR   t   reprt   valuest   keyst   listt	   iteritemst   popitem(   R   Rt   t   item(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testOrderedDict6  s    



"%c         C   sb   t  j i d d 6d d 6ƒ } |  j | j ƒ t  j d
 d d d f ƒ } |  j t | ƒ d	 ƒ d  S(   Nt   ookt   monkeyt   redt   applei   i   i   i    s   {1: 1, 3: 3, 2: 2, 0: 0}(   i   i   (   i   i   (   i   i   (   i    i    (   R   R€   R   t   _orderR   R   (   R   Rt   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testInitializationG  s
    (   RT   RU   Rˆ   RŽ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR   5  s   	t   InsensitiveDictTestc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s[  t  j } | i d d 6d d 6i d d 6d 6d d ƒ} |  j | d i d d 6ƒ |  j | d d ƒ |  j | j ƒ  | ƒ |  j | d | j d ƒ ƒ d | k r± d | k s· t ‚ |  j t t | ƒ ƒ | ƒ d d d g } xH | D]@ } | | j ƒ  k st ‚ | | | f | j	 ƒ  k sé t ‚ qé W|  j t
 | ƒ t
 | ƒ ƒ | d =| d =d  S(   NRG   R)   i   i   t   fnzt   preserveR(   (   R   t   InsensitiveDictR   t   copyt   gett   AssertionErrort   evalR   Rƒ   t   itemsRR   (   R   R’   t   dctRƒ   Rp   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testPreserveP  s    	.&c         C   s¿   t  j } | i d d 6d d 6i d d 6d 6d d ƒ} d d d g } xH | D]@ } | | j ƒ  k sk t ‚ | | | f | j ƒ  k sM t ‚ qM W|  j t | ƒ t | ƒ ƒ | d =| d =d  S(	   NRG   R)   i   i   R   R‘   i    R(   (   R   R’   Rƒ   R•   R—   R   RR   (   R   R’   R˜   Rƒ   Rp   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testNoPreservea  s    	.&(   RT   RU   R™   Rš   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR   O  s   	t   PasswordTestingProcessProtocolc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s‘   
    Write the string C{"secret
"} to a subprocess and then collect all of
    its output and fire a Deferred with it when the process ends.
    c         C   s   g  |  _  |  j j d ƒ d  S(   Ns   secret
(   t   outputt	   transportt   write(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   connectionMadet  s    	c         C   s   |  j  j | | f ƒ d  S(   N(   Rœ   R]   (   R   t   fdRœ   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   childDataReceivedx  s    c         C   s   |  j  j | |  j f ƒ d  S(   N(   t   finishedt   callbackRœ   (   R   t   reason(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   processEnded{  s    (   RT   RU   Rl   RŸ   R¡   R¥   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR›   o  s   		t   GetPasswordTestc           B   s)   e  Z e j e ƒ s d  Z n  d „  Z RS(   s,   Process support required to test getPasswordc            sr   t  ƒ  } t ƒ  | _ t j | t j t j d d g d i t j j	 t j
 ƒ d 6ƒ‡  f d †  } | j j | ƒ S(   s.  
        Making sure getPassword accepts a password from standard input by
        running a child process which uses getPassword to read in a string
        which it then writes it out again.  Write a string to the child
        process and then read one and make sure it is the right string.
        s   -csj   import sys
from twisted.python.util import getPassword
sys.stdout.write(getPassword())
sys.stdout.flush()
t   envt
   PYTHONPATHc            s-   |  \ } } | j  t ƒ ˆ  j d | ƒ d  S(   Ni   t   secret(   i   R©   (   t   trapR   Rg   (   t   .0R¤   Rœ   (   R   (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   processFinished—  s    	(   R›   R   R¢   R   t   spawnProcesst   syst
   executableR8   t   pathsept   joint   patht   addCallback(   R   t   pR¬   (    (   R   sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt
   test_stdinƒ  s    		(   RT   RU   R   t
   providedByR   RV   Rµ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR¦     s   	t   SearchUpwardsTestc           B   s   e  Z d  „  Z RS(   c         C   s  t  j d ƒ t d d ƒ j ƒ  t d d ƒ j ƒ  t d d ƒ j ƒ  t  j d ƒ t  j d ƒ t  j d ƒ t  j d	 ƒ t j d d
 d g d d d g ƒ} t  j j d ƒ t  j	 } |  j
 | | ƒ t j d ƒ t j d d
 d g d d d g ƒ} d  } |  j
 | | ƒ d  S(   Ns   searchupwards/a/b/cs   searchupwards/foo.txtt   ws   searchupwards/a/foo.txts   searchupwards/a/b/c/foo.txts   searchupwards/bars   searchupwards/bams   searchupwards/a/bars   searchupwards/a/b/bamt   filess   foo.txtt   dirsRG   t   bamt   searchupwards(   R8   t   makedirst   filet   closet   mkdirR   R¼   R²   t   abspatht   sepR3   t   shutilt   rmtreeR   (   R   t   actualt   expected(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testSearchupwards   s&    		(   RT   RU   RÇ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR·   Ÿ  s   R)   c           B   s   e  Z d  „  Z RS(   c         C   s   | |  _  d  S(   N(   Rp   (   R   Rp   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   __init__¶  s    (   RT   RU   RÈ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR)   µ  s   t   DSUc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
    Tests for L{util.dsu}
    c         C   ss   g  t  d d d ƒ D] } t | ƒ ^ q } t j | d „  ƒ } |  j t  d d ƒ g  | D] } | j ^ qY ƒ d  S(   Ni   i	   iÿÿÿÿc         S   s   |  j  S(   N(   Rp   (   t   o(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   <lambda>¿  s    i
   i   (   t   rangeR)   R   t   dsuR   Rp   (   R   Rp   t   Lt   L2RÊ   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_dsu½  s    +c         C   s   |  j  t d t d „  ƒ d  S(   NsH   dsu is deprecated since Twisted 10.1. Use the built-in sorted() instead.c           S   s   t  j g  d „  ƒ S(   Nc           S   s   d S(   Ni    (    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRË   Ç  s    (   R   RÍ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRË   Ç  s    (   t   assertWarnsRQ   t   __file__(   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_deprecationÃ  s    	(   RT   RU   Rl   RÐ   RÓ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRÉ   ¹  s   	t   IntervalDifferentialTestCasec           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sI   t  t j g  d ƒ ƒ } x* t d ƒ D] } |  j | j ƒ  d ƒ q% Wd  S(   Ni
   id   (   i
   N(   t   iterR   t   IntervalDifferentialRÌ   R   t   nextR   (   R   Rt   t   i(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testDefaultÌ  s    c         C   sL   t  t j d g d ƒ ƒ } x* t d ƒ D] } |  j | j ƒ  d ƒ q( Wd  S(   Ni   i
   id   i    (   i   i    (   RÕ   R   RÖ   RÌ   R   R×   (   R   Rt   RØ   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt
   testSingleÑ  s    c         C   sA  t  t j d d g d ƒ ƒ } xt d ƒ D]} |  j | j ƒ  d
 ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ q+ Wd  S(   Ni   i   i
   id   i    i   i   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   i   i    (   i   i    (   i   i   (   i   i    (   i   i   (   i   i    (   i   i    (   i    i   (   RÕ   R   RÖ   RÌ   R   R×   (   R   Rt   RØ   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   testPairÖ  s    c         C   sÞ  t  t j d d d g d ƒ ƒ } x¶t d ƒ D]¨} |  j | j ƒ  d ƒ |  j | j ƒ  d	 ƒ |  j | j ƒ  d
 ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ q. Wd  S(   Ni   i   i   i
   id   i    i   (   i   i    (   i   i    (   i    i   (   i   i   (   i   i    (   i   i    (   i    i   (   i   i    (   i    i   (   i   i    (   i    i   (   i   i    (   i   i   (   i   i    (   i    i   (   i   i    (   i   i    (   i    i   (   i    i   (   RÕ   R   RÖ   RÌ   R   R×   (   R   Rt   RØ   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt
   testTripleæ  s*    !c         C   sü   t  t j g  d ƒ ƒ } |  j | j ƒ  d ƒ | j d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ | j d ƒ |  j | j ƒ  d	 ƒ |  j | j ƒ  d
 ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ d  S(   Ni
   i   i    i   i   (   i
   N(   i   i    (   i   i    (   i   i    (   i   i    (   i    i   (   i   i    (   i   i    (   i    i   (   RÕ   R   RÖ   R   R×   R   t   addInterval(   R   Rt   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt
   testInsertý  s    c         C   sÖ   t  t j d d g d ƒ ƒ } |  j | j ƒ  d ƒ |  j | j ƒ  d	 ƒ |  j | j ƒ  d
 ƒ | j d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ | j d ƒ |  j | j ƒ  d ƒ |  j t | j d ƒ d  S(   Ni   i   i
   i    i   i   i   (   i   i    (   i   i   (   i   i    (   i   i    (   i   i    (   i
   N(	   RÕ   R   RÖ   R   R×   t   removeIntervalR   t   assertRaisest
   ValueError(   R   Rt   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt
   testRemove  s    (   RT   RU   RÙ   RÚ   RÛ   RÜ   RÞ   Râ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRÔ   Ë  s   					t   Recordc           B   s   e  Z d  Z d Z d „  Z RS(   s8   
    Trivial user of L{FancyEqMixin} used by tests.
    R	   R   c         C   s   | |  _  | |  _ d  S(   N(   R	   R   (   R   R	   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRÈ     s    	(   R	   R   (   RT   RU   Rl   t   compareAttributesRÈ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRã     s   t   DifferentRecordc           B   s   e  Z d  Z d Z d „  Z RS(   sL   
    Trivial user of L{FancyEqMixin} which is not related to L{Record}.
    R	   R   c         C   s   | |  _  | |  _ d  S(   N(   R	   R   (   R   R	   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRÈ   +  s    	(   R	   R   (   RT   RU   Rl   Rä   RÈ   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRå   %  s   t   DerivedRecordc           B   s   e  Z d  Z RS(   s@   
    A class with an inheritance relationship to L{Record}.
    (   RT   RU   Rl   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRæ   1  s   t   EqualToEverythingc           B   s    e  Z d  Z d „  Z d „  Z RS(   sQ   
    A class the instances of which consider themselves equal to everything.
    c         C   s   t  S(   N(   Rd   (   R   t   other(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   __eq__<  s    c         C   s   t  S(   N(   t   False(   R   Rè   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   __ne__@  s    (   RT   RU   Rl   Ré   Rë   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRç   8  s   	t   EqualToNothingc           B   s    e  Z d  Z d „  Z d „  Z RS(   sN   
    A class the instances of which consider themselves equal to nothing.
    c         C   s   t  S(   N(   Rê   (   R   Rè   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRé   I  s    c         C   s   t  S(   N(   Rd   (   R   Rè   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRë   M  s    (   RT   RU   Rl   Ré   Rë   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRì   E  s   	t   EqualityTestsc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s$   
    Tests for L{FancyEqMixin}.
    c         C   s~   d t  j f d „  ƒ  Y} |  j | ƒ  | ƒ  k ƒ |  j | ƒ  | ƒ  k ƒ | ƒ  } |  j | | k ƒ |  j | | k ƒ d S(   s   
        Instances of a class which mixes in L{FancyEqMixin} but which
        defines no comparison attributes compare by identity.
        t   Emptyc           B   s   e  Z RS(    (   RT   RU   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRî   [  s   N(   R   t   FancyEqMixint   assertFalset
   assertTrue(   R   Rî   t   empty(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_identityV  s    	c         C   s˜   |  j  t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ d S(   sä   
        Instances of a class which mixes in L{FancyEqMixin} should compare
        equal if all of their attributes compare equal.  They should not
        compare equal if any of their attributes do not compare equal.
        i   i   i   i   N(   Rñ   Rã   Rð   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_equalitye  s    %%%c         C   s˜   |  j  t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ d S(   s   
        Unequality between instances of a particular L{record} should be
        defined as the negation of equality.
        i   i   i   i   N(   Rð   Rã   Rñ   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_unequalityq  s    %%%c         C   s)   |  j  t d d ƒ t d d ƒ k ƒ d S(   so   
        Instances of different classes which mix in L{FancyEqMixin} should not
        compare equal.
        i   i   N(   Rð   Rã   Rå   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_differentClassesEquality|  s    c         C   s)   |  j  t d d ƒ t d d ƒ k ƒ d S(   sm   
        Instances of different classes which mix in L{FancyEqMixin} should
        compare unequal.
        i   i   N(   Rñ   Rã   Rå   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_differentClassesInequality„  s    c         C   s˜   |  j  t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ d S(   sÞ   
        An instance of a class which derives from a class which mixes in
        L{FancyEqMixin} should compare equal to an instance of the base class
        if and only if all of their attributes compare equal.
        i   i   i   i   N(   Rñ   Rã   Ræ   Rð   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_inheritedClassesEqualityŒ  s    %%%c         C   s˜   |  j  t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ |  j t d d ƒ t d d ƒ k ƒ d S(   sÖ   
        An instance of a class which derives from a class which mixes in
        L{FancyEqMixin} should compare unequal to an instance of the base
        class if any of their attributes compare unequal.
        i   i   i   i   N(   Rð   Rã   Ræ   Rñ   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_inheritedClassesInequality˜  s    %%%c         C   sB   |  j  t d d ƒ t ƒ  k ƒ |  j t d d ƒ t ƒ  k ƒ d S(   sï   
        The right-hand argument to the equality operator is given a chance
        to determine the result of the operation if it is of a type
        unrelated to the L{FancyEqMixin}-based instance on the left-hand
        side.
        i   i   N(   Rñ   Rã   Rç   Rð   Rì   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt(   test_rightHandArgumentImplementsEquality¤  s    c         C   sB   |  j  t d d ƒ t ƒ  k ƒ |  j t d d ƒ t ƒ  k ƒ d S(   só   
        The right-hand argument to the non-equality operator is given a
        chance to determine the result of the operation if it is of a type
        unrelated to the L{FancyEqMixin}-based instance on the left-hand
        side.
        i   i   N(   Rð   Rã   Rç   Rñ   Rì   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt*   test_rightHandArgumentImplementsUnequality¯  s    (   RT   RU   Rl   Ró   Rô   Rõ   Rö   R÷   Rø   Rù   Rú   Rû   (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRí   R  s   								t   RunAsEffectiveUserTestsc           B   s‰   e  Z d  Z e e d d ƒ d k r- d Z n  d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s;   
    Test for the L{util.runAsEffectiveUser} function.
    Ri   s   geteuid/seteuid not availablec         C   st   t  ƒ  |  _ |  j t d |  j j ƒ |  j t d |  j j ƒ |  j t d |  j j ƒ |  j t d |  j j ƒ d  S(   NRi   t   getegidt   seteuidt   setegid(   R   RY   RZ   R8   Ri   Rý   Rþ   Rÿ   (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR\   Ã  s
    c         C   sV   |  j  | | k p% | |  j j d k ƒ |  j  | | k pN | |  j j d k ƒ d S(   sF   
        Check if wanted UID/GID matched start or saved ones.
        iÿÿÿÿN(   Rñ   RY   Re   t   setegidCalls(   R   t   startUIDt   startGIDt   wantUIDt   wantGID(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   _securedFunctionË  s    c         C   s,   t  j d d d „  ƒ } |  j | d ƒ d S(   so   
        L{util.runAsEffectiveUser} forwards the result obtained by calling the
        given function
        i    c           S   s   d S(   Ni   (    (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRË   Ú  s    i   N(   R   t   runAsEffectiveUserR   (   R   t   result(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_forwardResultÕ  s    c         C   s/   t  j d d d „  d ƒ } |  j | d ƒ d S(   se   
        L{util.runAsEffectiveUser} pass the given parameters to the given
        function.
        i    c         S   s   d |  S(   Ni   (    (   Rp   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRË   ã  s    i   i   N(   R   R  R   (   R   R  (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_takeParametersÞ  s    c         C   s;   t  j d d d d d „ d d d ƒ} |  j | d ƒ d S(	   sg   
        L{util.runAsEffectiveUser} pass the keyword parameters to the given
        function.
        i    i   c         S   s   |  | | S(   N(    (   Rp   Rq   t   z(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRË   ì  s    i   R
  i   i   N(   R   R  R   (   R   R  (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_takesKeyworkArgumentsç  s    'c         C   s‚   | |  j  _ | |  j  _ t j | | |  j | | | | ƒ |  j |  j  j | ƒ |  j |  j  j | ƒ g  |  j  _ g  |  j  _ d S(   sÏ   
        Helper method checking the calls to C{os.seteuid} and C{os.setegid}
        made by L{util.runAsEffectiveUser}, when switching from startUID to
        wantUID and from startGID to wantGID.
        N(	   RY   Rj   t   egidR   R  R  R   Re   R   (   R   R  R  R  R  t   expectedUIDSwitchest   expectedGIDSwitches(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   _testUIDGIDSwitchð  s    c         C   sŒ   |  j  d d d d g  g  ƒ |  j  d d d d d d g g  ƒ |  j  d d d d g  d d g ƒ |  j  d d d d d d g d d g ƒ d S(   sL   
        Check UID/GID switches when current effective UID is root.
        i    i   N(   R  (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt	   test_root  s    ""c      	   C   sž   |  j  d d d d d d g g  ƒ |  j  d d d d g  g  ƒ |  j  d d d d d d d d g d d g ƒ |  j  d d d d d d d d g d d g ƒ d S(   sP   
        Check UID/GID switches when current effective UID is non-root.
        i   i    i   N(   R  (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_UID  s    ".c         C   sŒ   |  j  d d d d g  d d g ƒ |  j  d d d d g  g  ƒ |  j  d d d d d d g g  ƒ |  j  d d d d d d g d d g ƒ d S(   sP   
        Check UID/GID switches when current effective GID is non-root.
        i    i   i   N(   R  (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_GID  s    ""c      	   C   s  |  j  d d d d d d g d d g ƒ |  j  d d d d d d g g  ƒ |  j  d d d d d d d d g d d g ƒ |  j  d d d d g  g  ƒ |  j  d d d d d d d d g g  ƒ |  j  d d d d d d d d g d d g ƒ |  j  d d d d d d d d g d d g ƒ d S(   sT   
        Check UID/GID switches when current effective UID/GID is non-root.
        i   i    i   N(   R  (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_UIDGID   s    (".(.N(   RT   RU   Rl   Rm   R8   R   RV   R\   R  R  R	  R  R  R  R  R  R  (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRü   »  s   			
								
	
	
t   UnsignedIDTestsc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sA   
    Tests for L{util.unsignedID} and L{util.setIDFunction}.
    c         C   s   |  j  t t d t j ƒ d S(   sv   
        Save the value of L{util._idFunction} and arrange for it to be restored
        after the test runs.
        t   _idFunctionN(   t
   addCleanupt   setattrR   R  (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR\   2  s    c         C   s;   t  ƒ  } t j | ƒ } t j | ƒ } |  j | | ƒ d S(   sL   
        L{util.setIDFunction} returns the last value passed to it.
        N(   Rw   R   t   setIDFunctionRy   (   R   t   valuet   previousR  (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_setIDFunction:  s    	c            s‡   t  ƒ  } t  ƒ  } i d | 6d | 6‰  ‡  f d †  } t j | ƒ |  j t j | ƒ d ƒ |  j t j | ƒ t j d d d ƒ d S(   sÇ   
        L{util.unsignedID} uses the function passed to L{util.setIDFunction} to
        determine the unique integer id of an object and then adjusts it to be
        positive if necessary.
        i   i·ÿÿÿc            s   ˆ  |  S(   N(    (   t   obj(   t   objects(    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   fakeIdO  s    i   i   iI   N(   Rw   R   R  R   t
   unsignedIDR®   t   maxint(   R   R(   RG   R  (    (   R  sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_unsignedIDD  s    		c         C   sV   t  ƒ  } t | ƒ } | d k  r9 | t j d d 7} n  |  j t j | ƒ | ƒ d S(   sH   
        L{util.unsignedID} uses the built in L{id} by default.
        i    i   i   N(   Rw   t   idR®   R   R   R   R  (   R   R  t   idValue(    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_defaultIDFunctionX  s
    	(   RT   RU   Rl   R\   R  R!  R$  (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR  .  s
   		
	t   InitGroupsTestsc           B   sb   e  Z d  Z e d k r! d Z n  d „  Z d „  Z d „  Z d „  Z	 e
 j d k r` d e	 _ n  RS(   s'   
    Tests for L{util.initgroups}.
    s   pwd not availablec         C   s6   |  j  t t d t j ƒ |  j  t t d t j ƒ d  S(   Nt   _c_initgroupst	   setgroups(   R  R  R   R&  R'  (   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR\   n  s    c            s}   g  ‰  ‡  f d †  t  _ g  } ˆ  j t  _ t  j t j ƒ  d ƒ |  j ˆ  t j	 t j ƒ  ƒ d d f g ƒ |  j
 | ƒ d S(   sw   
        If we fake the presence of the C extension, it's called instead of the
        Python implementation.
        c            s   ˆ  j  |  | f ƒ S(   N(   R]   (   Rp   Rq   (   R   (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyRË   y  s    i   i    N(   R   R&  R]   R'  RX   R8   R9   R   R6   R7   Rð   (   R   t   setgroupsCalls(    (   R   sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_initgroupsForceCs  s    ,c         C   sH   d t _ g  } | j t _ t j t j ƒ  t j ƒ  ƒ |  j	 | ƒ d S(   sŠ   
        If we fake the absence of the C extension, the Python implementation is
        called instead, calling C{os.setgroups}.
        N(
   R   R   R&  R]   R'  RX   R8   R9   RB   Rñ   (   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_initgroupsForcePython‚  s
    	c         C   sW   g  } | j  t _ y  t j t j ƒ  t j ƒ  ƒ Wn t k
 rE n X|  j | ƒ d S(   s    
        If the C extension is present, it's called instead of the Python
        version.  We check that by making sure C{os.setgroups} is not called.
        N(	   R]   R   R'  RX   R8   R9   RB   R"   Rð   (   R   R   (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   test_initgroupsInC  s     s   C initgroups not availableN(   RT   RU   Rl   R6   R   RV   R\   R)  R*  R+  R   R&  (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyR%  e  s   					(    (1   Rl   t   os.pathR8   R®   RÃ   R   R6   R@   t   ImportErrorR   t   twisted.trialR    t   twisted.pythonR   t   twisted.internetR   t   twisted.internet.interfacesR   t   twisted.internet.protocolR   t   twisted.internet.deferR   t   twisted.internet.errorR   t   twisted.test.test_processR   t   TestCaseR   RW   Rn   R   R   R›   R¦   R·   R)   RÉ   RÔ   Rï   Rã   Rå   Ræ   Rw   Rç   Rì   Rí   Rü   R  R%  (    (    (    sA   /usr/lib/python2.7/dist-packages/twisted/python/test/test_util.pyt   <module>   sD   lL`  Nis7