o
    Óó·iHˆ  ã                   @   sÎ  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 z
ddlZddlZW n ey?   dZdZY nw 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j)ƒ *¡ Z+G dd„ de%ƒZ,G dd„ de%ƒZ-G dd„ de%ƒZ.ee/eddƒ dƒG dd„ de%ƒƒZ0G dd„ de%ƒZ1G dd„ de%ƒZ2G dd„ de%ƒZ3G dd „ d eƒZ4ee 5e¡ d!ƒG d"d#„ d#e%ƒƒZ6G d$d%„ d%e%ƒZ7G d&d'„ d'e%ƒZ8G d(d)„ d)ej9ƒZ:G d*d+„ d+ej9ƒZ;G d,d-„ d-e:ƒZ<G d.d/„ d/ƒZ=G d0d1„ d1ƒZ>G d2d3„ d3e%ƒZ?ee/ed4dƒ d5ƒG d6d7„ d7e%ƒƒZ@eejA d8ƒG d9d:„ d:e%ƒƒZBG d;d<„ d<e%ƒZCG d=d>„ d>e%ƒZDG d?d@„ d@e%ƒZEG dAdB„ dBe%ƒZFdS )Cz#
Tests for L{twisted.python.util}.
é    N)ÚIterableÚMappingÚMutableMappingÚSequence)ÚskipIf)Úreactor)ÚDeferred)ÚProcessDone)ÚIReactorProcess)ÚProcessProtocol)Úutil)ÚFilePath)ÚMockOS)ÚFailTestÚTestCase)Úsuppressc                   @   sX   e Zd Zdd„ Zdd„ Zdd„ Zeedu dƒd	d
„ ƒZdd„ Z	ee
du dƒdd„ ƒZdS )Ú	UtilTestsc                 C   s"   g d¢}|   t |¡g d¢¡ d S )N)Úaé   Úabr   é   é   r   é   r   r   é   )r   r   r   r   r   r   r   )ÚassertEqualr   Zuniquify)ÚselfZlistWithDupes© r   úcC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/python/test/test_util.pyÚtestUniq+   s   zUtilTests.testUniqc                 C   s\   |   t ttdd¡¡ |  t ttdd¡¡ zt ttdd¡ W tdƒ‚ ty-   Y d S w )Nr   r   z,util.raises didn't raise when it should have)Ú
assertTruer   ZraisesÚZeroDivisionErrorÚdivmodÚassertFalseÚ	TypeErrorr   ©r   r   r   r   Ú
testRaises/   s   ýÿzUtilTests.testRaisesc                 C   ó   |   t d¡d¡ dS )ú†
        When L{uidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        Ú100éd   N)r   r   ÚuidFromStringr$   r   r   r   Útest_uidFromNumericString:   ó   z#UtilTests.test_uidFromNumericStringNz0Username/UID conversion requires the pwd module.c                 C   ó(   t  t ¡ ¡}|  t |j¡|j¡ dS )r'   N)	ÚpwdÚgetpwuidÚosÚgetuidr   r   r*   Úpw_nameÚpw_uid)r   Úpwentr   r   r   Útest_uidFromUsernameStringA   ó   z$UtilTests.test_uidFromUsernameStringc                 C   r&   )ú†
        When L{gidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        r(   r)   N)r   r   ÚgidFromStringr$   r   r   r   Útest_gidFromNumericStringJ   r,   z#UtilTests.test_gidFromNumericStringz2Group Name/GID conversion requires the grp module.c                 C   r-   )r7   N)	ÚgrpÚgetgrgidr0   Úgetgidr   r   r8   Úgr_nameÚgr_gid)r   Zgrentr   r   r   Útest_gidFromGroupnameStringQ   r6   z%UtilTests.test_gidFromGroupnameString)Ú__name__Ú
