AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/python/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_deprecate.cpython-310.pyc
o

�b(��@s�dZddlZddlZddlZddlZddlmZddlmZmZzddl	m
Z
Wney3dZ
Ynwddlm
Z
ddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZdd	lmZdd
l m!Z!ddl"m#Z#ddl$m%Z%dd
l&m'Z'Gdd�d�Z(Gdd�de'�Z)Gdd�de'�Z*Gdd�de%e'�Z+Gdd�de'�Z,dd�Z-dd�Z.Gdd�de'�Z/ee
ddd d!��Gd"d#�d#��Z0Gd$d%�d%�Z1ee
dd&d d�d'�d2d(d)��Z2Gd*d+�d+e'�Z3Gd,d-�d-e'�Z4Gd.d/�d/e'�Z5Gd0d1�d1e'�Z6dS)3zI
Tests for Twisted's deprecation framework, L{twisted.python.deprecate}.
�N)�normcase)�catch_warnings�simplefilter)�invalidate_caches)�Version)�	deprecate)�DEPRECATION_WARNING_FORMAT�_appendToDocstring�_fullyQualifiedName�_getDeprecationDocstring�_getDeprecationWarningString�_mutuallyExclusiveArguments�_passedArgSpec�_passedSignature�
deprecated�deprecatedKeywordParameter�deprecatedProperty�getDeprecationWarningString)�FilePath)�platform)�deprecatedattributes)�TwistedModulesMixin)�SynchronousTestCasec@� eZdZdZdd�Zdd�ZdS)�_MockDeprecatedAttributezq
    Mock of L{twisted.python.deprecate._DeprecatedAttribute}.

    @ivar value: The value of the attribute.
    cC�
||_dS�N��value��selfr�r!�D/usr/lib/python3/dist-packages/twisted/python/test/test_deprecate.py�__init__8�
z!_MockDeprecatedAttribute.__init__cC�|jS)z$
        Get a known value.
        r�r r!r!r"�get;sz_MockDeprecatedAttribute.getN)�__name__�
__module__�__qualname__�__doc__r#r'r!r!r!r"r1src@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ModuleProxyTestsz�
    Tests for L{twisted.python.deprecate._ModuleProxy}, which proxies
    access to module-level attributes, intercepting access to deprecated
    attributes and passing through access to normal attributes.
    cKs2t�d�}|��D]
\}}t|||�q	t�|�S)z�
        Create a temporary module proxy object.

        @param **kw: Attributes to initialise on the temporary module object

        @rtype: L{twistd.python.deprecate._ModuleProxy}
        �foo)�types�
ModuleType�items�setattrr�_ModuleProxy)r �attrs�mod�keyrr!r!r"�
_makeProxyIs

zModuleProxyTests._makeProxycCs.|jdd�}|�|jd�|�tt|d�dS)z�
        Getting a normal attribute on a L{twisted.python.deprecate._ModuleProxy}
        retrieves the underlying attribute's value, and raises C{AttributeError}
        if a non-existent attribute is accessed.
        �hello)�SOME_ATTRIBUTE�DOES_NOT_EXISTN)r6�assertIsr8�assertRaises�AttributeError�getattr�r �proxyr!r!r"�test_getattrPassthroughVsz(ModuleProxyTests.test_getattrPassthroughcCs2|��}t�|d�}td�|d<|�|jd�dS)z�
        Getting an attribute marked as being deprecated on
        L{twisted.python.deprecate._ModuleProxy} results in calling the
        deprecated wrapper's C{get} method.
        �_deprecatedAttributes�*r-N)r6�object�__getattribute__r�assertEqualr-)r r?rAr!r!r"�test_getattrIntercept`sz&ModuleProxyTests.test_getattrInterceptcCs,|��}|�tt|d�|�tt|d�dS)z�
        Private attributes of L{twisted.python.deprecate._ModuleProxy} are
        inaccessible when regular attribute access is used.
        �_modulerAN)r6r;r<r=r>r!r!r"�test_privateAttributesksz'ModuleProxyTests.test_privateAttributescCs4|��}d|_|�t�|d�d�|�|jd�dS)z�
        Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies
        them through to the wrapped module.
        �rGN)r6rG�assertNotEqualrCrDrEr>r!r!r"�test_setattrtszModuleProxyTests.test_setattrcCs<|��}t�|d�}|�t|�dt|�j�d|�d��dS)z�
        L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string
        containing the proxy type and a representation of the wrapped module
        object.
        rG�<z module=�>N)r6rCrDrE�repr�typer()r r?�
