HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_util.cpython-38.pyc
U


W[l��@s�dZddlmZmZddlZddlZddlZddlZddl	Z	zddl
Z
ddlZWnek
rldZ
ZYnXddl
mZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
l m!Z!eej"��#�Z$Gdd�dej%�Z&Gdd�dej%�Z'Gdd�dej%�Z(Gdd�dej%�Z)Gdd�dej%�Z*Gdd�dej%�Z+Gdd�dej%�Z,Gdd�de�Z-Gdd�dej%�Z.Gd d!�d!ej%�Z/Gd"d#�d#ej%�Z0Gd$d%�d%ej1�Z2Gd&d'�d'ej1�Z3Gd(d)�d)e2�Z4Gd*d+�d+e5�Z6Gd,d-�d-e5�Z7Gd.d/�d/ej%�Z8Gd0d1�d1ej%�Z9Gd2d3�d3ej%�Z:Gd4d5�d5ej%�Z;Gd6d7�d7ej%�Z<Gd8d9�d9ej%�Z=Gd:d;�d;ej%�Z>Gd<d=�d=ej%�Z?dS)>z#
Tests for L{twisted.python.util}.
�)�division�absolute_importN)�unittest)�suppress)�util)�FilePath)�reactor)�IReactorProcess)�ProcessProtocol)�Deferred)�ProcessDone)�MockOSc@sXeZdZdd�Zdd�Zdd�Zdd�Zed	kr6d
e_dd�Z	d
d�Z
ed	krTde
_d	S)�	UtilTestscCs>dddddddddddg}|�t�|�dddddddg�dS)N�a��ab����)�assertEqualrZuniquify)�self�l�r�?/usr/lib/python3/dist-packages/twisted/python/test/test_util.py�testUniq(szUtilTests.testUniqcCsd|�t�ttdd��|�t�ttdd��zt�ttdd�Wntk
rTYnXt�d��dS)Nrrz,util.raises didn't raise when it should have)	�
assertTruerZraises�ZeroDivisionError�divmod�assertFalse�	TypeErrorrZFailTest�rrrr�
testRaises,szUtilTests.testRaisescCs|�t�d�d�dS)��
        When L{uidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        �100�dN)rr�
uidFromStringr!rrr�test_uidFromNumericString8sz#UtilTests.test_uidFromNumericStringcCs(t�t���}|�t�|j�|j�dS)r#N)	�pwd�getpwuid�os�getuidrrr&�pw_nameZpw_uid)r�pwentrrr�test_uidFromUsernameString@sz$UtilTests.test_uidFromUsernameStringNz0Username/UID conversion requires the pwd module.cCs|�t�d�d�dS)��
        When L{gidFromString} is called with a base-ten string representation
        of an integer, it returns the integer.
        r$r%N)rr�
gidFromStringr!rrr�test_gidFromNumericStringLsz#UtilTests.test_gidFromNumericStringcCs(t�t���}|�t�|j�|j�dS)r/N)	�grpZgetgrgidr*�getgidrrr0Zgr_nameZgr_gid)rZgrentrrr�test_gidFromGroupnameStringTsz%UtilTests.test_gidFromGroupnameStringz2Group Name/GID conversion requires the grp module.)�__name__�
__module__�__qualname__rr"r'r.r(�skipr1r4r2rrrrr&s��rc@seZdZdZdd�ZdS)�NameToLabelTestsz#
    Tests for L{nameToLabel}.
    c	CsBdddddg}|D]*\}}t�|�}|�||d|||f�qdS)zK
        Test the various kinds of inputs L{nameToLabel} supports.
        )�f�F)ZfoZFo)�foo�Foo)ZfooBarzFoo Bar)Z	fooBarBazzFoo Bar BazznameToLabel(%r) == %r != %rN)rZnameToLabelr)rZnameDataZinp�outZgotrrr�test_nameToLabelfs�
�z!NameToLabelTests.test_nameToLabelN)r5r6r7�__doc__r?rrrrr9asr9c@seZdZdZdd�ZdS)�UntilConcludesTestsz:
    Tests for L{untilConcludes}, an C{EINTR} helper.
    csx�fdd�}dg�_d�_��t�|dd�d����jd�dttg�_d�_��t�|dd�d����jd�dS)	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.
        cs4�jd7_�j��}|dk	r,|tjd��||S)NrzInterrupted system call!)�calls�
exceptions�pop�errnoZEINTR)r�b�excr!rrr:�s

