
    VhH                     $   d Z ddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZ ddlmZ 	 ddlZddlZeZe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dl!m"Z" ddl#m$Z$m%Z% ddl&m'Z(  e ejR                        jU                         Z+ G d de%      Z, G d de%      Z- G d de%      Z. e e/edd       d       G d de%             Z0 G d de%      Z1 G d de%      Z2 G d de%      Z3 G d d e      Z4 e ejj                  e       d!       G d" d#e%             Z6 G d$ d%e%      Z7 G d& d'e%      Z8 G d( d)ejr                        Z: G d* d+ejr                        Z; G d, d-e:      Z< G d. d/      Z= G d0 d1      Z> G d2 d3e%      Z? e e/ed4d       d5       G d6 d7e%             Z@ eej                   d8       G d9 d:e%             ZB G d; d<e%      ZC G d= d>e%      ZD G d? d@e%      ZE G dA dBe%      ZFy# e$ r dZdZY w xY w)Cz#
Tests for L{twisted.python.util}.
    N)IterableMappingMutableMappingSequence)skipIf)reactor)Deferred)ProcessDone)IReactorProcess)ProcessProtocol)util)FilePath)MockOS)FailTestTestCase)suppressc                   h    e Zd Zd Zd Zd Z eedu d      d        Zd Z	 ee
du d      d	        Zy)
	UtilTestsc                 Z    g d}| j                  t        j                  |      g d       y )N)a   abr         r      r   r      )r   r   r   r   r   r   r   )assertEqualr   uniquify)selflistWithDupess     M/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_util.pytestUniqzUtilTests.testUniq+   s!    @}57QR    c                 4   | j                  t        j                  t        t        dd             | j                  t        j                  t        t        dd             	 t        j                  t        t        dd       t        d      # t        $ r Y y w xY w)Nr   r   z,util.raises didn't raise when it should have)
assertTruer   raisesZeroDivisionErrordivmodassertFalse	TypeErrorr   r   s    r!   
testRaiseszUtilTests.testRaises/   sv    $5vq!DE%61EF	KKK	61a0 IJJ ! 		s     B 	BBc                 N    | j                  t        j                  d      d       y)
        When L{uidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        100d   N)r   r   uidFromStringr+   s    r!   test_uidFromNumericStringz#UtilTests.test_uidFromNumericString:       
 	++E2C8r#   Nz0Username/UID conversion requires the pwd module.c                     t         j                  t        j                               }| j	                  t        j                  |j                        |j                         y)r.   N)	pwdgetpwuidosgetuidr   r   r1   pw_namepw_uid)r   pwents     r!   test_uidFromUsernameStringz$UtilTests.test_uidFromUsernameStringA   ;     RYY[)++EMM:ELLIr#   c                 N    | j                  t        j                  d      d       y)
        When L{gidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        r/   r0   N)r   r   gidFromStringr+   s    r!   test_gidFromNumericStringz#UtilTests.test_gidFromNumericStringJ   r3   r#   z2Group Name/GID conversion requires the grp module.c                     t         j                  t        j                               }| j	                  t        j                  |j                        |j                         y)r?   N)	grpgetgrgidr7   getgidr   r   r@   gr_namegr_gid)r   grents     r!   test_gidFromGroupnameStringz%UtilTests.test_gidFromGroupnameStringQ   r=   r#   )__name__
__module____qualname__r"   r,   r2   r   r5   r<   rA   rC   rI    r#   r!   r   r   *   s^    S	K9 C4KKLJ MJ9 C4KMNJ OJr#   r   c                       e Zd ZdZd Zy)NameToLabelTestsz#
    Tests for L{nameToLabel}.
    c                     g d}|D ]6  \  }}t        j                  |      }| j                  ||d|d|d|       8 y)zK
        Test the various kinds of inputs L{nameToLabel} supports.
        ))fF)foFo)fooFoo)fooBarzFoo Bar)	fooBarBazzFoo Bar BazznameToLabel(z) == z != N)r   nameToLabelr   )r   nameDatainpoutgots        r!   test_nameToLabelz!NameToLabelTests.test_nameToLabel`   sU    
 ! 	VHC""3'CS#cWE#SG'TU	Vr#   N)rJ   rK   rL   __doc__r^   rM   r#   r!   rO   rO   [   s    Vr#   rO   c                       e Zd ZdZd Zy)UntilConcludesTestsz:
    Tests for L{untilConcludes}, an C{EINTR} helper.
    c                 l     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       y)a  
        L{untilConcludes} calls the function passed to it until the function
        does not raise either L{OSError} or L{IOError} with C{errno} of
        C{EINTR}.  It otherwise completes with the same result as the function
        passed to it.
        c                     xj                   dz  c_         j                  j                         }| |t        j                  d      | |z   S )Nr   zInterrupted system call!)calls
exceptionspoperrnoEINTR)r   bexcr   s      r!   rQ   z3UntilConcludesTests.test_uninterruptably.<locals>.f}   sB    JJ!OJ//%%'C%++'ABBq5Lr#   Nr   r   r   r      )re   rd   r   r   untilConcludesOSErrorIOError)r   rQ   s   ` r!   test_uninterruptablyz(UntilConcludesTests.test_uninterruptablyu   s    	  &
,,Q15q9Q''2
,,Q15q9Q'r#   N)rJ   rK   rL   r_   ro   rM   r#   r!   ra   ra   p   s    (r#   ra   r8   zgetuid/setuid not availablec                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	SwitchUIDTestsz&
    Tests for L{util.switchUID}.
    c                     t               | _        | j                  t        d| j                         | j                  t        d| j                         g | _        y )Nr7   