realModuler!r!r"�	test_repr~s(zModuleProxyTests.test_reprN)
r(r)r*r+r6r@rFrHrKrQr!r!r!r"r,Bs

	
r,c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�DeprecatedAttributeTestsz�
    Tests for L{twisted.python.deprecate._DeprecatedAttribute} and
    L{twisted.python.deprecate.deprecatedModuleAttribute}, which issue
    warnings for deprecated module-level attributes.
    cCstj|_tj|_td|_dS)Nz.foo)r�version�messager(�_testModuleNamer&r!r!r"�setUp�szDeprecatedAttributeTests.setUpcCs"ttjd|tjtdtj�S)zJ
        Create the warning string used by deprecated attributes.
        �.z: )rrr(rSrrT)r �attrr!r!r"�_getWarningString�s
�z*DeprecatedAttributeTests._getWarningStringcs�d}tt|d�t�t||j|j��|��j|��fdd�}|�|�|j	g�}|�
|ddt�|�|dd|�|��|�t
|�d�d	S)
z�
        L{twisted.python.deprecate._DeprecatedAttribute} correctly sets its
        __name__ to match that of the deprecated attribute and emits a warning
        when the original attribute value is accessed.
        �ANOTHER_DEPRECATED_ATTRIBUTErBcs���dSr)r'r!�rXr!r"�
addStackLevel�szNDeprecatedAttributeTests.test_deprecatedAttributeHelper.<locals>.addStackLevelr�categoryrTrIN)r1rr�_DeprecatedAttributerSrTrEr(�
flushWarnings�test_deprecatedAttributeHelperr:�DeprecationWarningrY�len)r �namer\�
warningsShownr!r[r"r`�s�z7DeprecatedAttributeTests.test_deprecatedAttributeHelpercCs�tj|�|jg�}|�t|�d�d}tt|�|�|jg�}|�t|�d�|�|ddt�|�|dd|�	|��dS)a
        L{twisted.python.deprecate.deprecatedModuleAttribute} wraps a
        module-level attribute in an object that emits a deprecation warning
        when it is accessed the first time only, while leaving other unrelated
        attributes alone.
        r�DEPRECATED_ATTRIBUTErIr]rTN)
r�ANOTHER_ATTRIBUTEr_�test_deprecatedAttributerErbr=r:rarY)r rdrcr!r!r"rg�s
z1DeprecatedAttributeTests.test_deprecatedAttributecCs�t�d�tj|j<}|�tjj|j�t|dd�t|dd�t�	t
dddd�d	|jd�tj|j}|�||�t�	t
dddd�d	|jd�|�|tj|j�d
S)z�
        Deprecating an attribute in a module replaces and wraps that module
        instance, in C{sys.modules}, with a
        L{twisted.python.deprecate._ModuleProxy} instance but only if it hasn't
        already been wrapped.
        r-�firstrI�second��Twisted�rrTN)
r.r/�sys�modulesrU�
addCleanup�popr1r�deprecatedModuleAttributerrJr:)r r4r?r!r!r"�test_wrappedModule�s��z+DeprecatedAttributeTests.test_wrappedModuleN)	r(r)r*r+rVrYr`rgrrr!r!r!r"rR�s
rRc@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�ImportedModuleAttributeTestsza
    Tests for L{deprecatedModuleAttribute} which involve loading a module via
    'import'.
    z�from twisted.python.deprecate import deprecatedModuleAttribute
from incremental import Version

deprecatedModuleAttribute(
    Version('Package', 1, 2, 3), 'message', __name__, 'module')
cs^�fdd��t|���d��}|���||�}|�|j�d�gtj�|�tj	�
��|S)a_
        Create some files in a hierarchy, based on a dictionary describing those
        files.  The resulting hierarchy will be placed onto sys.path for the
        duration of the test.

        @param tree: A dictionary representing a directory structure.  Keys are
            strings, representing filenames, dictionary values represent
            directories, string values represent file contents.

        @return: another dictionary similar to the input, with file content
            strings replaced with L{FilePath} objects pointing at where those
            contents are now stored.
        csji}|��D],\}}|�|�}t|t�r|||<|�|�qt|t�r/|���||�||<qtd��|S)Nz(only strings and dicts allowed as values)r0�child�
isinstance�bytes�
setContent�dict�createDirectory�
ValueError)�pathobj�dirdict�pathdictr5rrt��
makeSomeFilesr!r"rs


zAImportedModuleAttributeTests.pathEntryTree.<locals>.makeSomeFiles�utf-8)r�mktemp�encode�makedirs�replaceSysPath�path�decoderm�replaceSysModulesrn�copy)r �tree�base�resultr!r~r"�
pathEntryTree�s
z*ImportedModuleAttributeTests.pathEntryTreecCs(|�d|j�d�dd�i�}|ddS)z�
        Add a sample module and package to the path, returning a L{FilePath}
        pointing at the module which will be loadable as C{package.module}.
        spackager��)s__init__.py�	module.pyr�)r��_packageInitr�)r �pathsr!r!r"�simpleModuleEntrys