z3UntilConcludesTests.test_uninterruptably.<locals>.fNrrrr�)rCrBrrZuntilConcludes�OSError�IOError)rr:rr!r�test_uninterruptably}sz(UntilConcludesTests.test_uninterruptablyN)r5r6r7r@rKrrrrrAysrAc@sTeZdZdZeedd�dkr dZdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�ZdS)�SwitchUIDTestsz&
    Tests for L{util.switchUID}.
    r+Nzgetuid/setuid not availablecCs2t�|_|�td|j�|�td|j�g|_dS)Nr*�
initgroups)r
�mockos�patchrrM�initgroupsCallsr!rrr�setUp�szSwitchUIDTests.setUpcCs|j�||f�dS)zK
        Save L{util.initgroups} calls in C{self.initgroupsCalls}.
        N)rP�append)r�uid�gidrrrrM�szSwitchUIDTests.initgroupscCs2t�dd�|�|jdg�|�|jjdg�dS)zn
        L{util.switchUID} calls L{util.initgroups} and then C{os.setuid} with
        the given uid.
        ��.N�rUN)�setuidrU)r�	switchUIDrrPrN�actionsr!rrr�test_uid�szSwitchUIDTests.test_uidcCs4t�ddd�|�|jdg�|�|jjdg�dS)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}.
        rUNTrV)rrXrrPrN�seteuidCallsr!rrr�	test_euid�szSwitchUIDTests.test_euidcCs�|j��}t�|d�|�|jg�|�|jjg�|�tjg�}|�t|�d�|�	d||dd�|�	d||dd�dS)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.
        Nrz&tried to drop privileges and setuid %ir�messagezbut uid is already %i)
rNr+rrXrrPrY�
flushWarnings�len�assertIn)rrS�currentWarningsrrr�test_currentUID�s


�
�zSwitchUIDTests.test_currentUIDcCs�|j��}t�|dd�|�|jg�|�|jjg�|�tjg�}|�t|�d�|�	d||dd�|�	d||dd�dS)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.
        NTrz'tried to drop privileges and seteuid %irr]zbut euid is already %i)
rN�geteuidrrXrrPr[r^r_r`)r�euidrarrr�test_currentEUID�s


�
�zSwitchUIDTests.test_currentEUID)
r5r6r7r@�getattrr*r8rQrMrZr\rbrerrrrrL�s

rLc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MergeFunctionMetadataTestsz-
    Tests for L{mergeFunctionMetadata}.
    csNt��t���fdd�}d�fdd�	}t�||�}|�|ddddd	���d
S)zt
        After merging C{foo}'s data into C{bar}, the returned function behaves
        as if it is C{bar}.
        cs�S�Nrr)�
foo_objectrrr<�szQMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget.<locals>.foo�
cs|\}}�Srhr)�x�yr�c�d�errF)�
bar_objectrr�bar�szQMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTarget.<locals>.barrr)rr)ZquuxN)rj)�objectr�mergeFunctionMetadataZassertIs�rr<rq�bazr)rprir�)test_mergedFunctionBehavesLikeMergeTarget�szDMergeFunctionMetadataTests.test_mergedFunctionBehavesLikeMergeTargetcCs6dd�}dd�}d|_t�||�}|�|j|j�dS)zd
        Merging C{foo} into C{bar} returns a function with C{foo}'s
        C{__module__}.
        cSsdSrhrrrrrr<sz;MergeFunctionMetadataTests.test_moduleIsMerged.<locals>.foocSsdSrhrrrrrrqsz;MergeFunctionMetadataTests.test_moduleIsMerged.<locals>.barzsomewhere.elseN)r6rrsrrtrrr�test_moduleIsMerged�s
z.MergeFunctionMetadataTests.test_moduleIsMergedcCs0dd�}dd�}t�||�}|�|j|j�dS)zX
        Merging C{foo} into C{bar} returns a function with C{foo}'s docstring.
        cSsdS)z&
            This is foo.
            Nrrrrrr<sz>MergeFunctionMetadataTests.test_docstringIsMerged.<locals>.foocSsdS)z&
            This is bar.
            Nrrrrrrqsz>MergeFunctionMetadataTests.test_docstringIsMerged.<locals>.barN)rrsrr@rtrrr�test_docstringIsMerged
sz1MergeFunctionMetadataTests.test_docstringIsMergedcCs0dd�}dd�}t�||�}|�|j|j�dS)zS
        Merging C{foo} into C{bar} returns a function with C{foo}'s name.
        cSsdSrhrrrrrr<%sz9MergeFunctionMetadataTests.test_nameIsMerged.<locals>.foocSsdSrhrrrrrrq(sz9MergeFunctionMetadataTests.test_nameIsMerged.<locals>.barN)rrsrr5rtrrr�test_nameIsMerged sz,MergeFunctionMetadataTests.test_nameIsMergedcCshdd�}d|_d|_dd�}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.
        cSsdSrhrrrrrr<5szGMergeFunctionMetadataTests.test_instanceDictionaryIsMerged.<locals>.foorrcSsdSrhrrrrrrq:szGMergeFunctionMetadataTests.test_instanceDictionaryIsMerged.<locals>.barrrN)rrFrmrrsrrtrrr�test_instanceDictionaryIsMerged/sz:MergeFunctionMetadataTests.test_instanceDictionaryIsMergedN)	r5r6r7r@rvrwrxryrzrrrrrg�srgc@seZdZdZdd�ZdS)�OrderedDictTestsz(
    Tests for L{util.OrderedDict}.
    cCs\ddlm}||j|jgd�}|�|ddd�|�|ddt�|�t|�d�dS)	z4
        L{util.OrderedDict} is deprecated.
        r)�OrderedDict�ZoffendingFunctionsr]zftwisted.python.util.OrderedDict was deprecated in Twisted 15.5.0: Use collections.OrderedDict instead.�categoryrN)Ztwisted.python.utilr|r^�test_deprecatedr�DeprecationWarningr_)rr|rarrrrJs�
�z OrderedDictTests.test_deprecatedN)r5r6r7r@rrrrrr{Fsr{c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�InsensitiveDictTestsz,
    Tests for L{util.InsensitiveDict}.
    cCstjddddid�dd�}|�|dddi�|�|dd�|�|��|�|�|d|�d��|�d|�|�d|�tt|�|tjd	��}|�||�dddg}|D],}|�||���|�|||f|�	��q�|�t
|�t
|��|d=|d=|�|��dg�d
S)zr
        L{util.InsensitiveDict} preserves the case of keys if constructed with
        C{preserve=True}.
        rqrr�r=r�fnz�Zpreserver�r<r=)�dct�InsensitiveDictN)rr�r�copy�getr`�eval�repr�keys�itemsr_)rr��resultr�rkrrr�
test_preserveas(�
z"InsensitiveDictTests.test_preservecCs�tjddddid�dd�}dddg}|D],}|�||���|�|||f|���q(|�t|�t|��|d=|d=|�|��dg�d	S)
z|
        L{util.InsensitiveDict} does not preserves the case of keys if
        constructed with C{preserve=False}.
        rqrrr�rr�r<r�N)rr�r`r�r�rr_)rr�r�rkrrr�test_noPreserve~s
z$InsensitiveDictTests.test_noPreservecCs:tjdd�}d|d<|�|dd�|�|��dg�dS)z4
        Unicode keys are case insensitive.
        Fr�rr=ZFOOr<N�rr�rr��rrnrrr�test_unicode�sz!InsensitiveDictTests.test_unicodecCs:tjdd�}d|d<|�|dd�|�|��dg�dS)z2
        Bytes keys are case insensitive.
        Fr�rsFoosFOOsfooNr�r�rrr�
test_bytes�szInsensitiveDictTests.test_bytesN)r5r6r7r@r�r�r�r�rrrrr�\s

r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�PasswordTestingProcessProtocolz�
    Write the string C{"secret
"} to a subprocess and then collect all of
    its output and fire a Deferred with it when the process ends.
    cCsg|_|j�d�dS)Nssecret
)�outputZ	transport�writer!rrr�connectionMade�sz-PasswordTestingProcessProtocol.connectionMadecCs|j�||f�dSrh)r�rR)r�fdr�rrr�childDataReceived�sz0PasswordTestingProcessProtocol.childDataReceivedcCs|j�||jf�dSrh)�finished�callbackr�)r�reasonrrr�processEnded�sz+PasswordTestingProcessProtocol.processEndedN)r5r6r7r@r�r�r�rrrrr��sr�c@s"eZdZe�e�sdZdd�ZdS)�GetPasswordTestsz,Process support required to test getPasswordcsRt�}t�|_tj|ttddgdtj�t	j
��d�id��fdd�}|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-csjimport sys
from twisted.python.util import getPassword
sys.stdout.write(getPassword())
sys.stdout.flush()
s
PYTHONPATH�utf8)�envcs"|\}}|�t���d|�dS)N)rssecret)Ztraprr`)r�r�r�r!rr�processFinished�s
z4GetPasswordTests.test_stdin.<locals>.processFinished)
r�rr�rZspawnProcess�pyExer*�pathsep�join�sys�path�encodeZaddCallback)r�pr�rr!r�
test_stdin�s��
zGetPasswordTests.test_stdinN)r5r6r7r	Z
providedByrr8r�rrrrr��s
r�c@seZdZdd�ZdS)�SearchUpwardsTestscCs�t�d�tdd���tdd���tdd���t�d�t�d�t�d�t�d	�tjdd
gddgd
�}tj�d�tj	}|�
||�t�d�tjdd
gddgd
�}d}|�
||�dS)Nzsearchupwards/a/b/czsearchupwards/foo.txt�wzsearchupwards/a/foo.txtzsearchupwards/a/b/c/foo.txtzsearchupwards/barzsearchupwards/bamzsearchupwards/a/barzsearchupwards/a/b/bamzfoo.txtrqZbam)�files�dirs�
searchupwards)
r*�makedirs�open�close�mkdirrr�r��abspath�sepr�shutilZrmtree)rZactualZexpectedrrr�testSearchupwards�s*