initgroups)r   mockospatchr   rs   initgroupsCallsr+   s    r!   setUpzSwitchUIDTests.setUp   s;    h

4t{{+

4t7!r#   c                 >    | j                   j                  ||f       y)zK
        Save L{util.initgroups} calls in C{self.initgroupsCalls}.
        N)rv   append)r   uidgids      r!   rs   zSwitchUIDTests.initgroups   s     	##S#J/r#   c                     t        j                  dd       | j                  | j                  dg       | j                  | j                  j
                  dg       y)zn
        L{util.switchUID} calls L{util.initgroups} and then C{os.setuid} with
        the given uid.
        .  Nr}   N)setuidr}   )r   	switchUIDr   rv   rt   actionsr+   s    r!   test_uidzSwitchUIDTests.test_uid   sH    
 	ud#--?,,/@.ABr#   c                     t        j                  ddd       | j                  | j                  dg       | j                  | j                  j
                  dg       y)z
        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}.
        r}   NTr~   )r   r   r   rv   rt   seteuidCallsr+   s    r!   	test_euidzSwitchUIDTests.test_euid   sH    
 	udD)--?11E7;r#   c                    | j                   j                         }t        j                  |d       | j	                  | j
                  g        | j	                  | j                   j                  g        | j                  t        j                  g      }| j	                  t        |      d       | j                  d|z  |d   d          | j                  d|z  |d   d          y)z
        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.
        Nr   z&tried to drop privileges and setuid %ir   messagezbut uid is already %i)
rt   r8   r   r   r   rv   r   flushWarningslenassertIn)r   rz   currentWarningss      r!   test_currentUIDzSwitchUIDTests.test_currentUID   s    
 kk  "sD!--r2,,b1,,dnn-=>_-q14s:Ay)	
 	-3_Q5G	5RSr#   c                    | j                   j                         }t        j                  |dd       | j	                  | j
                  g        | j	                  | j                   j                  g        | j                  t        j                  g      }| j	                  t        |      d       | j                  d|z  |d   d          | j                  d|z  |d   d          y)z
        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.
        NTr   z'tried to drop privileges and seteuid %ir   r   zbut euid is already %i)
rt   geteuidr   r   r   rv   r   r   r   r   )r   euidr   s      r!   test_currentEUIDzSwitchUIDTests.test_currentEUID   s    
 {{""$tT4(--r21126,,dnn-=>_-q15<Ay)	
 	.5q7I)7TUr#   N)
rJ   rK   rL   r_   rw   rs   r   r   r   r   rM   r#   r!   rq   rq      s(    "0C<T"Vr#   rq   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)MergeFunctionMetadataTestsz-
    Tests for L{mergeFunctionMetadata}.
    c                     t               t               fd}d	fd	}t        j                  ||      }| j                   |dddd             y)
zt
        After merging C{foo}'s data into C{bar}, the returned function behaves
        as if it is C{bar}.
        c                       S NrM   )
foo_objects   r!   rU   zQMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget.<locals>.foo   s	    r#   
   c                     |\  }}S r   rM   )	xyr   cder   ri   
bar_objects	           r!   barzQMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget.<locals>.bar   s    FQr#   r   r   )r   r   )quuxN)r   )objectr   mergeFunctionMetadataassertIs)r   rU   r   bazr   r   s       @@r!   )test_mergedFunctionBehavesLikeMergeTargetzDMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget   sJ    
 X