���z.ImportedModuleAttributeTests.simpleModuleEntrycCsnddlm}|�t|j�d��|�|�|jg�}|�t|�d�|�|ddd�|�|ddt	�dS)	zB
        Verification logic for L{test_deprecatedModule}.
        r��moduler�rIrTz7package.module was deprecated in Package 1.2.3: messager]N)
�packager�rEr�__file__r�r_�checkOneWarningrbra)r �
modulePathr��emittedr!r!r"r�.s
�z,ImportedModuleAttributeTests.checkOneWarningcCs|�|���dS)z�
        If L{deprecatedModuleAttribute} is used to deprecate a module attribute
        of a package, only one deprecation warning is emitted when the
        deprecated module is imported.
        N)r�r�r&r!r!r"�test_deprecatedModule=sz2ImportedModuleAttributeTests.test_deprecatedModulecCs8|��}|�|�|�|�td�D]}|�|�qdS)z�
        If L{deprecatedModuleAttribute} is used to deprecate a module attribute
        of a package, only one deprecation warning is emitted when the
        deprecated module is subsequently imported.
        rjN)r�r��range)r �mp�xr!r!r"�"test_deprecatedModuleMultipleTimesEs

�z?ImportedModuleAttributeTests.test_deprecatedModuleMultipleTimesN)
r(r)r*r+r�r�r�r�r�r�r!r!r!r"rs�s&rsc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�WarnAboutFunctionTestsz�
    Tests for L{twisted.python.deprecate.warnAboutFunction} which allows the
    callers of a function to issue a C{DeprecationWarning} about that function.
    cs�t|����d�|_|j��|j�d��d�|j�d��d�|j�d��d�|j��j}tj�	d|�|�
tjj|�tj�
��|�
�fd	d
��t��rW|��dSdS)zY
        Create a file that will have known line numbers when emitting warnings.
        �twisted_private_helperz__init__.pyr�z	module.pys
"A module string"

from twisted.python import deprecate

def testFunction():
    "A doc string"
    a = 1 + 2
    return a

def callTestFunction():
    b = testFunction()
    if b == 3:
        deprecate.warnAboutFunction(testFunction, "A Warning String")
z	pep626.pysQ
"A module string"

from twisted.python import deprecate

def noop():
    pass

def testFunction(a=1, b=1):
    "A doc string"
    if a:
        if b:
            noop()
        else:
            pass

def callTestFunction():
    b = testFunction()
    if b is None:
        deprecate.warnAboutFunction(testFunction, "A Warning String")