__module__Ú__qualname__r   r%   r+   r   r.   r5   r9   r:   r?   r   r   r   r   r   *   s    
r   c                   @   ó   e Zd ZdZdd„ ZdS )ÚNameToLabelTestsz#
    Tests for L{nameToLabel}.
    c                 C   sD   g d¢}|D ]\}}t  |¡}|  ||d|›d|›d|›�¡ qdS )zK
        Test the various kinds of inputs L{nameToLabel} supports.
        ))ÚfÚF)ÚfoZFo)ÚfooÚFoo)ZfooBarzFoo Bar)Z	fooBarBazzFoo Bar BazznameToLabel(z) == z != N)r   ZnameToLabelr   )r   ZnameDataÚinpÚoutÚgotr   r   r   Útest_nameToLabel`   s
   
"þz!NameToLabelTests.test_nameToLabelN)r@   rA   rB   Ú__doc__rM   r   r   r   r   rD   [   ó    rD   c                   @   rC   )ÚUntilConcludesTestsz:
    Tests for L{untilConcludes}, an C{EINTR} helper.
    c                    sx   ‡ fdd„}dgˆ _ dˆ _ˆ  t |dd¡d¡ ˆ  ˆ jd¡ dttgˆ _ dˆ _ˆ  t |dd¡d¡ ˆ  ˆ jd¡ dS )	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                    s4   ˆ  j d7  _ ˆ j ¡ }|d ur|tjdƒ‚| | S )Nr   zInterrupted system call!)ÚcallsÚ
exceptionsÚpopÚerrnoZEINTR)r   ÚbÚexcr$   r   r   rE   }   s
   
z3UntilConcludesTests.test_uninterruptably.<locals>.fNr   r   r   r   é   )rR   rQ   r   r   ZuntilConcludesÚOSErrorÚIOError)r   rE   r   r$   r   Útest_uninterruptablyu   s   z(UntilConcludesTests.test_uninterruptablyN)r@   rA   rB   rN   rZ   r   r   r   r   rP   p   rO   rP   r1   zgetuid/setuid not availablec                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚSwitchUIDTestsz&
    Tests for L{util.switchUID}.
    c                 C   s2   t ƒ | _|  td| j¡ |  td| j¡ g | _d S )Nr0   Ú
initgroups)r   ÚmockosÚpatchr   r\   ÚinitgroupsCallsr$   r   r   r   ÚsetUp•   s   
zSwitchUIDTests.setUpc                 C   s   | j  ||f¡ dS )zK
        Save L{util.initgroups} calls in C{self.initgroupsCalls}.
        N)r_   Úappend)r   ÚuidÚgidr   r   r   r\   ›   s   zSwitchUIDTests.initgroupsc                 C   s2   t  dd¡ |  | jdg¡ |  | jjdg¡ dS )zn
        L{util.switchUID} calls L{util.initgroups} and then C{os.setuid} with
        the given uid.
        éà.  N©rd   N)Zsetuidrd   )r   Ú	switchUIDr   r_   r]   Úactionsr$   r   r   r   Útest_uid¡   s   zSwitchUIDTests.test_uidc                 C   s4   t  ddd¡ |  | jdg¡ |  | jjdg¡ dS )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}.
        rd   NTre   )r   rf   r   r_   r]   ÚseteuidCallsr$   r   r   r   Ú	test_euidª   s   zSwitchUIDTests.test_euidc                 C   s†   | j  ¡ }t |d¡ |  | jg ¡ |  | j jg ¡ |  tjg¡}|  t|ƒd¡ |  	d| |d d ¡ |  	d| |d d ¡ dS )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)
r]   r1   r   rf   r   r_   rg   ÚflushWarningsÚlenÚassertIn)r   rb   ÚcurrentWarningsr   r   r   Útest_currentUID³   s   

þzSwitchUIDTests.test_currentUIDc                 C   sˆ   | j  ¡ }t |dd¡ |  | jg ¡ |  | j jg ¡ |  tjg¡}|  t|ƒd¡ |  	d| |d d ¡ |  	d| |d d ¡ dS )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   rk   zbut euid is already %i)
r]   Úgeteuidr   rf   r   r_   ri   rl   rm   rn   )r   Úeuidro   r   r   r   Útest_currentEUIDÄ   s   

þzSwitchUIDTests.test_currentEUIDN)
r@   rA   rB   rN   r`   r\   rh   rj   rp   rs   r   r   r   r   r[   �   s    		r[   c                   @   ó8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚMergeFunctionMetadataTestsz-
    Tests for L{mergeFunctionMetadata}.
    c                    sN   t ƒ ‰t ƒ ‰ ‡fdd„}d‡ fdd„	}t ||¡}|  |ddddd	�ˆ ¡ d
S )zt
        After merging C{foo}'s data into C{bar}, the returned function behaves
        as if it is C{bar}.
        c                      s   ˆ S ©Nr   r   )Ú
foo_objectr   r   rH   ã   ó   zQMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget.<locals>.fooé
   c                    s   |\}}ˆ S rv   r   )ÚxÚyr   ÚcÚdÚer   rU   )Ú
bar_objectr   r   Úbaræ   s   zQMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget.<locals>.barr   r   )r   r   )ZquuxN)ry   )Úobjectr   ÚmergeFunctionMetadataZassertIs©r   rH   r€   Zbazr   )r   rw   r   Ú)test_mergedFunctionBehavesLikeMergeTargetÛ   s   zDMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTargetc                 C   s6   dd„ }dd„ }d|_ t ||¡}|  |j |j ¡ dS )zd
        Merging C{foo} into C{bar} returns a function with C{foo}'s
        C{__module__}.
        c                   S   ó   d S rv   r   r   r   r   r   rH   ó   rx   z;MergeFunctionMetadataTests.test_moduleIsMerged.<locals>.fooc                   S   r…   rv   r   r   r   r   r   r€   ö   rx   z;MergeFunctionMetadataTests.test_moduleIsMerged.<locals>.barzsomewhere.elseN)rA   r   r‚   r   rƒ   r   r   r   Útest_moduleIsMergedí   s
   z.MergeFunctionMetadataTests.test_moduleIsMergedc                 C   ó0   dd„ }dd„ }t  ||¡}|  |j|j¡ dS )zX
        Merging C{foo} into C{bar} returns a function with C{foo}'s docstring.
        c                   S   ó   dS )z&
            This is foo.
            Nr   r   r   r   r   rH     ó    z>MergeFunctionMetadataTests.test_docstringIsMerged.<locals>.fooc                   S   rˆ   )z&
            This is bar.
            Nr   r   r   r   r   r€     r‰   z>MergeFunctionMetadataTests.test_docstringIsMerged.<locals>.barN)r   r‚   r   rN   rƒ   r   r   r   Útest_docstringIsMergedþ   s   z1MergeFunctionMetadataTests.test_docstringIsMergedc                 C   r‡   )zS
        Merging C{foo} into C{bar} returns a function with C{foo}'s name.
        c                   S   r…   rv   r   r   r   r   r   rH     rx   z9MergeFunctionMetadataTests.test_nameIsMerged.<locals>.fooc                   S   r…   rv   r   r   r   r   r   r€     rx   z9MergeFunctionMetadataTests.test_nameIsMerged.<locals>.barN)r   r‚   r   r@   rƒ   r   r   r   Útest_nameIsMerged  s   z,MergeFunctionMetadataTests.test_nameIsMergedc                 C   sh   dd„ }d|_ d|_dd„ }d|_d|_t ||¡}|  |j |j ¡ |  |j|j¡ |  |j|j¡ d	S )