X
		 ((c2c!QR0*=r#   c                     d }d }d|_         t        j                  ||      }| j                  |j                   |j                          y)zd
        Merging C{foo} into C{bar} returns a function with C{foo}'s
        C{__module__}.
        c                       y r   rM   rM   r#   r!   rU   z;MergeFunctionMetadataTests.test_moduleIsMerged.<locals>.foo       r#   c                       y r   rM   rM   r#   r!   r   z;MergeFunctionMetadataTests.test_moduleIsMerged.<locals>.bar   r   r#   zsomewhere.elseN)rK   r   r   r   r   rU   r   r   s       r!   test_moduleIsMergedz.MergeFunctionMetadataTests.test_moduleIsMerged   s?    		 *((c28r#   c                     d }d }t        j                  ||      }| j                  |j                  |j                         y)zX
        Merging C{foo} into C{bar} returns a function with C{foo}'s docstring.
        c                       y)z&
            This is foo.
            NrM   rM   r#   r!   rU   z>MergeFunctionMetadataTests.test_docstringIsMerged.<locals>.foo      r#   c                       y)z&
            This is bar.
            NrM   rM   r#   r!   r   z>MergeFunctionMetadataTests.test_docstringIsMerged.<locals>.bar  r   r#   N)r   r   r   r_   r   s       r!   test_docstringIsMergedz1MergeFunctionMetadataTests.test_docstringIsMerged   s8    
	
	
 ((c2ckk2r#   c                     d }d }t        j                  ||      }| j                  |j                  |j                         y)zS
        Merging C{foo} into C{bar} returns a function with C{foo}'s name.
        c                       y r   rM   rM   r#   r!   rU   z9MergeFunctionMetadataTests.test_nameIsMerged.<locals>.foo  r   r#   c                       y r   rM   rM   r#   r!   r   z9MergeFunctionMetadataTests.test_nameIsMerged.<locals>.bar  r   r#   N)r   r   r   rJ   r   s       r!   test_nameIsMergedz,MergeFunctionMetadataTests.test_nameIsMerged  s8    
		 ((c2s||4r#   c                 X   d }d|_         d|_        d }d|_        d|_        t        j                  ||      }| j                  |j                   |j                          | j                  |j                  |j                         | j                  |j                  |j                         y)zv
        Merging C{foo} into C{bar} returns a function with C{bar}'s
        dictionary, updated by C{foo}'s.
        c                       y r   rM   rM   r#   r!   rU   zGMergeFunctionMetadataTests.test_instanceDictionaryIsMerged.<locals>.foo$  r   r#   r   r   c                       y r   rM   rM   r#   r!   r   zGMergeFunctionMetadataTests.test_instanceDictionaryIsMerged.<locals>.bar*  r   r#   r   r   N)r   ri   r   r   r   r   r   s       r!   test_instanceDictionaryIsMergedz:MergeFunctionMetadataTests.test_instanceDictionaryIsMerged  s    	 	 ((c2&&&r#   N)	rJ   rK   rL   r_   r   r   r   r   r   rM   r#   r!   r   r      s     >$9"3$5'r#   r   c                       e Zd ZdZd Zy)OrderedDictTestsz(
    Tests for L{util.OrderedDict}.
    c                     ddl m} | | j                  | j                  g      }| j	                  |d   d   d       | j	                  |d   d   t
               | j	                  t        |      d       y)	z4
        L{util.OrderedDict} is deprecated.
        r   )OrderedDictoffendingFunctionsr   zftwisted.python.util.OrderedDict was deprecated in Twisted 15.5.0: Use collections.OrderedDict instead.categoryr   N)twisted.python.utilr   r   test_deprecatedr   DeprecationWarningr   )r   r   r   s      r!   r   z OrderedDictTests.test_deprecated;  sx     	4,,AUAU@V,WAy);	

 	+J79KL_-q1r#   N)rJ   rK   rL   r_   r   rM   r#   r!   r   r   6  s    2r#   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)InsensitiveDictTestsz,
    Tests for L{util.InsensitiveDict}.
    c                 $   t        j                         }| j                  t        |t                     | j                  t        |t
                     | j                  t        |t                     | j                  t        |t                     y)zN
        L{util.InsensitiveDict} implements L{typing.MutableMapping}.
        N)	r   InsensitiveDictr%   
isinstancer   r   r   r)   r   )r   dcts     r!   test_abczInsensitiveDictTests.test_abcR  s`     ""$
312
301
378C23r#   c                    t        j                  ddddidd      }| j                  |d   ddi       | j                  |d   d       | j                  |j                         |       | j                  |d   |j	                  d             | j                  d|       | j                  d|       t        t        |      |t         j                  d	      }| j                  ||       g d
}|D ]G  }| j                  ||j                                | j                  |||   f|j                                I | j                  t        |      t        |             |d= |d= | j                  |j                         dg       y)zr
        L{util.InsensitiveDict} preserves the case of keys if constructed with
        C{preserve=True}.
        r   r   r   rV   r   fnzpreserver   rU   rV   )r   r   )rV   r   r   N)r   r   r   copygetr   evalreprkeysitemsr   )r   r   resultr   r   s        r!   test_preservez"InsensitiveDictTests.test_preserve\  sT   
 ""5Q1v#FQRSUaV,UU+S)USWWU^4aeS!I#'#7#7
 	%  	4AMM!SXXZ(MM1c!f+syy{3	4 	TCH-FJeW-r#   c                 t   t        j                  ddddidd      }g d}|D ]G  }| j                  ||j                                | j                  |||   f|j	                                I | j                  t        |      t        |             |d= |d= | j                  |j                         d	g       y
)z|
        L{util.InsensitiveDict} does not preserves the case of keys if
        constructed with C{preserve=False}.
        r   r   r   r   r   r   )rU   r   r   rU   r   N)r   r   r   r   r   r   r   )r   r   r   r   s       r!   test_noPreservez$InsensitiveDictTests.test_noPreserve{  s    
 ""5Q1v#FQRS  	4AMM!SXXZ(MM1c!f+syy{3	4 	TCH-FJeW-r#   c                     t        j                  d      }d|d<   | j                  |d   d       | j                  |j                         dg       y)z4
        Unicode keys are case insensitive.
        Fr   r   rV   FOOrU   Nr   r   r   r   r   r   s     r!   test_unicodez!InsensitiveDictTests.test_unicode  sI       %0%51%E7+r#   c                     t        j                  d      }d|d<   | j                  |d   d       | j                  |j                         dg       y)z2
        Bytes keys are case insensitive.
        Fr   r   s   Foos   FOOs   fooNr   r   s     r!   
test_byteszInsensitiveDictTests.test_bytes  sI       %0&	6A&F8,r#   N)	rJ   rK   rL   r_   r   r   r   r   r   rM   r#   r!   r   r   M  s     4.>.,-r#   r   c                   "    e Zd ZdZd Zd Zd Zy)PasswordTestingProcessProtocolz
    Write the string C{"secret\n"} to a subprocess and then collect all of
    its output and fire a Deferred with it when the process ends.
    c                 H    g | _         | j                  j                  d       y )Ns   secret
)output	transportwriter+   s    r!   connectionMadez-PasswordTestingProcessProtocol.connectionMade  s    [)r#   c                 >    | j                   j                  ||f       y r   )r   ry   )r   fdr   s      r!   childDataReceivedz0PasswordTestingProcessProtocol.childDataReceived  s    B<(r#   c                 R    | j                   j                  || j                  f       y r   )finishedcallbackr   )r   reasons     r!   processEndedz+PasswordTestingProcessProtocol.processEnded  s    45r#   N)rJ   rK   rL   r_   r   r   r   rM   r#   r!   r   r     s    
*)6r#   r   z,Process support required to test getPasswordc                       e Zd Zd Zy)GetPasswordTestsc           	      6    t               }t               |_        t        j                  |t
        t
        ddgdt        j                  j                  t        j                        j                  d      i        fd}|j                  j                  |      S )a.  
        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()
s
   PYTHONPATHutf8)envc                 ^    | \  }}|j                  t               j                  d|       y )N)r   s   secret)trapr
   r   )r   r   r   r   s      r!   processFinishedz4GetPasswordTests.test_stdin.<locals>.processFinished  s'    %VVKK$MM.&1r#   )r   r	   r   r   spawnProcesspyExer7   pathsepjoinsyspathencodeaddCallback)r   pr   s   `  r!   