rcstj��tj���fSr)rmrn�clear�updater!�rnr!r"�<lambda>�sz.WarnAboutFunctionTests.setUp.<locals>.<lambda>N)rr�rtr�r�rw�parentr�rm�insertro�removernr�r�	isWindowsr_)r �packagePathr!r�r"rV`s"
��
�zWarnAboutFunctionTests.setUpcCsndd�}t�|d�|��}t}|���d�r|dd�}|�t|dd�t|��|�|dd	d�dS)
z�
        L{deprecate.warnAboutFunction} emits a warning the file and line number
        of which point to the beginning of the implementation of the function
        passed to it.
        cS�dSrr!r!r!r!r"�aFunc��z2WarnAboutFunctionTests.test_warning.<locals>.aFunczA Warning Messagez.pycN���r�filenamerT)	r�warnAboutFunctionr_r��lower�endswith�assertSamePathrrE)r r�rdr�r!r!r"�test_warning�sz#WarnAboutFunctionTests.test_warningcC�ddlm}|��|��}|�t|dd�d��|j�d��	d��|�
|ddd�|�
|dd	d
�|�
t|�d�dS)
z�
        L{deprecate.warnAboutFunction} emits a C{DeprecationWarning} with the
        number of a line within the implementation of the function passed to it.
        rr�r�r��twisted_private_helperr��lineno�	rT�A Warning StringrIN)r�r��callTestFunctionr_r�rr�r��siblingrtrErb�r r�rdr!r!r"�test_warningLineNumber�s�z-WarnAboutFunctionTests.test_warningLineNumbercCr�)
z�
        L{deprecate.warnAboutFunction} emits a C{DeprecationWarning} with the
        number of a line within the implementation handling the case in which
        dis.findlinestarts returns the lines in random order.
        r)�pep626r�r�r�s	pep626.pyr��rTr�rIN)r�r�r�r_r�rr�r�r�rtrErb)r r�rdr!r!r"�'test_warningLineNumberDisFindlinestarts�s�z>WarnAboutFunctionTests.test_warningLineNumberDisFindlinestartscCs*|�t|j�t|j�k|�d|���dS)a
        Assert that the two paths are the same, considering case normalization
        appropriate for the current platform.

        @type first: L{FilePath}
        @type second: L{FilePath}

        @raise C{self.failureType}: If the paths are not the same.
        z != N)�
assertTruerr�)r rhrir!r!r"r��s
�z%WarnAboutFunctionTests.assertSamePathcCs�ddlm}tjd=tj|j=|j�|j�d��trt�ddl	m}|�
tjjd�|�
tjj|j�|��|�
|jg�}t|dd�d��}|j�d��d�}|�||�|�|dd	d
�|�|ddd�|�t|�d
�dS)a
        Even if the implementation of a deprecated function is moved around on
        the filesystem, the line number in the warning emitted by
        L{deprecate.warnAboutFunction} points to a line in the implementation of
        the deprecated function.
        rr�r�stwisted_renamed_helper�twisted_renamed_helperr�r�r�r�r�rTr�rIN)r�r�rmrnr(r��moveTor�rr�rorpr�r_�testFunctionrr�rtr�rErb)r r�rd�
warnedPath�expectedPathr!r!r"�test_renamedFile�s&
�z'WarnAboutFunctionTests.test_renamedFilecCsJtjdd�=tjddd�ddlm}|��|��}|�t|�d�dS)z�
        L{deprecate.warnAboutFunction} emits a warning that will be filtered if
        L{warnings.filterwarning} is called with the module name of the
        deprecated function.
        N�ignorer���actionr�rr�)	�warnings�filters�filterwarningsr�r�r�r_rErbr�r!r!r"�test_filteredWarnings	z+WarnAboutFunctionTests.test_filteredWarningcCs�tjdd�=tjddd�ddlm}|��|��|��}|�t|�d�|dd}|dd	}|dd
}|dd}t�	||||�}|�
|�d�d
|���dS)z�
        L{deprecate.warnAboutFunction} emits a warning that will be filtered
        once if L{warnings.filterwarning} is called with the module name of the
        deprecated function and an action of once.
        Nr�r�r�rr�rIrTr]r�r�z=module.py:9: DeprecationWarning: A Warning String
  return a
zUnexpected warning string: )r�r�r�r�r�r�r_rErb�
formatwarningr�r�)r r�rdrTr]r�r��msgr!r!r"�test_filteredOnceWarnings$	��z/WarnAboutFunctionTests.test_filteredOnceWarningN)r(r)r*r+rVr�r�r�r�r�r�r�r!r!r!r"r�Zs=&r�cC�dS)zK
    Do nothing.

    This is used to test the deprecation decorators.
    Nr!r!r!r!r"�
dummyCallable@�r�cCr�)z[
    Do nothing.

    This is used to test the replacement parameter to L{deprecated}.
    Nr!r!r!r!r"�dummyReplacementMethodHr�r�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�DeprecationWarningsTestscCs,tdddd�}|�t|j|�dtf�dS)z�
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted.
        rkrlrz\%s.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0N)rrEr� test_getDeprecationWarningStringr(�r rSr!r!r"r�Qs
��z9DeprecationWarningsTests.test_getDeprecationWarningStringcCs6tdddd�}td}|�t|j||�dtf�dS)z�
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted, with
        a message containing additional information about the deprecation.
        rkrlrz: This is a messagezo%s.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0: This is a messageN)rrrErr�r()r rS�formatr!r!r"�*test_getDeprecationWarningStringWithFormat]s���zCDeprecationWarningsTests.test_getDeprecationWarningStringWithFormatcs�tdddd�}t|�t���fdd�}tdd��6}td�|�|�|djt�|�t|dj	�t
t|��|�|dj�d	�t
�d	��Wd
�d
S1sQwYd
S)zK
        Decorating a callable with L{deprecated} emits a warning.
        rkrlrcs
��dSrr!r!��dummyr!r"r\tr$zJDeprecationWarningsTests.test_deprecateEmitsWarning.<locals>.addStackLevelT��record�always�coN)rrr�rrrEr]ra�strrTrr��rstripr�)r rSr\�caughtr!r�r"�test_deprecateEmitsWarningms� "�z3DeprecationWarningsTests.test_deprecateEmitsWarningcCsBtdddd�}t|�t�}|�tj|j�|�tt�t|��dS)zK
        The decorated function has the same name as the original.
        rkrlrN)rrr�rEr(�fullyQualifiedName�r rSr�r!r!r"�test_deprecatedPreservesName�sz5DeprecationWarningsTests.test_deprecatedPreservesNamecCs$tdddd�}|�dt|d��dS)zr
        L{_getDeprecationDocstring} returns a note about the deprecation to go
        into a docstring.
        rkrlrzDeprecated in Twisted 8.0.0.�N)rrErr�r!r!r"�test_getDeprecationDocstring�s
�z5DeprecationWarningsTests.test_getDeprecationDocstringcCsFdd�}tdddd�}t|�|�}t|t|d��|�|j|j�dS)zv
        The docstring of the deprecated function is appended with information
        about the deprecation.
        cSr�)zc
            Do nothing.

            This is used to test the deprecation decorators.
            Nr!r!r!r!r"�localDummyCallable�r�zTDeprecationWarningsTests.test_deprecatedUpdatesDocstring.<locals>.localDummyCallablerkrlrr�N)rrr	rrEr+)r r�rSr�r!r!r"�test_deprecatedUpdatesDocstring�s
z8DeprecationWarningsTests.test_deprecatedUpdatesDocstringcCs,tdddd�}t|�t�}|�||j�dS)zt
        Deprecating a function adds version information to the decorated
        version of that function.
        rkrlrN)rrr�rE�deprecatedVersionr�r!r!r"�test_versionMetadata�sz-DeprecationWarningsTests.test_versionMetadatacCs:tdddd�}t|j|dd�}|�|dt|j�f�dS)a
        L{getDeprecationWarningString} takes an additional replacement parameter
        that can be used to add information to the deprecation.  If the
        replacement parameter is a string, it will be interpolated directly into
        the result.
        rkrlr�something.foobar��replacementzG%s was deprecated in Twisted 8.0.0; please use something.foobar insteadN)rrr�rEr��r rS�
warningStringr!r!r"�+test_getDeprecationWarningStringReplacement�s�
��zDDeprecationWarningsTests.test_getDeprecationWarningStringReplacementcCs<tdddd�}t|j|td�}|�|dt|j�tf�dS)a
        L{getDeprecationWarningString} takes an additional replacement parameter
        that can be used to add information to the deprecation. If the
        replacement parameter is a callable, its fully qualified name will be
        interpolated into the result.
        rkrlrr�zP%s was deprecated in Twisted 8.0.0; please use %s.dummyReplacementMethod insteadN)rrr�r�rEr�r(r�r!r!r"�7test_getDeprecationWarningStringReplacementWithCallable�s���zPDeprecationWarningsTests.test_getDeprecationWarningStringReplacementWithCallableN)r(r)r*r�r�r�r�r�r�r�r�r�r!r!r!r"r�Ps	
	r�rkrIrj�c@seZdZdZdS)�DeprecatedClasszJ
    Class which is entirely deprecated without having a replacement.
    N)r(r)r*r+r!r!r!r"r��sr�c@s<eZdZdZdZeedddd��dd��Zejd	d��ZdS)
�ClassWithDeprecatedPropertyz2
    Class with a single deprecated property.
    NrkrIrjr�cCr%)zC
        Getter docstring.

        @return: The property.
        ��_someProtectedValuer&r!r!r"�someProperty�sz(ClassWithDeprecatedProperty.somePropertycCs
||_dS)z#
        Setter docstring.
        Nr�rr!r!r"r��s
)	r(r)r*r+r�rrr��setterr!r!r!r"r��s
r��r-cCr�)z7
    Function with a deprecated keyword parameter.
    Nr!)�a�b�cr-�barr!r!r"�functionWithDeprecatedParameter�r�r�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�DeprecatedDecoratorTestsz*
    Tests for deprecated decorators.
    cCs |�|dd�|j��D��dS)a8
        Check that C{target} object has the C{expected} docstring lines.

        @param target: Object which is checked.
        @type target: C{anything}

        @param expected: List of lines, ignoring empty lines or leading or
            trailing spaces.
        @type expected: L{list} or L{str}
        cSsg|]
}|��r|���qSr!)�strip)�.0r�r!r!r"�
<listcomp>sz<DeprecatedDecoratorTests.assertDocstring.<locals>.<listcomp>N)rEr+�
splitlines)r �target�expectedr!r!r"�assertDocstrings�z(DeprecatedDecoratorTests.assertDocstringcCs~t�}|j|�tjgd��tdddd�tj_d}|�|jg�}|�dt|��|�t	|dd�|�||dd	�d
S)a%
        When L{deprecatedProperty} is used on a C{property}, accesses raise a
        L{DeprecationWarning} and getter docstring is updated to inform the
        version in which it was deprecated. C{deprecatedVersion} attribute is
        also set to inform the deprecation version.
        )zGetter docstring.z@return: The property.�Deprecated in Twisted 1.2.3.rkrIrjr��ktwisted.python.test.test_deprecate.ClassWithDeprecatedProperty.someProperty was deprecated in Twisted 1.2.3rr]rTN)
r�r�rrr�r_�test_propertyGetterrErbra)r �objrTr�r!r!r"r
s���z,DeprecatedDecoratorTests.test_propertyGettercCsnt�}t�}||_|�||j�d}|�|jg�}|�dt|��|�t	|dd�|�||dd�dS)z}
        When L{deprecatedProperty} is used on a C{property}, setter accesses
        raise a L{DeprecationWarning}.
        r	rIrr]rTN)
rCr�r�r:r�r_�test_propertySetterrErbra)r �newValuerrTr�r!r!r"r4s�z,DeprecatedDecoratorTests.test_propertySettercCstt�|�tddg�tdddd�t_d}|�|jg�}|�dt|��|�t|dd	�|�||dd
�dS)a
        When L{deprecated} is used on a class, instantiations raise a
        L{DeprecationWarning} and class's docstring is updated to inform the
        version in which it was deprecated. C{deprecatedVersion} attribute is
        also set to inform the deprecation version.
        z@Class which is entirely deprecated without having a replacement.rrkrIrjr�zRtwisted.python.test.test_deprecate.DeprecatedClass was deprecated in Twisted 1.2.3rr]rTN)	r�rrr�r_�
test_classrErbra)r rTr�r!r!r"rHs���z#DeprecatedDecoratorTests.test_classcCs.tdddd�}t|d�t�}|�|jd�dS)a
        L{deprecated} takes an additional replacement parameter that can be used
        to indicate the new, non-deprecated method developers should use.  If
        the replacement parameter is a string, it will be interpolated directly
        into the warning message.
        rkrlrr�z�
    Do nothing.

    This is used to test the deprecation decorators.

    Deprecated in Twisted 8.0.0; please use something.foobar instead.
    N)rrr�rEr+r�r!r!r"�test_deprecatedReplacementcs�z3DeprecatedDecoratorTests.test_deprecatedReplacementcCs:tdddd�}t|td�}|t�}|�|jdtf�dS)a)
        L{deprecated} takes an additional replacement parameter that can be used
        to indicate the new, non-deprecated method developers should use.  If
        the replacement parameter is a callable, its fully qualified name will
        be interpolated into the warning message.
        rkrlrr�z�
    Do nothing.

    This is used to test the deprecation decorators.

    Deprecated in Twisted 8.0.0; please use %s.dummyReplacementMethod instead.
    N)rrr�r�rEr+r()r rS�	decoratorr�r!r!r"�&test_deprecatedReplacementWithCallablews��z?DeprecatedDecoratorTests.test_deprecatedReplacementWithCallablecCsd}tdd��{}td�tdd�|�|g�tddd�|�|g�tdddd	�|�t|�d
�|�|djt�|�t|dj�|�|�	�tdddd
�|�|g�tdddd�|�t|�d
�|�|djt�|�t|dj�|�Wd�dS1s�wYdS)NzzThe 'foo' parameter to twisted.python.test.test_deprecate.functionWithDeprecatedParameter was deprecated in Twisted 19.2.0Tr�r��
���()r-rIr�2)r�)
rrr�rErbr]rar�rTr�)r rT�wsr!r!r"�test_deprecatedKeywordParameter�s(�
"�z8DeprecatedDecoratorTests.test_deprecatedKeywordParameterN)r(r)r*r+rr
rrrrrr!r!r!r"rs rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�AppendToDocstringTestszk
    Test the _appendToDocstring function.

    _appendToDocstring is used to add text to a docstring.
    cCs$dd�}t|d�|�d|j�dS)zP
        Appending to an empty docstring simply replaces the docstring.
        cSr�rr!r!r!r!r"�noDocstring�r�zGAppendToDocstringTests.test_appendToEmptyDocstring.<locals>.noDocstring�Appended text.N�r	rEr+)r rr!r!r"�test_appendToEmptyDocstring�s
z2AppendToDocstringTests.test_appendToEmptyDocstringcCs>dd�}t|d�|�gd�|j���|�|j�d��dS)a�
        Appending to a single line docstring places the message on a new line,
        with a blank line separating it from the rest of the docstring.

        The docstring ends with a newline, conforming to Twisted and PEP 8
        standards. Unfortunately, the indentation is incorrect, since the
        existing docstring doesn't have enough info to help us indent
        properly.
        cSr�)�;This doesn't comply with standards, but is here for a test.Nr!r!r!r!r"�singleLineDocstring�r�zTAppendToDocstringTests.test_appendToSingleLineDocstring.<locals>.singleLineDocstringr)rr�r�
N)r	rEr+rr�r�)r rr!r!r"� test_appendToSingleLineDocstring�s
�z7AppendToDocstringTests.test_appendToSingleLineDocstringcCs.dd�}dd�}t|d�|�|j|j�dS)z�
        Appending to a multi-line docstring places the messade on a new line,
        with a blank line separating it from the rest of the docstring.

        Because we have multiple lines, we have enough information to do
        indentation.
        cSr�)z9
            This is a multi-line docstring.
            Nr!r!r!r!r"�multiLineDocstring�r�zRAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.multiLineDocstringcSr�)zU
            This is a multi-line docstring.

            Appended text.
            Nr!r!r!r!r"�expectedDocstring�r�zQAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.expectedDocstringrNr)r r"r#r!r!r"�test_appendToMultilineDocstring�s	
z6AppendToDocstringTests.test_appendToMultilineDocstringN)r(r)r*r+rr!r$r!r!r!r"r�s
rc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�MutualArgumentExclusionTestsz2
    Tests for L{mutuallyExclusiveArguments}.
    cOs0ttdd�rtt�|�||�Stt�|�||�S)a�
        Test an invocation of L{passed} with the given function, arguments, and
        keyword arguments.

        @param func: A function whose argspec will be inspected.
        @type func: A callable.

        @param args: The arguments which could be passed to C{func}.

        @param kw: The keyword arguments which could be passed to C{func}.

        @return: L{_passedSignature} or L{_passedArgSpec}'s return value
        @rtype: L{dict}
        �	signatureN)r=�inspectrr&r�
getargspec�r �func�args�kwr!r!r"�checkPassed�sz(MutualArgumentExclusionTests.checkPassedcCs*dd�}|�|�|dd�tddd��dS)z`
        L{passed} identifies the arguments passed by a simple
        positional test.
        cSr�rr!�r�r�r!r!r"r*r�zGMutualArgumentExclusionTests.test_passed_simplePositional.<locals>.funcrIrjr.N�rEr-rx�r r*r!r!r"�test_passed_simplePositionals"z9MutualArgumentExclusionTests.test_passed_simplePositionalcCs"dd�}|�t|j|ddd�dS)z[
        L{passed} raises a L{TypeError} if too many arguments are
        passed.
        cSr�rr!r.r!r!r"r*r�zBMutualArgumentExclusionTests.test_passed_tooManyArgs.<locals>.funcrIrjr�N�r;�	TypeErrorr-r0r!r!r"�test_passed_tooManyArgs�z4MutualArgumentExclusionTests.test_passed_tooManyArgscC�"dd�}|jt|j|ddd�dS)zs
        L{passed} raises a L{TypeError} if a argument is passed both
        positionally and by keyword.
        cSr�rr!�r�r!r!r"r*'r�zHMutualArgumentExclusionTests.test_passed_doublePassKeyword.<locals>.funcrIrjr7Nr2r0r!r!r"�test_passed_doublePassKeyword!r5z:MutualArgumentExclusionTests.test_passed_doublePassKeywordcCr6)z�
        L{passed} raises a L{TypeError} if a keyword argument not
        present in the function's declaration is passed.
        cSr�rr!r7r!r!r"r*2r�zIMutualArgumentExclusionTests.test_passed_unspecifiedKeyword.<locals>.funcrIrj)�zNr2r0r!r!r"�test_passed_unspecifiedKeyword,r5z;MutualArgumentExclusionTests.test_passed_unspecifiedKeywordcCs,dd�}|�|�|ddd�tddd��dS)	z|
        L{passed} places additional positional arguments into a tuple
        under the name of the star argument.
        cWr�rr!r.r!r!r"r*=r�z;MutualArgumentExclusionTests.test_passed_star.<locals>.funcrIrjr�)rjr�r.Nr/r0r!r!r"�test_passed_star7s$z-MutualArgumentExclusionTests.test_passed_starc