zv
        Merging C{foo} into C{bar} returns a function with C{bar}'s
        dictionary, updated by C{foo}'s.
        c                   S   r…   rv   r   r   r   r   r   rH   $  rx   zGMergeFunctionMetadataTests.test_instanceDictionaryIsMerged.<locals>.foor   r   c                   S   r…   rv   r   r   r   r   r   r€   *  rx   zGMergeFunctionMetadataTests.test_instanceDictionaryIsMerged.<locals>.barr   r   N)r   rU   r|   r   r‚   r   rƒ   r   r   r   Útest_instanceDictionaryIsMerged  s   z:MergeFunctionMetadataTests.test_instanceDictionaryIsMergedN)	r@   rA   rB   rN   r„   r†   rŠ   r‹   rŒ   r   r   r   r   ru   Ö   s    ru   c                   @   rC   )ÚOrderedDictTestsz(
    Tests for L{util.OrderedDict}.
    c                 C   s\   ddl m} | | j| jgd�}|  |d d d¡ |  |d d t¡ |  t|ƒd¡ dS )	z4
        L{util.OrderedDict} is deprecated.
        r   )ÚOrderedDict©ZoffendingFunctionsrk   zftwisted.python.util.OrderedDict was deprecated in Twisted 15.5.0: Use collections.OrderedDict instead.Úcategoryr   N)Ztwisted.python.utilrŽ   rl   Útest_deprecatedr   ÚDeprecationWarningrm   )r   rŽ   ro   r   r   r   r‘   ;  s   
þz OrderedDictTests.test_deprecatedN)r@   rA   rB   rN   r‘   r   r   r   r   r�   6  rO   r�   c                   @   rt   )ÚInsensitiveDictTestsz,
    Tests for L{util.InsensitiveDict}.
    c                 C   sL   t  ¡ }|  t|tƒ¡ |  t|tƒ¡ |  t|tƒ¡ |  t|tƒ¡ dS )zN
        L{util.InsensitiveDict} implements L{typing.MutableMapping}.
        N)	r   ÚInsensitiveDictr   Ú
isinstancer   r   r   r"   r   )r   Údctr   r   r   Útest_abcR  s
   zInsensitiveDictTests.test_abcc                 C   s  t jddddidœdd�}|  |d ddi¡ |  |d d¡ |  | ¡ |¡ |  |d | d¡¡ |  d|¡ |  d|¡ tt|ƒ|t jd	œƒ}|  ||¡ g d
¢}|D ]}|  || ¡ ¡ |  ||| f| 	¡ ¡ qU|  t
|ƒt
|ƒ¡ |d= |d= |  | ¡ dg¡ dS )zr
        L{util.InsensitiveDict} preserves the case of keys if constructed with
        C{preserve=True}.
        r€   r   r   ©rI   r   Úfnz©Úpreserver™   rH   rI   )r–   r”   )rI   r™   r   N)r   r”   r   ÚcopyÚgetrn   ÚevalÚreprÚkeysÚitemsrm   )r   r–   Úresultr    rz   r   r   r   Útest_preserve\  s,   þþz"InsensitiveDictTests.test_preservec                 C   sŠ   t jddddidœdd�}g d¢}|D ]}|  || ¡ ¡ |  ||| f| ¡ ¡ q|  t|ƒt|ƒ¡ |d= |d= |  | ¡ d	g¡ d
S )z|
        L{util.InsensitiveDict} does not preserves the case of keys if
        constructed with C{preserve=False}.
        r€   r   r   r˜   r   rš   )rH   r™   r   rH   r™   N)r   r”   rn   r    r¡   r   rm   )r   r–   r    rz   r   r   r   Útest_noPreserve{  s   z$InsensitiveDictTests.test_noPreservec                 C   ó:   t jdd�}d|d< |  |d d¡ |  | ¡ dg¡ dS )z4
        Unicode keys are case insensitive.
        Frš   r   rI   ZFOOrH   N©r   r”   r   r    ©r   r}   r   r   r   Útest_unicodeŠ  ó   z!InsensitiveDictTests.test_unicodec                 C   r¥   )z2
        Bytes keys are case insensitive.
        Frš   r   s   Foos   FOOs   fooNr¦   r§   r   r   r   Ú