�
�z$SearchUpwardsTests.testSearchupwardsN)r5r6r7r�rrrrr��sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�IntervalDifferentialTestscCs2tt�gd��}td�D]}|�t|�d�qdS)Nrjr%�rjN��iterr�IntervalDifferential�ranger�next�rrn�irrr�testDefault�sz%IntervalDifferentialTests.testDefaultcCs4tt�dgd��}td�D]}|�t|�d�qdS)NrHrjr%�rHrr�r�rrr�
testSingle�sz$IntervalDifferentialTests.testSinglecCs�tt�ddgd��}td�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�qdS)NrH�rjr%r��rr�rr)rr�rr)rr�rr)rr�rr�rrr�r�rrr�testPair�sz"IntervalDifferentialTests.testPaircCsZtt�dddgd��}td�D�]4}|�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
�qdS)NrrrHrjr%r�r�)rrr�)rrr�r�rrr�
testTriples*z$IntervalDifferentialTests.testTriplecCs�tt�gd��}|�t|�d�|�d�|�t|�d�|�t|�d�|�d�|�t|�d�|�t|�d�|�t|�d�|�t|�d�|�t|�d�|�t|�d�dS)Nrjr�rr�rr�)r�rr�rr�ZaddIntervalr�rrr�
testInserts

z$IntervalDifferentialTests.testInsertcCs�tt�ddgd��}|�t|�d�|�t|�d�|�t|�d�|�d�|�t|�d�|�t|�d�|�d�|�t|�d	�|�t|jd�dS)
NrrHrjr�r�r�r�r�r�)r�rr�rr�ZremoveInterval�assertRaises�
ValueErrorr�rrr�
testRemove+s

z$IntervalDifferentialTests.testRemoveN)	r5r6r7r�r�r�r�r�r�rrrrr��sr�c@seZdZdZdZdd�ZdS)�Recordz8
    Trivial user of L{FancyEqMixin} used by tests.
    �rrFcCs||_||_dSrhr��rrrFrrr�__init__?szRecord.__init__N�r5r6r7r@ZcompareAttributesr�rrrrr�9sr�c@seZdZdZdZdd�ZdS)�DifferentRecordzL
    Trivial user of L{FancyEqMixin} which is not related to L{Record}.
    r�cCs||_||_dSrhr�r�rrrr�KszDifferentRecord.__init__Nr�rrrrr�Esr�c@seZdZdZdS)�
DerivedRecordz@
    A class with an inheritance relationship to L{Record}.
    N)r5r6r7r@rrrrr�Qsr�c@s eZdZdZdd�Zdd�ZdS)�EqualToEverythingzQ
    A class the instances of which consider themselves equal to everything.
    cCsdS�NTr�r�otherrrr�__eq__\szEqualToEverything.__eq__cCsdS�NFrr�rrr�__ne__`szEqualToEverything.__ne__N�r5r6r7r@r�r�rrrrr�Xsr�c@s eZdZdZdd�Zdd�ZdS)�EqualToNothingzN
    A class the instances of which consider themselves equal to nothing.
    cCsdSr�rr�rrrr�iszEqualToNothing.__eq__cCsdSr�rr�rrrr�mszEqualToNothing.__ne__Nr�rrrrr�esr�c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�
EqualityTestsz$
    Tests for L{FancyEqMixin}.
    cCs\Gdd�dtj�}|�|�|�k�|�|�|�k�|�}|�||k�|�||k�dS)z�
        Instances of a class which mixes in L{FancyEqMixin} but which
        defines no comparison attributes compare by identity.
        c@seZdZdS)z*EqualityTests.test_identity.<locals>.EmptyN)r5r6r7rrrr�Empty{sr�N)r�FancyEqMixinrr)rr��emptyrrr�
test_identityvszEqualityTests.test_identitycCsl|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�dS)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.
        rrrrN)rr�rr!rrr�
test_equality�szEqualityTests.test_equalitycCsl|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�dS)z
        Inequality between instances of a particular L{record} should be
        defined as the negation of equality.
        rrrrN)rr�rr!rrr�test_unequality�szEqualityTests.test_unequalitycCs|�tdd�tdd�k�dS)zo
        Instances of different classes which mix in L{FancyEqMixin} should not
        compare equal.
        rrN)rr�r�r!rrr�test_differentClassesEquality�sz+EqualityTests.test_differentClassesEqualitycCs|�tdd�tdd�k�dS)zm
        Instances of different classes which mix in L{FancyEqMixin} should
        compare unequal.
        rrN)rr�r�r!rrr�test_differentClassesInequality�sz-EqualityTests.test_differentClassesInequalitycCsl|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�dS)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.
        rrrrN)rr�r�rr!rrr�test_inheritedClassesEquality�sz+EqualityTests.test_inheritedClassesEqualitycCsl|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�|�tdd�tdd�k�dS)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.
        rrrrN)rr�r�rr!rrr�test_inheritedClassesInequality�sz-EqualityTests.test_inheritedClassesInequalitycCs0|�tdd�t�k�|�tdd�t�k�dS)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.
        rrN)rr�r�rr�r!rrr�(test_rightHandArgumentImplementsEquality�sz6EqualityTests.test_rightHandArgumentImplementsEqualitycCs0|�tdd�t�k�|�tdd�t�k�dS)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.
        rrN)rr�r�rr�r!rrr�*test_rightHandArgumentImplementsUnequality�sz8EqualityTests.test_rightHandArgumentImplementsUnequalityN)
r5r6r7r@r�r�r�r�r�r�r�r�r�rrrrr�rsr�c@steZdZdZeedd�dkr dZdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�RunAsEffectiveUserTestsz;
    Test for the L{util.runAsEffectiveUser} function.
    rcNzgeteuid/seteuid not availablecCsTt�|_|�td|jj�|�td|jj�|�td|jj�|�td|jj�dS)Nrc�getegid�seteuid�setegid)r
rNrOr*rcr�r�r�r!rrrrQ�s
zRunAsEffectiveUserTests.setUpcCs@|�||kp||jjdk�|�||kp8||jjdk�dS)zF
        Check if wanted UID/GID matched start or saved ones.
        ���N)rrNr[�setegidCalls)r�startUID�startGID�wantUID�wantGIDrrr�_securedFunction�s��z(RunAsEffectiveUserTests._securedFunctioncCs"t�dddd��}|�|d�dS)zo
        L{util.runAsEffectiveUser} forwards the result obtained by calling the
        given function
        rcSsdS)Nrrrrrr�<lambda>��z<RunAsEffectiveUserTests.test_forwardResult.<locals>.<lambda>rN�r�runAsEffectiveUserr�rr�rrr�test_forwardResult�sz*RunAsEffectiveUserTests.test_forwardResultcCs$t�dddd�d�}|�|d�dS)ze
        L{util.runAsEffectiveUser} pass the given parameters to the given
        function.
        rcSsd|S)Nrr)rkrrrr�r�z=RunAsEffectiveUserTests.test_takeParameters.<locals>.<lambda>rrNr�r�rrr�test_takeParameters�sz+RunAsEffectiveUserTests.test_takeParameterscCs*tjddd
dd�ddd�}|�|d�d	S)zg
        L{util.runAsEffectiveUser} pass the keyword parameters to the given
        function.
        rrcSs|||Srhr)rkrl�zrrrr�r�zDRunAsEffectiveUserTests.test_takesKeyworkArguments.<locals>.<lambda>rr)r�rN)rrr�r�rrr�test_takesKeyworkArgumentssz2RunAsEffectiveUserTests.test_takesKeyworkArgumentsc	Cs\||j_||j_t�|||j||||�|�|jj|�|�|jj|�g|j_g|j_dS)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)	rNrdZegidrr�r�rr[r�)rr�r�r�r�ZexpectedUIDSwitchesZexpectedGIDSwitchesrrr�_testUIDGIDSwitchs�z)RunAsEffectiveUserTests._testUIDGIDSwitchc	Csd|�ddddgg�|�ddddddgg�|�ddddgddg�|�ddddddgddg�dS)zL
        Check UID/GID switches when current effective UID is root.
        rrN�rr!rrr�	test_root"sz!RunAsEffectiveUserTests.test_rootc
Csp|�ddddddgg�|�ddddgg�|�ddddddddgddg�|�ddddddddgddg�dS)zP
        Check UID/GID switches when current effective UID is non-root.
        rrrNrr!rrr�test_UID,s z RunAsEffectiveUserTests.test_UIDc	Csd|�ddddgddg�|�ddddgg�|�ddddddgg�|�ddddddgddg�dS)zP
        Check UID/GID switches when current effective GID is non-root.
        rrrNrr!rrr�test_GID6sz RunAsEffectiveUserTests.test_GIDc
Cs�|�ddddddgddg�|�ddddddgg�|�ddddddddgddg�|�ddddgg�|�ddddddddgg�|�ddddddddgddg�|�ddddddddgddg�dS)zT
        Check UID/GID switches when current effective UID/GID is non-root.
        rrrNrr!rrr�test_UIDGID@s  z#RunAsEffectiveUserTests.test_UIDGID)r5r6r7r@rfr*r8rQr�r�r�rrrrrrrrrrr��s
			


r�c@s.eZdZdZdd�Zdd�Zejdkr*dZdS)�InitGroupsTestsz'
    Tests for L{util.initgroups}.
    csng��fdd�}|�td|�g}|�td|j�t�t��d�|��t�t���j	dfg�|�
|�dS)zc
        Calling L{util.initgroups} will call the underlying stdlib
        implmentation.
        cs��||f�dSrh)rR)rkrl�rBrr�mockInitgroupsYsz?InitGroupsTests.test_initgroupsInStdlib.<locals>.mockInitgroups�_initgroups�	setgroupsrN)rOrrRrMr*r+rr(r)r,r)rr	ZsetgroupsCallsrrr�test_initgroupsInStdlibRsz'InitGroupsTests.test_initgroupsInStdlibcCs|�ttjt��d�dS)zN
        Calling L{util.initgroups} with None for gid gives an error.
        N)r�r rrMr*r+r!rrr�test_initgroupsNoneGidesz&InitGroupsTests.test_initgroupsNoneGidNz.stdlib support for initgroups is not available)	r5r6r7r@rr
rr
r8rrrrrNs

rc@s0eZdZdZdd�Zdd�Zeedd�ge_dS)	�DeprecationTestsz;
    Tests for deprecations in C{twisted.python.util}.
    cCsTt��|j|jgd�}|�|ddd�|�|ddt�|�t|�d�dS)z6
        L{util.getPluginDirs} is deprecated.
        r}rr]zCtwisted.python.util.getPluginDirs is deprecated since Twisted 12.2.r~rN)rZ
getPluginDirsr^�test_getPluginDirsrr�r_�rrarrrrts�
�z#DeprecationTests.test_getPluginDirscCsTt��|j|jgd�}|�|ddd�|�|ddt�|�t|�d�dS)z5
        L{util.addPluginDir} is deprecated.
        r}rr]zBtwisted.python.util.addPluginDir is deprecated since Twisted 12.2.r~rN)rZaddPluginDirr^�test_addPluginDirrr�r_rrrrr�s�
�z"DeprecationTests.test_addPluginDirz/twisted.python.util.getPluginDirs is deprecated)r~r]N)	r5r6r7r@rr�SUPPRESSr�rrrrrrps��rc@s:eZdZdZeej�Zdd�Zdd�Zdd�Z	dd	�Z
d
S)�SuppressedWarningsTestsz6
    Tests for L{util.runWithWarningsSuppressed}.
    cCsDdifdifg}|�|tjd�|�|tjd�|�g|���dS)z�
        Warnings from the function called by C{runWithWarningsSuppressed} are
        suppressed if they match the passed in filter.
        ��ignorez.*foo.*�rz.*bar.*�
ignore fooz
ignore barN��runWithWarningsSuppressed�warnings�warnrr^�r�filtersrrr�&test_runWithWarningsSuppressedFiltered�s�z>SuppressedWarningsTests.test_runWithWarningsSuppressedFilteredcCs@difdifg}|�|tjd�|�dgdd�|��D��dS)z�
        Warnings from the function called by C{runWithWarningsSuppressed} are
        not suppressed if they do not match the passed in filter.
        rrzdon't ignorecSsg|]}|d�qS�r]r��.0r�rrr�
<listcomp>�szTSuppressedWarningsTests.test_runWithWarningsSuppressedUnfiltered.<locals>.<listcomp>Nrrrrr�(test_runWithWarningsSuppressedUnfiltered�s��z@SuppressedWarningsTests.test_runWithWarningsSuppressedUnfilteredcCs|�|�gdd��d�dS)zd
        C{runWithWarningsSuppressed} returns the result of the function it
        called.
        cSsdS)Nrrrrrrr��r�z:SuppressedWarningsTests.test_passThrough.<locals>.<lambda>rN)rrr!rrr�test_passThrough�sz(SuppressedWarningsTests.test_passThroughcCsJdifdifg}|�|dd��t�d�|�dgdd�|��D��dS)	zk
        Once C{runWithWarningsSuppressed} has returned, it no longer
        suppresses warnings.
        rrcSsdSrhrrrrrr��r�z<SuppressedWarningsTests.test_noSideEffects.<locals>.<lambda>rcSsg|]}|d�qSrrr rrrr"�sz>SuppressedWarningsTests.test_noSideEffects.<locals>.<listcomp>Nrrrrr�test_noSideEffects�s�
�z*SuppressedWarningsTests.test_noSideEffectsN)r5r6r7r@�staticmethodrrrr#r$r%rrrrr�s
rc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�FancyStrMixinTestsz*
    Tests for L{util.FancyStrMixin}.
    cCs(Gdd�dtj�}|�t|��d�dS)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@seZdZdZdZdZdS)z6FancyStrMixinTests.test_sequenceOfStrings.<locals>.Foo��first�secondr�helloN�r5r6r7ZshowAttributesr)r*rrrrr=�sr=z<Foo first=1 second='hello'>N�r�
FancyStrMixinr�str�rr=rrr�test_sequenceOfStrings�sz)FancyStrMixinTests.test_sequenceOfStringscCs(Gdd�dtj�}|�dt|���dS)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$eZdZdddd�ffZdZdZdS)z.FancyStrMixinTests.test_formatter.<locals>.Foor)r*cSst|ddd��S)Nr�)r�)�valuerrrr��r�z7FancyStrMixinTests.test_formatter.<locals>.Foo.<lambda>r+ZworldNr,rrrrr=�s

�r=z"<Foo first='hello' second='dlrow'>Nr-r0rrr�test_formatter�sz!FancyStrMixinTests.test_formattercCs(Gdd�dtj�}|�t|��d�dS)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@seZdZdZdZdZdS)z-FancyStrMixinTests.test_override.<locals>.Foo)r))r*Z2ndz%.1frg��S�@Nr,rrrrr=�sr=z<Foo first=1 2nd=2.1>Nr-r0rrr�
test_override�sz FancyStrMixinTests.test_overridecCs(Gdd�dtj�}|�t|��d�dS)z_
        If C{fancybasename} is present, C{__str__} uses it instead of the class name.
        c@seZdZdZdS)z2FancyStrMixinTests.test_fancybasename.<locals>.FooZBarN)r5r6r7Z
fancybasenamerrrrr=�sr=z<Bar>Nr-r0rrr�test_fancybasename�sz%FancyStrMixinTests.test_fancybasenamecCs0Gdd�dtj�}|�}|�t|�t|��dS)zE
        C{__repr__} outputs the same content as C{__str__}.
        c@seZdZdZdZdZdS)z)FancyStrMixinTests.test_repr.<locals>.Foor(rr+Nr,rrrrr=sr=N)rr.rr/r�)rr=�objrrr�	test_reprszFancyStrMixinTests.test_reprN)	r5r6r7r@r1r3r4r5r7rrrrr'�s	r'c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
PadToTestsz"
    Tests for L{util.padTo}.
    cCs"t�dg�}|�dgd|�dS)ze
        L{None} values can be added to a list to cause it to have a certain
        length.
        rN�r�padTor�r�paddedrrr�test_defaultszPadToTests.test_defaultcCs$t�dgd�}|�dgd|�dS)zg
        A specific value can be added to a list to cause it to have a certain
        length.
        rrkNr9r;rrr�test_specificDefaultValuesz$PadToTests.test_specificDefaultValuecCs(t�dddgd�}|�dddg|�dS)zl
        A list which already has some items has the padding value added after
        those items.
        rrrr�Nr9r;rrr�test_padNonEmptyList'szPadToTests.test_padNonEmptyListcCs|�ttjdddg�dS)z{
        L{util.padTo} can't pad a list if the size requested is smaller than
        the size of the list to pad.
        rrN)r�r�rr:r!rrr�test_padToSmallerSize0sz PadToTests.test_padToSmallerSizecCs(ddg}t�t|�|�}|�||�dS)z�
        If the list is already the length indicated by the padding argument
        then a list with the same value is returned.
        rrN)rr:r_r�rr�r<rrr�test_alreadyPadded8szPadToTests.test_alreadyPaddedcCs(ddg}t�t|�|�}|�||�dS)z�
        If the list is already the length indicated by the padding argument
        then the return value is a copy of the input.
        rrN)rr:r_ZassertIsNotrArrr�test_alreadyPaddedCopiesBsz#PadToTests.test_alreadyPaddedCopiescCs g}t�d|�|�g|�dS)zO
        L{util.padTo} doesn't modify the input list but makes a copy.
        rNr9)rr�rrr�
test_makeCopyLszPadToTests.test_makeCopyN)r5r6r7r@r=r>r?r@rBrCrDrrrrr8s			

r8c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�ReplaceIfTestsz'
    Tests for L{util._replaceIf}.
    cCsFt�ddd��dd��}|�|�d�|�|jd�|�|jd�d	S)
zl
        L{util._replaceIf} swaps out the body of a function if the conditional
        is C{True}.
        TcSsdS�N�hirrrrrr�`r�z4ReplaceIfTests.test_replacesIfTrue.<locals>.<lambda>cSsdS�N�byerrrrr�test`sz0ReplaceIfTests.test_replacesIfTrue.<locals>.testrGrJztwisted.python.test.test_utilN)r�
_replaceIfrr5r6�rrJrrr�test_replacesIfTrue[s

z"ReplaceIfTests.test_replacesIfTruecCs*t�ddd��dd��}|�|�d�dS)zt
        L{util._replaceIf} keeps the original body of the function if the
        conditional is C{False}.
        FcSsdSrFrrrrrr�nr�z2ReplaceIfTests.test_keepsIfFalse.<locals>.<lambda>cSsdSrHrrrrrrJnsz.ReplaceIfTests.test_keepsIfFalse.<locals>.testrIN�rrKrrLrrr�test_keepsIfFalseis
z ReplaceIfTests.test_keepsIfFalsecCsJt�ddd��t�ddd��t�ddd��dd����}|�|�d	�d
S)z�
        In the case that multiple conditions are true, the first one
        (to the reader) is chosen by L{util._replaceIf}
        TcSsdSrFrrrrrr�zr�z5ReplaceIfTests.test_multipleReplace.<locals>.<lambda>FcSsdS)Nrqrrrrrr�{r�cSsdS)Nrurrrrrr�|r�cSsdSrHrrrrrrJzsz1ReplaceIfTests.test_multipleReplace.<locals>.testrGNrNrLrrr�test_multipleReplaceus
z#ReplaceIfTests.test_multipleReplacec	CsB|�t��}t�dd�dd��}W5QRX|�|jjdd�dS)zM
        L{util._replaceIf}'s condition argument only accepts bools.
        rGZtherecSsdS)z5
                Some test function.
                NrrrrrrJ�sz+ReplaceIfTests.test_boolsOnly.<locals>.testrz:condition argument to _replaceIf requires a bool, not 'hi'N)r�r�rrKrZ	exception�args)rrorJrrr�test_boolsOnly�s
�zReplaceIfTests.test_boolsOnlyN)r5r6r7r@rMrOrPrRrrrrrEVs
rE)@r@Z
__future__rrrE�os.pathr*r�r�rr(r2�ImportErrorZ
twisted.trialrZtwisted.trial.utilrrZtwisted.pythonrZtwisted.python.filepathrZtwisted.internetrZtwisted.internet.interfacesr	Ztwisted.internet.protocolr
Ztwisted.internet.deferrZtwisted.internet.errorrZtwisted.test.test_processr
�
executableZ_asBytesPathr�ZTestCaserr9rArLrgr{r�r�r�r�r�r�r�r�r�rrr�r�r�r�rrrr'r8rErrrr�<module>sZ;NaG N

is"'4EF