test_stdinzGetPasswordTests.test_stdin  s|     +,Z
,		 

 9 @ @ HI	
 	2
 zz%%o66r#   N)rJ   rK   rL   r   rM   r#   r!   r   r     s    
7r#   r   c                       e Zd Zd Zy)SearchUpwardsTestsc                    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
gddg      }t         j                  j                  d      t         j                  z   }| j                  ||       t        j                  d       t        j                  dd
gddg      }d }| j                  ||       y )Nzsearchupwards/a/b/czsearchupwards/foo.txtwzsearchupwards/a/foo.txtzsearchupwards/a/b/c/foo.txtzsearchupwards/barzsearchupwards/bamzsearchupwards/a/barzsearchupwards/a/b/bamzfoo.txtr   bam)filesdirssearchupwards)r7   makedirsopenclosemkdirr   r  r   abspathsepr   shutilrmtree)r   actualexpecteds      r!   testSearchupwardsz$SearchUpwardsTests.testSearchupwards  s	   
)*$c*002&,224*C0668
$%
$%
&'
()##!)E5>
 77???3bff<*o&##!)E5>
 *r#   N)rJ   rK   rL   r  rM   r#   r!   r  r    s    +r#   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)IntervalDifferentialTestsc                     t        t        j                  g d            }t        d      D ]  }| j	                  t        |      d        y )Nr   r0   r   Niterr   IntervalDifferentialranger   nextr   r   is      r!   testDefaultz%IntervalDifferentialTests.testDefault  s@    **2r23s 	2AT!Wj1	2r#   c                     t        t        j                  dgd            }t        d      D ]  }| j	                  t        |      d        y )Nrk   r   r0   rk   r   r  r  s      r!   
testSinglez$IntervalDifferentialTests.testSingle  sB    **A334s 	.AT!Wf-	.r#   c                    t        t        j                  ddgd            }t        d      D ]G  }| j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d	       | j	                  t        |      d       | j	                  t        |      d
       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       J y )Nrk      r   r0   r!  r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r  r  s      r!   testPairz"IntervalDifferentialTests.testPair  s    **Aq6267s 	.AT!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-	.r#   c                 l   t        t        j                  g dd            }t        d      D ]  }| j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d       | j	                  t        |      d        y )	N)r   r   rk   r   r0   r*  r+  )r   r   r'  )r   r   r  r  s      r!   
testTriplez$IntervalDifferentialTests.testTriple  s   **9b9:s 	.AT!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-T!Wf-'	.r#   c                 l   t        t        j                  g d            }| j                  t	        |      d       |j                  d       | j                  t	        |      d       | j                  t	        |      d       |j                  d       | j                  t	        |      d       | j                  t	        |      d       | j                  t	        |      d       | j                  t	        |      d       | j                  t	        |      d       | j                  t	        |      d       y )Nr   r  r   r&  r   r+  )r  r   r  r   r  addIntervalr   s     r!   
testInsertz$IntervalDifferentialTests.testInsert  s    **2r23a*-	aa&)a&)	aa&)a&)a&)a&)a&)a&)r#   c                    t        t        j                  ddgd            }| j                  t	        |      d       | j                  t	        |      d       | j                  t	        |      d       |j                  d       | j                  t	        |      d       | j                  t	        |      d       |j                  d       | j                  t	        |      d	       | j                  t        |j
                  d       y )