test_bytes“  r©   zInsensitiveDictTests.test_bytesN)	r@   rA   rB   rN   r—   r£   r¤   r¨   rª   r   r   r   r   r“   M  s    
	r“   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú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                 C   s   g | _ | j d¡ d S )Ns   secret
)ÚoutputÚ	transportÚwriter$   r   r   r   ÚconnectionMade£  s   z-PasswordTestingProcessProtocol.connectionMadec                 C   s   | j  ||f¡ d S rv   )r¬   ra   )r   Úfdr¬   r   r   r   ÚchildDataReceived§  s   z0PasswordTestingProcessProtocol.childDataReceivedc                 C   s   | j  || jf¡ d S rv   )ÚfinishedÚcallbackr¬   )r   Úreasonr   r   r   ÚprocessEndedª  s   z+PasswordTestingProcessProtocol.processEndedN)r@   rA   rB   rN   r¯   r±   rµ   r   r   r   r   r«   �  s
    r«   z,Process support required to test getPasswordc                   @   ó   e Zd Zdd„ ZdS )ÚGetPasswordTestsc                    sR   t ƒ }tƒ |_tj|ttddgdtj t	j
¡ d¡id� ‡ fdd„}|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                    s"   | \}}|  t¡ ˆ  d|¡ d S )N)r   s   secret)Ztrapr	   rn   )r¢   r´   r¬   r$   r   r   ÚprocessFinishedÌ  s   
z4GetPasswordTests.test_stdin.<locals>.processFinishedN)r«   r   r²   r   ZspawnProcessÚpyExer0   ÚpathsepÚjoinÚsysÚpathÚencodeZaddCallback)r   Úprº   r   r$   r   Ú
test_stdin³  s   ü
ózGetPasswordTests.test_stdinN)r@   rA   rB   rÂ   r   r   r   r   r·   ®  s    r·   c                   @   r¶   )ÚSearchUpwardsTestsc                 C   sÄ   t  d¡ tddƒ ¡  tddƒ ¡  tddƒ ¡  t  d¡ t  d¡ t  d¡ t  d	¡ tjdd
gddgd�}t j d¡t j	 }|  
||¡ t d¡ tjdd
gddgd�}d }|  
||¡ d S )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€   Zbam)ÚfilesÚdirsÚsearchupwards)r0   ÚmakedirsÚopenÚcloseÚmkdirr   rÇ   r¿   ÚabspathÚsepr   ÚshutilÚrmtree)r   ÚactualÚexpectedr   r   r   ÚtestSearchupwardsÕ  s&   




ÿ
ÿz$SearchUpwardsTests.testSearchupwardsN)r@   rA   rB   rÒ   r   r   r   r   rÃ   Ô  s    rÃ   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚIntervalDifferentialTestsc                 C   s2   t t g d¡ƒ}tdƒD ]
}|  t|ƒd¡ qd S )Nry   r)   ©ry   N©Úiterr   ÚIntervalDifferentialÚranger   Únext©r   r}   Úir   r   r   ÚtestDefaultì  s   ÿz%IntervalDifferentialTests.testDefaultc                 C   s4   t t dgd¡ƒ}tdƒD ]
}|  t|ƒd¡ qd S )NrW   ry   r)   ©rW   r   rÕ   rÚ   r   r   r   Ú
testSingleñ  s   ÿz$IntervalDifferentialTests.testSinglec                 C   sæ   t t ddgd¡ƒ}tdƒD ]b}|  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd	¡ |  t|ƒd¡ |  t|ƒd
¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ qd S )NrW   é   ry   r)   rÝ   ©r   r   ©r   r   )r   r   ©r   r   ©r   r   ©r   r   )r   r   ©r   r   ©r   r   rÕ   rÚ   r   r   r   ÚtestPairö  s   ôz"IntervalDifferentialTests.testPairc                 C   sV  t t g d¢d¡ƒ}tdƒD ]š}|  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ qd S )	N)r   r   rW   ry   r)   rå   ræ   )r   r   râ   )r   r   rÕ   rÚ   r   r   r   Ú
testTriple  s,   íz$IntervalDifferentialTests.testTriplec                 C   s¸   t t g d¡ƒ}|  t|ƒd¡ | d¡ |  t|ƒd¡ |  t|ƒd¡ | d¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ d S )Nry   rÔ   r   rá   r   ræ   )rÖ   r   r×   r   rÙ   ZaddIntervalr§   r   r   r   Ú
testInsert  s   

z$IntervalDifferentialTests.testInsertc                 C   sœ   t t ddgd¡ƒ}|  t|ƒd¡ |  t|ƒd¡ |  t|ƒd¡ | d¡ |  t|ƒd¡ |  t|ƒd¡ | d¡ |  t|ƒd	¡ |  t|jd¡ d S )
Nr   rW   ry   rá   rà   râ   rä   rÝ   rÔ   )rÖ   r   r×   r   rÙ   ZremoveIntervalÚassertRaisesÚ
ValueErrorr§   r   r   r   Ú
testRemove+  s   