Cs:dd�}|�|j|ddddd�tdtdddd�d��d	S)
zn
        Additional keyword arguments are passed as a dict to the star star
        keyword argument.
        c[r�rr!r.r!r!r"r*Hr�z?MutualArgumentExclusionTests.test_passed_starStar.<locals>.funcrIrjr��)r��yr9r.Nr/r0r!r!r"�test_passed_starStarBs&�z1MutualArgumentExclusionTests.test_passed_starStarcCs2d
dd�}|�|j|dddd�tdddd��d	S)zp
        The results of L{passed} only include arguments explicitly
        passed, not default values.
        rIrjr�cSr�rr!�r�r�r��d�er!r!r"r*Ur�zFMutualArgumentExclusionTests.test_passed_noDefaultValues.<locals>.func�)rA)r�r�rAN�rIrjr�r/r0r!r!r"�test_passed_noDefaultValuesOs
(z8MutualArgumentExclusionTests.test_passed_noDefaultValuescCsTtdg�ddd��}|�|dd�d�|�|ddd	�d
�|�|ddd	d�d�d
S)z�
        L{mutuallyExclusiveArguments} does not interfere in its
        decoratee's operation, either its receipt of arguments or its return
        value.
        r.r�r<cSs||||Srr!)r�r=r�r�r!r!r"r*aszMMutualArgumentExclusionTests.test_mutualExclusionPrimeDirective.<locals>.funcrIrjrrB��r��
N�r�r<)r
rEr0r!r!r"�"test_mutualExclusionPrimeDirectiveZs
z?MutualArgumentExclusionTests.test_mutualExclusionPrimeDirectivecCs.tddgg�d	dd��}|jt|ddd�dS)
z�
        L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
        decoratee is passed a pair of mutually exclusive arguments.
        r�r�r�r<cSs||Srr!r.r!r!r"r*oszPMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeyword.<locals>.funcr.NrH)r
r;r3r0r!r!r"�%test_mutualExclusionExcludesByKeywordiszBMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeywordcCsnGdd�d�}Gdd�d�}dd�}|dd�t�|�j}|��}|d	d	�|d
<||�}|�tt|di�dS)
z�
        Create a fake signature with an invalid parameter
        type to test error handling.  The valid parameter
        types are specified in L{inspect.Parameter}.
        c@�eZdZdd�ZdS)zMMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignaturecSrr)�
parameters)r rLr!r!r"r#}r$zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignature.__init__N�r(r)r*r#r!r!r!r"�
FakeSignature|�rNc@rK)zMMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParametercSs||_||_dSr)rc�kind)r rcrPr!r!r"r#�s
zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameter.__init__NrMr!r!r!r"�
FakeParameter�rOrQcSr�rr!r.r!r!r"r*�r�zDMutualArgumentExclusionTests.test_invalidParameterType.<locals>.funcrIrj�faker��rIrjN)r'r&rLr�r;r3r)r rNrQr*rL�dummyParameters�fakeSigr!r!r"�test_invalidParameterTypeus
z6MutualArgumentExclusionTests.test_invalidParameterTypeN)r(r)r*r+r-r1r4r8r:r;r>rDrIrJrVr!r!r!r"r%�s
r%c@r)�KeywordOnlyTestsz,
    Keyword only arguments (PEP 3102).
    cOstt�|�||�S)a�
        Test an invocation of L{passed} with the given function, arguments, and
        keyword arguments.

        @param func: A function whose argspec to pass to L{_passed}.
        @type func: A callable.

        @param args: The arguments which could be passed to L{func}.

        @param kw: The keyword arguments which could be passed to L{func}.

        @return: L{_passed}'s return value
        @rtype: L{dict}
        )rr'r&r)r!r!r"r-�szKeywordOnlyTests.checkPassedcCs�dd�dd�}dd�dd�}|�|�|ddd	�td