Nr   rk   r   r&  r%  r'  r)  r!  r  )r  r   r  r   r  removeIntervalassertRaises
ValueErrorr   s     r!   
testRemovez$IntervalDifferentialTests.testRemove+  s    **Aq6267a&)a&)a&)	a&)a&)	a*-*a&6&6;r#   N)	rJ   rK   rL   r  r"  r,  r.  r1  r6  rM   r#   r!   r  r    s     2
.
. ..*
<r#   r  c                       e Zd ZdZdZd Zy)Recordz8
    Trivial user of L{FancyEqMixin} used by tests.
    r   ri   c                      || _         || _        y r   r9  r   r   ri   s      r!   __init__zRecord.__init__?      r#   NrJ   rK   rL   r_   compareAttributesr<  rM   r#   r!   r8  r8  8       #r#   r8  c                       e Zd ZdZdZd Zy)DifferentRecordzL
    Trivial user of L{FancyEqMixin} which is not related to L{Record}.
    r9  c                      || _         || _        y r   r9  r;  s      r!   r<  zDifferentRecord.__init__K  r=  r#   Nr>  rM   r#   r!   rB  rB  D  r@  r#   rB  c                       e Zd ZdZy)DerivedRecordz@
    A class with an inheritance relationship to L{Record}.
    N)rJ   rK   rL   r_   rM   r#   r!   rE  rE  P  s    r#   rE  c                        e Zd ZdZdedefdZy)EqualToEverythingzQ
    A class the instances of which consider themselves equal to everything.
    otherreturnc                      y)NTrM   r   rH  s     r!   __eq__zEqualToEverything.__eq__[  s    r#   NrJ   rK   rL   r_   r   boolrL  rM   r#   r!   rG  rG  V  s    F t r#   rG  c                        e Zd ZdZdedefdZy)EqualToNothingzN
    A class the instances of which consider themselves equal to nothing.
    rH  rI  c                      y)NFrM   rK  s     r!   rL  zEqualToNothing.__eq__d  s    r#   NrM  rM   r#   r!   rP  rP  _  s    F t r#   rP  c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)EqualityTestsz$
    Tests for L{FancyEqMixin}.
    c                     G d dt         j                        }| j                   |        |       k(         | j                   |        |       k7          |       }| j                  ||k(         | j                  ||k7         y)z
        Instances of a class which mixes in L{FancyEqMixin} but which
        defines no comparison attributes compare by identity.
        c                       e Zd Zy)*EqualityTests.test_identity.<locals>.EmptyN)rJ   rK   rL   rM   r#   r!   EmptyrV  s  s    r#   rW  N)r   FancyEqMixinr)   r%   )r   rW  emptys      r!   test_identityzEqualityTests.test_identitym  sk    	D%% 	 	EG+,57*+'%(r#   c                 D   | 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(         y)z
        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.
        r   r   r   r   N)r%   r8  r)   r+   s    r!   test_equalityzEqualityTests.test_equality|  s~     	q!q!45115611561156r#   c                 D   | j                  t        dd      t        dd      k7         | j                  t        dd      t        dd      k7         | j                  t        dd      t        dd      k7         | j                  t        dd      t        dd      k7         y)z
        Inequality between instances of a particular L{record} should be
        defined as the negation of equality.
        r   r   r   r   N)r)   r8  r%   r+   s    r!   test_unequalityzEqualityTests.test_unequality  sz    
 	1156q!q!45q!q!45q!q!45r#   c                 T    | j                  t        dd      t        dd      k(         y)zo
        Instances of different classes which mix in L{FancyEqMixin} should not
        compare equal.
        r   r   N)r)   r8  rB  r+   s    r!   test_differentClassesEqualityz+EqualityTests.test_differentClassesEquality  s$    
 	1A)>>?r#   c                 T    | j                  t        dd      t        dd      k7         y)zm
        Instances of different classes which mix in L{FancyEqMixin} should
        compare unequal.
        r   r   N)r%   r8  rB  r+   s    r!   test_differentClassesInequalityz-EqualityTests.test_differentClassesInequality  s"    
 	q!1(==>r#   c                 D   | 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(         y)z
        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.
        r   r   r   r   N)r%   r8  rE  r)   r+   s    r!   test_inheritedClassesEqualityz+EqualityTests.test_inheritedClassesEquality  s     	q!a(;;<1q!)<<=1q!)<<=1q!)<<=r#   c                 D   | j                  t        dd      t        dd      k7         | j                  t        dd      t        dd      k7         | j                  t        dd      t        dd      k7         | j                  t        dd      t        dd      k7         y)z
        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.
        r   r   r   r   N)r)   r8  rE  r%   r+   s    r!   test_inheritedClassesInequalityz-EqualityTests.test_inheritedClassesInequality  s~     	1q!)<<=q!a(;;<q!a(;;<q!a(;;<r#   c                     | j                  t        dd      t               k(         | j                  t        dd      t	               k(         y)z
        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.
        r   r   N)r%   r8  rG  r)   rP  r+   s    r!   (test_rightHandArgumentImplementsEqualityz6EqualityTests.test_rightHandArgumentImplementsEquality  s;     	q!(9(;;<1)99:r#   c                     | j                  t        dd      t               k7         | j                  t        dd      t	               k7         y)z
        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.
        r   r   N)r)   r8  rG  r%   rP  r+   s    r!   *test_rightHandArgumentImplementsUnequalityz8EqualityTests.test_rightHandArgumentImplementsUnequality  s;     	1):)<<=q!(889r#   N)rJ   rK   rL   r_   rZ  r\  r^  r`  rb  rd  rf  rh  rj  rM   r#   r!   rS  rS  h  s5    )	76@?	>	=;:r#   rS  r   zgeteuid/seteuid not availablec                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)RunAsEffectiveUserTestsz;
    Test for the L{util.runAsEffectiveUser} function.
    c                 z   t               | _        | j                  t        d| j                  j                         | j                  t        d| j                  j
                         | j                  t        d| j                  j                         | j                  t        d| j                  j                         y )Nr   getegidseteuidsetegid)r   rt   ru   r7   r   rn  ro  rp  r+   s    r!   rw   zRunAsEffectiveUserTests.setUp  ss    h

2y$++"5"56

2y$++"5"56

2y$++"5"56