z$IntervalDifferentialTests.testRemoveN)	r@   rA   rB   rÜ   rÞ   rç   rè   ré   rì   r   r   r   r   rÓ   ë  s    rÓ   c                   @   ó   e Zd ZdZdZdd„ ZdS )ÚRecordz8
    Trivial user of L{FancyEqMixin} used by tests.
    ©r   rU   c                 C   ó   || _ || _d S rv   rï   ©r   r   rU   r   r   r   Ú__init__?  ó   
zRecord.__init__N©r@   rA   rB   rN   ZcompareAttributesrò   r   r   r   r   rî   8  ó    rî   c                   @   rí   )ÚDifferentRecordzL
    Trivial user of L{FancyEqMixin} which is not related to L{Record}.
    rï   c                 C   rð   rv   rï   rñ   r   r   r   rò   K  ró   zDifferentRecord.__init__Nrô   r   r   r   r   rö   D  rõ   rö   c                   @   ó   e Zd ZdZdS )ÚDerivedRecordz@
    A class with an inheritance relationship to L{Record}.
    N)r@   rA   rB   rN   r   r   r   r   rø   P  ó    rø   c                   @   ó"   e Zd ZdZdedefdd„ZdS )ÚEqualToEverythingzQ
    A class the instances of which consider themselves equal to everything.
    ÚotherÚreturnc                 C   rˆ   )NTr   ©r   rü   r   r   r   Ú__eq__[  rx   zEqualToEverything.__eq__N©r@   rA   rB   rN   r�   Úboolrÿ   r   r   r   r   rû   V  ó    rû   c                   @   rú   )ÚEqualToNothingzN
    A class the instances of which consider themselves equal to nothing.
    rü   rý   c                 C   rˆ   )NFr   rþ   r   r   r   rÿ   d  rx   zEqualToNothing.__eq__Nr   r   r   r   r   r  _  r  r  c                   @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚEqualityTestsz$
    Tests for L{FancyEqMixin}.
    c                 C   s\   G dd„ dt jƒ}|  |ƒ |ƒ k¡ |  |ƒ |ƒ k¡ |ƒ }|  ||k¡ |  ||k¡ dS )z�
        Instances of a class which mixes in L{FancyEqMixin} but which
        defines no comparison attributes compare by identity.
        c                   @   s   e Zd ZdS )z*EqualityTests.test_identity.<locals>.EmptyN)r@   rA   rB   r   r   r   r   ÚEmptys  s    r  N)r   ÚFancyEqMixinr"   r   )r   r  Úemptyr   r   r   Útest_identitym  s   zEqualityTests.test_identityc                 C   sl   |   tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ dS )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   rî   r"   r$   r   r   r   Útest_equality|  ó   zEqualityTests.test_equalityc                 C   sl   |   tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ dS )z
        Inequality between instances of a particular L{record} should be
        defined as the negation of equality.
        r   r   r   r   N)r"   rî   r   r$   r   r   r   Útest_unequality‡  s   zEqualityTests.test_unequalityc                 C   s   |   tddƒtddƒk¡ dS )zo
        Instances of different classes which mix in L{FancyEqMixin} should not
        compare equal.
        r   r   N)r"   rî   rö   r$   r   r   r   Útest_differentClassesEquality‘  ó   z+EqualityTests.test_differentClassesEqualityc                 C   s   |   tddƒtddƒk¡ dS )zm
        Instances of different classes which mix in L{FancyEqMixin} should
        compare unequal.
        r   r   N)r   rî   rö   r$   r   r   r   Útest_differentClassesInequality˜  r  z-EqualityTests.test_differentClassesInequalityc                 C   sl   |   tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ dS )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   rî   rø   r"   r$   r   r   r   Útest_inheritedClassesEqualityŸ  r
  z+EqualityTests.test_inheritedClassesEqualityc                 C   sl   |   tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ |  tddƒtddƒk¡ dS )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"   rî   rø   r   r$   r   r   r   Útest_inheritedClassesInequalityª  r
  z-EqualityTests.test_inheritedClassesInequalityc                 C   s0   |   tddƒtƒ k¡ |  tddƒtƒ k¡ dS )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   rî   rû   r"   r  r$   r   r   r   Ú(test_rightHandArgumentImplementsEqualityµ  ó   z6EqualityTests.test_rightHandArgumentImplementsEqualityc                 C   s0   |   tddƒtƒ k¡ |  tddƒtƒ k¡ dS )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"   rî   rû   r   r  r$   r   r   r   Ú*test_rightHandArgumentImplementsUnequality¿  r  z8EqualityTests.test_rightHandArgumentImplementsUnequalityN)r@   rA   rB   rN   r  r	  r  r  r  r  r  r  r  r   r   r   r   r  h  s    