dd��|�|j|ddd	dd�td
dd��|�|j|dddddd	d
�tddddd	d��|jt|j|dddddd�dS)z`
        Keyword only arguments follow varargs.
        They are specified in PEP 3102.
        TrFcWr�)zM
            b is a keyword-only argument, with a default value.
            Nr!)r�r�r!r!r"�func1�r�z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func1cWr�)zd
            b, c, d, e  are keyword-only arguments.
            b has a default value.
            Nr!)r�r�r@rAr�r!r!r"�func2�r�z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func2rIrjr�rCr.F)r�r�r@rArSr?)r�r�r@N)rEr-rxr;r3)r rXrYr!r!r"�test_passedKeywordOnly�s �� z'KeywordOnlyTests.test_passedKeywordOnlyN)r(r)r*r+r-rZr!r!r!r"rW�srWrC)7r+r'rmr.r��os.pathrrr�	importlibr�ImportError�incrementalr�twisted.pythonr�twisted.python.deprecaterr	r
r�rrr
rrrrrr�twisted.python.filepathr�twisted.python.runtimer�twisted.python.testr�#twisted.python.test.modules_helpersr�twisted.trial.unittestrrr,rRrsr�r�r�r�r�r�r�rrr%rWr!r!r!r"�<module>sR�8Gbog-D!

Anon7 - 2022
AnonSec Team