2y$++"5"56r#   c                     | j                  ||k(  xs || j                  j                  d   k(         | j                  ||k(  xs || j                  j                  d   k(         y)zF
        Check if wanted UID/GID matched start or saved ones.
        N)r%   rt   r   setegidCalls)r   startUIDstartGIDwantUIDwantGIDs        r!   _securedFunctionz(RunAsEffectiveUserTests._securedFunction  sZ     	8+Vw$++:R:RSU:V/VW8+Vw$++:R:RSU:V/VWr#   c                 X    t        j                  ddd       }| j                  |d       y)zo
        L{util.runAsEffectiveUser} forwards the result obtained by calling the
        given function
        r   c                       y)Nr   rM   rM   r#   r!   <lambda>z<RunAsEffectiveUserTests.test_forwardResult.<locals>.<lambda>  r   r#   r   Nr   runAsEffectiveUserr   r   r   s     r!   test_forwardResultz*RunAsEffectiveUserTests.test_forwardResult  s(    
 ((Ay9#r#   c                 Z    t        j                  ddd d      }| j                  |d       y)ze
        L{util.runAsEffectiveUser} pass the given parameters to the given
        function.
        r   c                     d| z  S )Nr   rM   )r   s    r!   r{  z=RunAsEffectiveUserTests.test_takeParameters.<locals>.<lambda>  s
    Q r#   r   r   Nr|  r~  s     r!   test_takeParametersz+RunAsEffectiveUserTests.test_takeParameters  s*    
 ((AB#r#   c                 `    t        j                  dddddd      }| j                  |d       y)	zg
        L{util.runAsEffectiveUser} pass the keyword parameters to the given
        function.
        r   c                     | |z  |z  S r   rM   )r   r   zs      r!   r{  zDRunAsEffectiveUserTests.test_takesKeyworkArguments.<locals>.<lambda>  s    1q519 r#   r   r   )r  r   Nr(  r|  r~  s     r!   test_takesKeyworkArgumentsz2RunAsEffectiveUserTests.test_takesKeyworkArguments  s.    
 ((A/LaSTU#r#   c           	      n   || j                   _        || j                   _        t        j                  ||| j
                  ||||       | j                  | j                   j                  |       | j                  | j                   j                  |       g | j                   _        g | j                   _        y)z
        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)	rt   r   egidr   r}  rx  r   r   rs  )r   rt  ru  rv  rw  expectedUIDSwitchesexpectedGIDSwitchess          r!   _testUIDGIDSwitchz)RunAsEffectiveUserTests._testUIDGIDSwitch  s     $#!!	
 	113FG113FG#% #% r#   c           	          | 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       y)zL
        Check UID/GID switches when current effective UID is root.
        r   r   Nr  r+   s    r!   	test_rootz!RunAsEffectiveUserTests.test_root  st     	q!Q2r2q!QAq626q!Q21v6q!QAq6Aq6:r#   c           	          | j                  ddddddgg        | j                  ddddg g        | j                  ddddg dddg       | j                  ddddg dddg       y)zP
        Check UID/GID switches when current effective UID is non-root.
        r   r   r   r   r   r   r   r   r   r   r   Nr  r+   s    r!   test_UIDz RunAsEffectiveUserTests.test_UID  sp     	q!QAq626q!Q2r2q!Q<!Q@q!Q<!Q@r#   c           	          | 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       y)zP
        Check UID/GID switches when current effective GID is non-root.
        r   r   r   Nr  r+   s    r!   test_GIDz RunAsEffectiveUserTests.test_GID&  st     	q!Q21v6q!Q2r2q!QAq626q!QAq6Aq6:r#   c           	      `   | 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g dddg       | j                  ddddg g        | j                  ddddg dg        | j                  ddddg dddg       | j                  ddddg dddg       y)zT
        Check UID/GID switches when current effective UID/GID is non-root.
        r   r   r  r   r  Nr  r+   s    r!   test_UIDGIDz#RunAsEffectiveUserTests.test_UIDGID/  s     	q!QAq6Aq6:q!QAq626q!Q<!Q@q!Q2r2q!Q<<q!Q<!Q@q!Q<!Q@r#   N)rJ   rK   rL   r_   rw   rx  r  r  r  r  r  r  r  r  rM   r#   r!   rl  rl    s<    7X$$$&<;A;
Ar#   rl  z.stdlib support for initgroups is not availablec                       e Zd ZdZd Zd Zy)InitGroupsTestsz'
    Tests for L{util.initgroups}.
    c                    g fd}| j                  t        d|       g }| j                  t        d|j                         t        j                  t	        j
                         d       | j                  t        j                  t	        j
                               j                  dfg       | j                  |       y)zc
        Calling L{util.initgroups} will call the underlying stdlib
        implmentation.
        c                 ,    j                  | |f       y r   )ry   )r   r   rd   s     r!   mockInitgroupsz?InitGroupsTests.test_initgroupsInStdlib.<locals>.mockInitgroupsI  s    LL!Q r#   _initgroups	setgroupsr   N)ru   r   ry   rs   r7   r8   r   r5   r6   r9   r)   )r   r  setgroupsCallsrd   s      @r!   test_initgroupsInStdlibz'InitGroupsTests.test_initgroupsInStdlibB  s    
 	! 	

47