r  rq   zgeteuid/seteuid not availablec                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚRunAsEffectiveUserTestsz;
    Test for the L{util.runAsEffectiveUser} function.
    c                 C   sT   t ƒ | _|  td| jj¡ |  td| jj¡ |  td| jj¡ |  td| jj¡ d S )Nrq   ÚgetegidÚseteuidÚsetegid)r   r]   r^   r0   rq   r  r  r  r$   r   r   r   r`   Ð  s
   zRunAsEffectiveUserTests.setUpc                 C   s@   |   ||kp|| jjd k¡ |   ||kp|| jjd k¡ dS )zF
        Check if wanted UID/GID matched start or saved ones.
        éÿÿÿÿN)r   r]   ri   ÚsetegidCalls)r   ÚstartUIDÚstartGIDÚwantUIDÚwantGIDr   r   r   Ú_securedFunction×  s   "z(RunAsEffectiveUserTests._securedFunctionc                 C   s"   t  dddd„ ¡}|  |d¡ dS )zo
        L{util.runAsEffectiveUser} forwards the result obtained by calling the
        given function
        r   c                   S   rˆ   )Nr   r   r   r   r   r   Ú<lambda>ã  r‰   z<RunAsEffectiveUserTests.test_forwardResult.<locals>.<lambda>r   N©r   ÚrunAsEffectiveUserr   ©r   r¢   r   r   r   Útest_forwardResultÞ  s   z*RunAsEffectiveUserTests.test_forwardResultc                 C   s$   t  dddd„ d¡}|  |d¡ dS )ze
        L{util.runAsEffectiveUser} pass the given parameters to the given
        function.
        r   c                 S   s   d|  S )Nr   r   )rz   r   r   r   r  ë  s    z=RunAsEffectiveUserTests.test_takeParameters.<locals>.<lambda>r   r   Nr   r"  r   r   r   Útest_takeParametersæ  s   z+RunAsEffectiveUserTests.test_takeParametersc                 C   s*   t jddd
dd„ddd�}|  |d¡ d	S )zg
        L{util.runAsEffectiveUser} pass the keyword parameters to the given
        function.
        r   r   c                 S   s   | | | S rv   r   )rz   r{   Úzr   r   r   r  ó  s    zDRunAsEffectiveUserTests.test_takesKeyworkArguments.<locals>.<lambda>r   r   )r%  r   Nrã   r   r"  r   r   r   Útest_takesKeyworkArgumentsî  s   z2RunAsEffectiveUserTests.test_takesKeyworkArgumentsc              	   C   s\   || j _|| j _t ||| j||||¡ |  | j j|¡ |  | j j|¡ g | j _g | j _dS )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)	r]   rr   Zegidr   r!  r  r   ri   r  )r   r  r  r  r  ZexpectedUIDSwitchesZexpectedGIDSwitchesr   r   r   Ú_testUIDGIDSwitchö  s   ù	z)RunAsEffectiveUserTests._testUIDGIDSwitchc              	   C   sd   |   ddddg g ¡ |   ddddddgg ¡ |   ddddg ddg¡ |   ddddddgddg¡ dS )zL
        Check UID/GID switches when current effective UID is root.
        r   r   N©r'  r$   r   r   r   Ú	test_root  s    z!RunAsEffectiveUserTests.test_rootc              	   C   sh   |   ddddddgg ¡ |   ddddg g ¡ |   ddddg d¢ddg¡ |   ddddg d¢ddg¡ dS )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$   r   r   r   Útest_UID  s    z RunAsEffectiveUserTests.test_UIDc              	   C   sd   |   ddddg ddg¡ |   ddddg g ¡ |   ddddddgg ¡ |   ddddddgddg¡ dS )zP
        Check UID/GID switches when current effective GID is non-root.
        r   r   r   Nr(  r$   r   r   r   Útest_GID&  s    z RunAsEffectiveUserTests.test_GIDc              	   C   s¸   |   ddddddgddg¡ |   ddddddgg ¡ |   ddddg d¢ddg¡ |   ddddg g ¡ |   ddddg d¢g ¡ |   ddddg d¢ddg¡ |   ddddg d¢ddg¡ dS )zT
        Check UID/GID switches when current effective UID/GID is non-root.
        r   r   r*  r   r+  Nr(  r$   r   r   r   Útest_UIDGID/  s    z#RunAsEffectiveUserTests.test_UIDGIDN)r@   rA   rB   rN   r`   r  r#  r$  r&  r'  r)  r,  r-  r.  r   r   r   r   r  Ê  s    			r  z.stdlib support for initgroups is not availablec                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚInitGroupsTestsz'
    Tests for L{util.initgroups}.
    c                    sn   g ‰ ‡ fdd„}|   td|¡ g }|   td|j¡ t t ¡ d¡ |  ˆ t t ¡ ¡j	dfg¡ |  