4n&;&;<		Q'#,,ryy{";"C"CQ!G HI(r#   c                 t    | j                  t        t        j                  t	        j
                         d       y)zN
        Calling L{util.initgroups} with None for gid gives an error.
        N)r4  r*   r   rs   r7   r8   r+   s    r!   test_initgroupsNoneGidz&InitGroupsTests.test_initgroupsNoneGidT  s"     	)T__biik4Hr#   N)rJ   rK   rL   r_   r  r  rM   r#   r!   r  r  <  s    )$Ir#   r  c                   <    e Zd ZdZd Zd Z eed      ge_        y)DeprecationTestsz;
    Tests for deprecations in C{twisted.python.util}.
    c                    t        j                          | j                  | j                  g      }| j	                  |d   d   d       | j	                  |d   d   t
               | j	                  t        |      d       y)z6
        L{util.getPluginDirs} is deprecated.
        r   r   r   zCtwisted.python.util.getPluginDirs is deprecated since Twisted 12.2.r   r   N)r   getPluginDirsr   test_getPluginDirsr   r   r   r   r   s     r!   r  z#DeprecationTests.test_getPluginDirs`  s     	,, $ 7 78 - 
 	Ay)T	
 	+J79KL_-q1r#   c                    t        j                          | j                  | j                  g      }| j	                  |d   d   d       | j	                  |d   d   t
               | j	                  t        |      d       y)z5
        L{util.addPluginDir} is deprecated.
        r   r   r   zBtwisted.python.util.addPluginDir is deprecated since Twisted 12.2.r   r   N)r   addPluginDirr   test_addPluginDirr   r   r   r  s     r!   r  z"DeprecationTests.test_addPluginDiro  s     	,, $ 6 67 - 
 	Ay)S	
 	+J79KL_-q1r#   z/twisted.python.util.getPluginDirs is deprecated)r   r   N)	rJ   rK   rL   r_   r  r  SUPPRESSr   r   rM   r#   r!   r  r  [  s,    22  	'E	
"r#   r  c                   L    e Zd ZdZ eej                        Zd Zd Zd Z	d Z
y)SuppressedWarningsTestsz6
    Tests for L{util.runWithWarningsSuppressed}.
    c                     di fdi fg}| j                  |t        j                  d       | j                  |t        j                  d       | j                  g | j	                                y)z
        Warnings from the function called by C{runWithWarningsSuppressed} are
        suppressed if they match the passed in filter.
        ignorez.*foo.*r  z.*bar.*
ignore fooz
ignore barNrunWithWarningsSuppressedwarningswarnr   r   )r   filterss     r!   &test_runWithWarningsSuppressedFilteredz>SuppressedWarningsTests.test_runWithWarningsSuppressedFiltered  s^    
 *2.1F0KL&&w|L&&w|LT//12r#   c                     di fdi fg}| j                  |t        j                  d       | j                  dg| j	                         D cg c]  }|d   	 c}       yc c}w )z
        Warnings from the function called by C{runWithWarningsSuppressed} are
        not suppressed if they do not match the passed in filter.
        r  r  zdon't ignorer   Nr  r   r  r  s      r!   (test_runWithWarningsSuppressedUnfilteredz@SuppressedWarningsTests.test_runWithWarningsSuppressedUnfiltered  s]    
 *2.1F0KL&&w~N.)$BTBTBV+WQAiL+WX+Ws   	A
c                 J    | j                  | j                  g d       d       y)zd
        C{runWithWarningsSuppressed} returns the result of the function it
        called.
        c                       y)Nr   rM   rM   r#   r!   r{  z:SuppressedWarningsTests.test_passThrough.<locals>.<lambda>  r   r#   r   N)r   r  r+   s    r!   test_passThroughz(SuppressedWarningsTests.test_passThrough  s!    
 	77IFJr#   c                     di fdi fg}| j                  |d        t        j                  d       | j                  dg| j	                         D cg c]  }|d   	 c}       yc c}w )zk
        Once C{runWithWarningsSuppressed} has returned, it no longer
        suppresses warnings.
        r  r  c                       y r   rM   rM   r#   r!   r{  z<SuppressedWarningsTests.test_noSideEffects.<locals>.<lambda>  r   r#   r  r   Nr  r  s      r!   test_noSideEffectsz*SuppressedWarningsTests.test_noSideEffects  sb    
 *2.1F0KL&&w=l#,@R@R@T)U1!I,)UV)Us   A$
N)rJ   rK   rL   r_   staticmethodr   r  r  r  r  r  rM   r#   r!   r  r    s1     !-T-K-K L3YKWr#   r  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)FancyStrMixinTestsz*
    Tests for L{util.FancyStrMixin}.
    c                 v     G d dt         j                        }| j                  t         |             d       y)z
        If C{showAttributes} is set to a sequence of strings, C{__str__}
        renders using those by looking them up as attributes on the object.
        c                       e Zd ZdZdZdZy)6FancyStrMixinTests.test_sequenceOfStrings.<locals>.Foofirstsecondr   helloNrJ   rK   rL   showAttributesr  r  rM   r#   r!   rV   r        0NEFr#   rV   z<Foo first=1 second='hello'>Nr   FancyStrMixinr   strr   rV   s     r!   test_sequenceOfStringsz)FancyStrMixinTests.test_sequenceOfStrings  s-    	$$$ 	
 	SU%CDr#   c                 v     G d dt         j                        }| j                  dt         |                    y)a  
        If C{showAttributes} has an item that is a 2-tuple, C{__str__} renders
        the first item in the tuple as a key and the result of calling the
        second item with the value of the attribute named by the first item as
        the value.
        c                   "    e Zd Zddd ffZdZdZy).FancyStrMixinTests.test_formatter.<locals>.Foor  r  c                 $    t        | d d d         S )Nrr  )r   )values    r!   r{  z7FancyStrMixinTests.test_formatter.<locals>.Foo.<lambda>  s    U4R4[@Q r#   r  worldNr  rM   r#   r!   rV   r    s    %2Q'RSNEFr#   rV   z"<Foo first='hello' second='dlrow'>Nr  r  s     r!   test_formatterz!FancyStrMixinTests.test_formatter  s-    	$$$ 	
 	=s35zJr#   c                 v     G d dt         j                        }| j                  t         |             d       y)a&  
        If C{showAttributes} has an item that is a 3-tuple, C{__str__} renders
        the second item in the tuple as a key, and the contents of the
        attribute named in the first item are rendered as the value. The value
        is formatted using the third item in the tuple.
        c                       e Zd ZdZdZdZy)-FancyStrMixinTests.test_override.<locals>.Foo)r  )r  2ndz%.1fr   gS @Nr  rM   r#   r!   rV   r    s    ANEFr#   rV   z<Foo first=1 2nd=2.1>Nr  r  s     r!   test_overridez FancyStrMixinTests.test_override  s-    	$$$ 	
 	SU%<=r#   c                 v     G d dt         j                        }| j                  t         |             d       y)z_
        If C{fancybasename} is present, C{__str__} uses it instead of the class name.
        c                       e Zd ZdZy)2FancyStrMixinTests.test_fancybasename.<locals>.FooBarN)rJ   rK   rL   fancybasenamerM   r#   r!   rV   r    s    !Mr#   rV   z<Bar>Nr  r  s     r!   test_fancybasenamez%FancyStrMixinTests.test_fancybasename  s,    
	"$$$ 	" 	SUW-r#   c                      G d dt         j                        } |       }| j                  t        |      t	        |             y)zE
        C{__repr__} outputs the same content as C{__str__}.
        c                       e Zd ZdZdZdZy))FancyStrMixinTests.test_repr.<locals>.Foor  r   r  Nr  rM   r#   r!   rV   r    r  r#   rV   N)r   r  r   r  r   )r   rV   objs      r!   	test_reprzFancyStrMixinTests.test_repr  s5    
	$$$ 	
 eS49-r#   N)	rJ   rK   rL   r_   r  r  r  r  r  rM   r#   r!   r  r    s"    EK>..r#   r  c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)

PadToTestsz"
    Tests for L{util.padTo}.
    c                 \    t        j                  dg       }| j                  dgdz  |       y)ze
        L{None} values can be added to a list to cause it to have a certain
        length.
        r   Nr   padTor   r   paddeds     r!   test_defaultzPadToTests.test_default  s*    
 Ar"$!V,r#   c                 ^    t        j                  dg d      }| j                  dgdz  |       y)zg
        A specific value can be added to a list to cause it to have a certain
        length.
        r   r   Nr  r  s     r!   test_specificDefaultValuez$PadToTests.test_specificDefaultValue  s,    
 Ar3'#F+r#   c                 ^    t        j                  dddgd      }| j                  g d|       y)zl
        A list which already has some items has the padding value added after
        those items.
        r   r   r   r  )r   r   r  Nr  r  s     r!   test_padNonEmptyListzPadToTests.test_padNonEmptyList  s*    
 A1vs+f-r#   c                 T    | j                  t        t        j                  dddg       y)z{
        L{util.padTo} can't pad a list if the size requested is smaller than
        the size of the list to pad.
        r   r   N)r4  r5  r   r  r+   s    r!   test_padToSmallerSizez PadToTests.test_padToSmallerSize  s     
 	*djj!aV<r#   c                 n    ddg}t        j                  t        |      |      }| j                  ||       y)z
        If the list is already the length indicated by the padding argument
        then a list with the same value is returned.
        r   r   N)r   r  r   r   r   r   r  s      r!   test_alreadyPaddedzPadToTests.test_alreadyPadded  s1    
 ACJ.'r#   c                 n    ddg}t        j                  t        |      |      }| j                  ||       y)z
        If the list is already the length indicated by the padding argument
        then the return value is a copy of the input.
        r   r   N)r   r  r   assertIsNotr  s      r!   test_alreadyPaddedCopiesz#PadToTests.test_alreadyPaddedCopies'  s1    
 ACJ.'r#   c                 X    g }t        j                  d|       | j                  g |       y)zO
        L{util.padTo} doesn't modify the input list but makes a copy.
        r   Nr  )r   r   s     r!   test_makeCopyzPadToTests.test_makeCopy0  s'     

1eU#r#   N)rJ   rK   rL   r_   r  r  r  r  r  r  r   rM   r#   r!   r  r    s*    -,.=(($r#   r  )Gr_   rg   os.pathr7   r  r   r  typingr   r   r   r   unittestr   rC   _grpr5   _pwdImportErrortwisted.internetr   twisted.internet.deferr	   twisted.internet.errorr
   twisted.internet.interfacesr   twisted.internet.protocolr   twisted.pythonr   twisted.python.filepathr   twisted.test.test_processr   twisted.trial.unittestr   r   twisted.trial.utilr   r  
executable_asBytesPathr   r   rO   ra   getattrrq   r   r   r   r   
providedByr   r  r  rX  r8  rB  rE  rG  rP  rS  rl  r  r  r  r  r  r  rM   r#   r!   <module>r     se  

    
  > > 
 C
C $ + . 7 5  , , 5 3 --/.J .JbVx V*(( (> GB$'')FGCVX CV HCVL]' ]'@2x 2.M-8 M-`6_ 6" """7++27x 7	7D+ +.J< J<Z	T 		d'' 	F   _:H _:D GB	4((*IJnAh nA KnAb DNOIh I PI<(x (V)Wh )WXE. E.P<$ <$K  
C
Cs   H 	HH