|¡ dS )zc
        Calling L{util.initgroups} will call the underlying stdlib
        implmentation.
        c                    s   ˆ   | |f¡ d S rv   )ra   )rz   r{   ©rQ   r   r   ÚmockInitgroupsI  s   z?InitGroupsTests.test_initgroupsInStdlib.<locals>.mockInitgroupsÚ_initgroupsÚ	setgroupsr   N)r^   r   ra   r\   r0   r1   r   r.   r/   r2   r"   )r   r1  ZsetgroupsCallsr   r0  r   Útest_initgroupsInStdlibB  s   z'InitGroupsTests.test_initgroupsInStdlibc                 C   s   |   ttjt ¡ d¡ dS )zN
        Calling L{util.initgroups} with None for gid gives an error.
        N)rê   r#   r   r\   r0   r1   r$   r   r   r   Útest_initgroupsNoneGidT  s   z&InitGroupsTests.test_initgroupsNoneGidN)r@   rA   rB   rN   r4  r5  r   r   r   r   r/  <  s    r/  c                   @   s0   e Zd ZdZdd„ Zdd„ Zeedd�ge_dS )	ÚDeprecationTestsz;
    Tests for deprecations in C{twisted.python.util}.
    c                 C   óT   t  ¡  | j| jgd�}|  |d d d¡ |  |d d t¡ |  t|ƒd¡ dS )z6
        L{util.getPluginDirs} is deprecated.
        r�   r   rk   zCtwisted.python.util.getPluginDirs is deprecated since Twisted 12.2.r�   r   N)r   ZgetPluginDirsrl   Útest_getPluginDirsr   r’   rm   ©r   ro   r   r   r   r8  `  ó   ÿ
þz#DeprecationTests.test_getPluginDirsc                 C   r7  )z5
        L{util.addPluginDir} is deprecated.
        r�   r   rk   zBtwisted.python.util.addPluginDir is deprecated since Twisted 12.2.r�   r   N)r   ZaddPluginDirrl   Útest_addPluginDirr   r’   rm   r9  r   r   r   r;  o  r:  z"DeprecationTests.test_addPluginDirz/twisted.python.util.getPluginDirs is deprecated)r�   rk   N)	r@   rA   rB   rN   r8  r;  ÚSUPPRESSr’   r   r   r   r   r   r6  [  s    þ
ÿr6  c                   @   s:   e Zd ZdZeejƒZdd„ Zdd„ Zdd„ Z	dd	„ Z
d
S )ÚSuppressedWarningsTestsz6
    Tests for L{util.runWithWarningsSuppressed}.
    c                 C   sD   di fdi fg}|   |tjd¡ |   |tjd¡ |  g |  ¡ ¡ dS )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   rl   ©r   Úfiltersr   r   r   Ú&test_runWithWarningsSuppressedFiltered�  s   z>SuppressedWarningsTests.test_runWithWarningsSuppressedFilteredc                 C   s@   di fdi fg}|   |tjd¡ |  dgdd„ |  ¡ D ƒ¡ dS )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 ignorec                 S   ó   g | ]}|d  ‘qS ©rk   r   ©Ú.0rÄ   r   r   r   Ú
<listcomp>ž  ó    zTSuppressedWarningsTests.test_runWithWarningsSuppressedUnfiltered.<locals>.<listcomp>NrB  rF  r   r   r   Ú(test_runWithWarningsSuppressedUnfiltered—  s    z@SuppressedWarningsTests.test_runWithWarningsSuppressedUnfilteredc                 C   s   |   |  g dd„ ¡d¡ dS )zd
        C{runWithWarningsSuppressed} returns the result of the function it
        called.
        c                   S   rˆ   )Nr   r   r   r   r   r   r  ¥  r‰   z:SuppressedWarningsTests.test_passThrough.<locals>.<lambda>r   N)r   rC  r$   r   r   r   Útest_passThrough   s   z(SuppressedWarningsTests.test_passThroughc                 C   sJ   di fdi fg}|   |dd„ ¡ t d¡ |  dgdd„ |  ¡ D ƒ¡ dS )	zk
        Once C{runWithWarningsSuppressed} has returned, it no longer
        suppresses warnings.
        r>  r@  c                   S   r…   rv   r   r   r   r   r   r  ­  r‰   z<SuppressedWarningsTests.test_noSideEffects.<locals>.<lambda>rA  c                 S   rI  rJ  r   rK  r   r   r   rM  ¯  rN  z>SuppressedWarningsTests.test_noSideEffects.<locals>.<listcomp>NrB  rF  r   r   r   Útest_noSideEffects§  s   
 z*SuppressedWarningsTests.test_noSideEffectsN)r@   rA   rB   rN   Ústaticmethodr   rC  rH  rO  rP  rQ  r   r   r   r   r=  †  s    

	r=  c                   @   rt   )ÚFancyStrMixinTestsz*
    Tests for L{util.FancyStrMixin}.
    c                 C   ó(   G dd„ dt jƒ}|  t|ƒ ƒd¡ dS )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dS )z6FancyStrMixinTests.test_sequenceOfStrings.<locals>.Foo©ÚfirstÚsecondr   ÚhelloN©r@   rA   rB   ZshowAttributesrW  rX  r   r   r   r   rI   ½  ó    rI   z<Foo first=1 second='hello'>N©r   ÚFancyStrMixinr   Ústr©r   rI   r   r   r   Útest_sequenceOfStrings·  s   z)FancyStrMixinTests.test_sequenceOfStringsc                 C   s(   G dd„ dt jƒ}|  dt|ƒ ƒ¡ dS )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                   @   s$   e Zd Zdddd„ ffZdZdZdS )z.FancyStrMixinTests.test_formatter.<locals>.FoorW  rX  c                 S   s   t | d d d… ƒS )Nr  )rŸ   )Úvaluer   r   r   r  Í  s    z7FancyStrMixinTests.test_formatter.<locals>.Foo.<lambda>rY  ZworldNrZ  r   r   r   r   rI   Ì  s    rI   z"<Foo first='hello' second='dlrow'>Nr\  r_  r   r   r   Útest_formatterÄ  ó   z!FancyStrMixinTests.test_formatterc                 C   rT  )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                   @   rU  )z-FancyStrMixinTests.test_override.<locals>.Foo)rW  )rX  Z2ndz%.1fr   gÙÎ÷Sã @NrZ  r   r   r   r   rI   Û  r[  rI   z<Foo first=1 2nd=2.1>Nr\  r_  r   r   r   Útest_overrideÓ  rc  z FancyStrMixinTests.test_overridec                 C   rT  )z_
        If C{fancybasename} is present, C{__str__} uses it instead of the class name.
        c                   @   r÷   )z2FancyStrMixinTests.test_fancybasename.<locals>.FooÚBarN)r@   rA   rB   Zfancybasenamer   r   r   r   rI   ç  rù   rI   z<Bar>Nr\  r_  r   r   r   Útest_fancybasenameâ  s   z%FancyStrMixinTests.test_fancybasenamec                 C   s0   G dd„ dt jƒ}|ƒ }|  t|ƒt|ƒ¡ dS )zE
        C{__repr__} outputs the same content as C{__str__}.
        c                   @   rU  )z)FancyStrMixinTests.test_repr.<locals>.FoorV  r   rY  NrZ  r   r   r   r   rI   ñ  r[  rI   N)r   r]  r   r^  rŸ   )r   rI   Úobjr   r   r   Ú	test_reprì  s   zFancyStrMixinTests.test_reprN)	r@   rA   rB   rN   r`  rb  rd  rf  rh  r   r   r   r   rS  ²  s    
rS  c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )Ú
PadToTestsz"
    Tests for L{util.padTo}.
    c                 C   s"   t  dg ¡}|  dgd |¡ dS )ze
        L{None} values can be added to a list to cause it to have a certain
        length.
        r   N©r   ÚpadTor   ©r   Úpaddedr   r   r   Útest_defaultÿ  s   zPadToTests.test_defaultc                 C   s$   t  dg d¡}|  dgd |¡ dS )zg
        A specific value can be added to a list to cause it to have a certain
        length.
        r   rz   Nrj  rl  r   r   r   Útest_specificDefaultValue  s   z$PadToTests.test_specificDefaultValuec                 C   s&   t  dddgd¡}|  g d¢|¡ dS )zl
        A list which already has some items has the padding value added after
        those items.
        r   r   r   r%  )r   r   r%  Nrj  rl  r   r   r   Útest_padNonEmptyList  s   zPadToTests.test_padNonEmptyListc                 C   s   |   ttjdddg¡ dS )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)rê   rë   r   rk  r$   r   r   r   Útest_padToSmallerSize  s   z PadToTests.test_padToSmallerSizec                 C   s(   ddg}t  t|ƒ|¡}|  ||¡ dS )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   rk  rm   r   ©r   r¡   rm  r   r   r   Útest_alreadyPadded  ó   zPadToTests.test_alreadyPaddedc                 C   s(   ddg}t  t|ƒ|¡}|  ||¡ dS )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   rk  rm   ZassertIsNotrr  r   r   r   Útest_alreadyPaddedCopies'  rt  z#PadToTests.test_alreadyPaddedCopiesc                 C   s    g }t  d|¡ |  g |¡ dS )zO
        L{util.padTo} doesn't modify the input list but makes a copy.
        r   Nrj  )r   r¡   r   r   r   Útest_makeCopy0  s   zPadToTests.test_makeCopyN)r@   rA   rB   rN   rn  ro  rp  rq  rs  ru  rv  r   r   r   r   ri  ú  s    		ri  )GrN   rT   Úos.pathr0   rÎ   r¾   rD  Útypingr   r   r   r   Zunittestr   r:   Z_grpr.   Ú_pwdÚImportErrorZtwisted.internetr   Ztwisted.internet.deferr   Ztwisted.internet.errorr	   Ztwisted.internet.interfacesr
   Ztwisted.internet.protocolr   Ztwisted.pythonr   Ztwisted.python.filepathr   Ztwisted.test.test_processr   Ztwisted.trial.unittestr   r   Ztwisted.trial.utilr   r<  Ú
executableZ_asBytesPathr»   r   rD   rP   Úgetattrr[   ru   r�   r“   r«   Z
providedByr·   rÃ   rÓ   r  rî   rö   rø   rû   r  r  r  r2  r/  r6  r=  rS  ri  r   r   r   r   Ú<module>   st   þ1F`P
þ"M		bq+,H