%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/test/__pycache__/test_deprecate.cpython-312.pyc

�

Ϫ�fd���d�dZddlZddlZddlZddlZddlmZddlmZmZ	ddl	m
Z
ddlm
Z
ddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZdd	lmZdd
l m!Z!ddl"m#Z#ddl$m%Z%dd
l&m'Z'Gd�d�Z(Gd�de'�Z)Gd�de'�Z*Gd�de%e'�Z+Gd�de'�Z,d�Z-d�Z.Gd�de'�Z/ee
dddd��Gd �d!��Z0Gd"�d#�Z1ee
dd$dd�d%�d/d&��Z2Gd'�d(e'�Z3Gd)�d*e'�Z4Gd+�d,e'�Z5Gd-�d.e'�Z6y#e$rdZ
Y��wxYw)0zI
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��eZdZdZd�Zd�Zy)�_MockDeprecatedAttributezq
    Mock of L{twisted.python.deprecate._DeprecatedAttribute}.

    @ivar value: The value of the attribute.
    c��||_y�N��value��selfrs  �D/usr/lib/python3/dist-packages/twisted/python/test/test_deprecate.py�__init__z!_MockDeprecatedAttribute.__init__8s	����
�c��|jS)z$
        Get a known value.
        r�r!s r"�getz_MockDeprecatedAttribute.get;s���z�z�r$N)�__name__�
__module__�__qualname__�__doc__r#r'�r$r"rr1s����r$rc�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�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.
    c��tjd�}|j�D]\}}t|||��t	j
|�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�keyrs     r"�
_makeProxyzModuleProxyTests._makeProxyIsJ�����u�%���+�+�-�	%�J�C���C��e�$�	%��%�%�c�*�*r$c��|jd��}|j|jd�|jtt
|d�y)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)r9�assertIsr<�assertRaises�AttributeError�getattr�r!�proxys  r"�test_getattrPassthroughz(ModuleProxyTests.test_getattrPassthroughVs=�����w��7���
�
�e�*�*�G�4����.�'�5�:J�Kr$c��|j�}tj|d�}td�|d<|j	|j
d�y)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�*r0N)r9�object�__getattribute__r�assertEqualr0)r!rCrFs   r"�test_getattrInterceptz&ModuleProxyTests.test_getattrIntercept`sH�����!�� &� 7� 7��?V� W��'?��'C��e�$�������B�'r$c��|j�}|jtt|d�|jtt|d�y)z�
        Private attributes of L{twisted.python.deprecate._ModuleProxy} are
        inaccessible when regular attribute access is used.
        �_modulerFN)r9r?r@rArBs  r"�test_privateAttributesz'ModuleProxyTests.test_privateAttributesks9��
���!�����.�'�5�)�D����.�'�5�:Q�Rr$c��|j�}d|_|jtj	|d�d�|j|jd�y)z�
        Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies
        them through to the wrapped module.
        �rMN)r9rM�assertNotEqualrHrIrJrBs  r"�test_setattrzModuleProxyTests.test_setattrtsH��
���!����
����F�3�3�E�9�E�q�I��������*r$c��|j�}tj|d�}|jt	|�dt|�j�d|�d��y)z�
        L{twisted.python.deprecated._ModuleProxy.__repr__} produces a string
        containing the proxy type and a representation of the wrapped module
        object.
        rM�<z module=�>N)r9rHrIrJ�repr�typer()r!rC�
realModules   r"�	test_reprzModuleProxyTests.test_repr~sQ�����!���,�,�U�I�>�
�����e���$�u�+�*>�*>�)?�x�
�~�UV�&W�Xr$N)
r(r)r*r+r9rDrKrNrRrYr,r$r"r.r.Bs(���+�L�	(�S�+�Yr$r.c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�DeprecatedAttributeTestsz�
    Tests for L{twisted.python.deprecate._DeprecatedAttribute} and
    L{twisted.python.deprecate.deprecatedModuleAttribute}, which issue
    warnings for deprecated module-level attributes.
    c�t�tj|_tj|_tdz|_y)Nz.foo)r�version�messager(�_testModuleNamer&s r"�setUpzDeprecatedAttributeTests.setUp�s)��+�3�3���+�3�3���'�&�0��r$c��ttjdz|ztjtdztj
z�S)zJ
        Create the warning string used by deprecated attributes.
        �.z: )r
rr(r]r	r^)r!�attrs  r"�_getWarningStringz*DeprecatedAttributeTests._getWarningString�sA��,� �)�)�C�/�$�6� �(�(�&��-�0D�0L�0L�L�
�	
r$c����d}tt|d�tjt||j|j
��|j
�j|��fd�}|�|j|jg�}|j|ddt�|j
|dd|j|��|j
t|�d�y)	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_ATTRIBUTErGc�&���j�yr)r')rcs�r"�
addStackLevelzNDeprecatedAttributeTests.test_deprecatedAttributeHelper.<locals>.addStackLevel�s����H�H�Jr$r�categoryr^rPN)r4rr�_DeprecatedAttributer]r^rJr(�
flushWarnings�test_deprecatedAttributeHelperr>�DeprecationWarningrd�len)r!�namerh�
warningsShownrcs    @r"rlz7DeprecatedAttributeTests.test_deprecatedAttributeHelper�s����.���$�d�B�/��-�-� �$����d�l�l�
��	
�������-�	�	���*�*�D�,O�,O�+P�Q�
��
�
�m�A�&�z�2�4F�G�����q�)�)�4�d�6L�6L�T�6R�S�����]�+�Q�/r$c��tj|j|jg�}|j	t|�d�d}t
t|�|j|jg�}|j	t|�d�|j|ddt�|j	|dd|j|��y)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_ATTRIBUTErPrir^N)
r�ANOTHER_ATTRIBUTErk�test_deprecatedAttributerJrnrAr>rmrd)r!rpros   r"rtz1DeprecatedAttributeTests.test_deprecatedAttribute�s���	�.�.��*�*�D�,I�,I�+J�K�
�����]�+�Q�/�%��	�$�d�+��*�*�D�,I�,I�+J�K�
�����]�+�Q�/��
�
�m�A�&�z�2�4F�G�����q�)�)�4�d�6L�6L�T�6R�Sr$c�t�tjd�xtj|j<}|jtjj|j�t|dd�t|dd�tjtdddd�d	|jd�tj|j}|j||�tjtdddd�d	|jd�|j|tj|j�y
)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.
        r0�firstrP�second��Twisted�rr^N)
r1r2�sys�modulesr_�
addCleanup�popr4r�deprecatedModuleAttributerrQr>)r!r7rCs   r"�test_wrappedModulez+DeprecatedAttributeTests.test_wrappedModule�s���38�2B�2B�5�2I�I����D�(�(�)�C����������)=�)=�>���W�a� ���X�q�!��+�+��I�q�!�Q�'��D�4H�4H�'�	
����D�0�0�1�����E�3�'��+�+��I�q�!�Q�'��D�4H�4H�(�	
�	
�
�
�e�S�[�[��)=�)=�>�?r$N)	r(r)r*r+r`rdrlrtr�r,r$r"r[r[�s"���1�

�0�4T�.@r$r[c�2�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	y)	�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')
c�f���fd��t|j�jd��}|j��||�}|j	|j
j
d�gtj
z�|jtjj��|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.
        c���i}|j�D]t\}}|j|�}t|t�r|||<|j	|��>t|t
�r|j
��||�||<�ktd��|S)Nz(only strings and dicts allowed as values)r3�child�
isinstance�bytes�
setContent�dict�createDirectory�
ValueError)�pathobj�dirdict�pathdictr8rr��
makeSomeFiless      �r"r�zAImportedModuleAttributeTests.pathEntryTree.<locals>.makeSomeFiless�����H�%�m�m�o�	
Q�
��U��
�
�c�*���e�U�+�$)�H�S�M��$�$�U�+���t�,��)�)�+�$1�%��$?�H�S�M�$�%O�P�P�	
Q��Or$�utf-8)r�mktemp�encode�makedirs�replaceSysPath�path�decoder{�replaceSysModulesr|�copy)r!�tree�base�resultr�s    @r"�
pathEntryTreez*ImportedModuleAttributeTests.pathEntryTree�s����	�����
�,�,�W�5�6���
�
���t�T�*�����T�Y�Y�-�-�g�6�7�#�(�(�B�C����s�{�{�/�/�1�2��
r$c�p�|jd|jjd�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�r$)s__init__.py�	module.pyr�)r��_packageInitr�)r!�pathss  r"�simpleModuleEntryz.ImportedModuleAttributeTests.simpleModuleEntrysJ��
�"�"��$(�$5�$5�$<�$<�W�$E�"%��
�
���Z� ��.�.r$c�N�ddlm}|jt|jjd��|�|j
|jg�}|jt|�d�|j|ddd�|j|ddt�y)	zB
        Verification logic for L{test_deprecatedModule}.
        r��moduler�rPr^z7package.module was deprecated in Package 1.2.3: messageriN)
�packager�rJr�__file__r�rk�checkOneWarningrnrm)r!�
modulePathr��emitteds    r"r�z,ImportedModuleAttributeTests.checkOneWarning.s���	#�����&�/�/�"8�"8��"A�B�J�O��$�$�d�&:�&:�%;�<������W��q�)�����A�J�y�!�H�	
�	
������J�/�1C�Dr$c�B�|j|j��y)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&s r"�test_deprecatedModulez2ImportedModuleAttributeTests.test_deprecatedModule=s��	
���T�3�3�5�6r$c��|j�}|j|�|j|�td�D]}|j|��y)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.
        rxN)r�r��range)r!�mp�xs   r"�"test_deprecatedModuleMultipleTimesz?ImportedModuleAttributeTests.test_deprecatedModuleMultipleTimesEsS���
#�
#�
%�����R� �	
���R� ��q��	%�A�� � ��$�	%r$N)
r(r)r*r+r�r�r�r�r�r�r,r$r"r�r��s)���
�L�$�L
/�
E�7�%r$r�c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�WarnAboutFunctionTestsz�
    Tests for L{twisted.python.deprecate.warnAboutFunction} which allows the
    callers of a function to issue a C{DeprecationWarning} about that function.
    c���t|j��jd�|_|jj	�|jjd�jd�|jjd�jd�|jjd�jd�|jj
�j}tjjd|�|jtjj|�tjj��|j�fd	��tj�r|j!�y
y
)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")
rc�~��tjj�tjj��fSr)r{r|�clear�update)r|s�r"�<lambda>z.WarnAboutFunctionTests.setUp.<locals>.<lambda>�s(������!2�!2�!4�c�k�k�6H�6H��6Q� R�r$N)rr�r�r�r�r��parentr�r{�insertr}�remover|r�r�	isWindowsrk)r!�packagePathr|s  @r"r`zWarnAboutFunctionTests.setUp`s��� ����
�.�4�4�5M�N��������������=�)�4�4�S�9������;�'�2�2�
�	
�"	
�����;�'�2�2�
�	
�0�l�l�)�)�+�0�0��������;�'����������5��+�+�"�"�$�����R�S�
������� � r$c�.�d�}tj|d�|j�}t}|j	�jd�r|dd}|j
t|dd�t|��|j|ddd�y)	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.
        c��yrr,r,r$r"�aFuncz2WarnAboutFunctionTests.test_warning.<locals>.aFunc����r$zA Warning Messagez.pycN���r�filenamer^)	r�warnAboutFunctionrkr��lower�endswith�assertSamePathrrJ)r!r�rpr�s    r"�test_warningz#WarnAboutFunctionTests.test_warning�s���	�	�#�#�E�+>�?��*�*�,�
����>�>��$�$�V�,����}�H����H�]�1�%5�j�%A�B�H�X�DV�W�����q�)�)�4�6I�Jr$c��ddlm}|j�|j�}|j	t|ddj
d��|jjd�jd��|j|ddd�|j|dd	d
�|jt|�d�y)
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�	r^�A Warning StringrPN)r�r��callTestFunctionrkr�rr�r��siblingr�rJrn�r!r�rps   r"�test_warningLineNumberz-WarnAboutFunctionTests.test_warningLineNumber�s���
	2����!��*�*�,�
�����]�1�%�j�1�8�8��A�B��L�L� � �!:�;�A�A�,�O�	
�	
����q�)�(�3�Q�7�����q�)�)�4�6H�I�����]�+�Q�/r$c��ddlm}|j�|j�}|j	t|ddj
d��|jjd�jd��|j|ddd�|j|dd	d
�|jt|�d�y)
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��r^r�rPN)r�r�r�rkr�rr�r�r�r�rJrn)r!r�rps   r"�'test_warningLineNumberDisFindlinestartsz>WarnAboutFunctionTests.test_warningLineNumberDisFindlinestarts�s���	2����!��*�*�,�
�����]�1�%�j�1�8�8��A�B��L�L� � �!:�;�A�A�,�O�	
�	
����q�)�(�3�R�8�����q�)�)�4�6H�I�����]�+�Q�/r$c��|jt|j�t|j�k(|�d|���y)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!rvrws   r"r�z%WarnAboutFunctionTests.assertSamePath�s8��	
����U�Z�Z� �H�V�[�[�$9�9��i�t�F�:�&�	
r$c�^�ddlm}tjd=tj|j=|j
j
|j
jd��tr
t�ddl	m}|jtjjd�|jtjj|j�|j�|j|jg�}t|ddj!d��}|j
jd�j#d�}|j%||�|j'|dd	d
�|j'|ddd�|j't)|�d
�y)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�r^r�rPN)r�r�r{r|r(r��moveTor�rr�r}r~r�rk�testFunctionrr�r�r�rJrn)r!r�rp�
warnedPath�expectedPaths     r"�test_renamedFilez'WarnAboutFunctionTests.test_renamedFile�sN��	2�
�K�K�0�1��K�K����(�	
�����D�L�L�0�0�1J�K�L����	2���������)A�B������������9����!��*�*�F�,?�,?�+@�A�
��m�A�.�z�:�A�A�'�J�K�
��|�|�+�+�,E�F�L�L��
��	
���J��5�����q�)�(�3�Q�7�����q�)�)�4�6H�I�����]�+�Q�/r$c���tjdd�=tjdd��ddlm}|j�|j
�}|jt|�d�y)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�rkrJrnr�s   r"�test_filteredWarningz+WarnAboutFunctionTests.test_filteredWarningsU��
���Q�����x�8P�Q�1����!��*�*�,�
�����]�+�Q�/r$c��tjdd�=tjdd��ddlm}|j�|j�|j
�}|jt|�d�|dd}|dd	}|dd
}|dd}tj||||�}|j|jd�d
|���y)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�rPr^rir�r�z=module.py:9: DeprecationWarning: A Warning String
  return a
zUnexpected warning string: )r�r�r�r�r�r�rkrJrn�
formatwarningr�r�)r!r�rpr^rir�r��msgs        r"�test_filteredOnceWarningz/WarnAboutFunctionTests.test_filteredOnceWarnings���
���Q�����x�8P�Q�1����!����!��*�*�,�
�����]�+�Q�/���"�9�-�� ��#�J�/�� ��#�J�/���q�!�(�+���$�$�W�h��&�I������L�L�T�
�*�#��1�		
r$N)r(r)r*r+r`r�r�r�r�r�r�r�r,r$r"r�r�Zs2���
;!�zK�$0�&0�(

�$0�L0�(
r$r�c��y)zK
    Do nothing.

    This is used to test the deprecation decorators.
    Nr,r,r$r"�
dummyCallabler�@��r$c��y)z[
    Do nothing.

    This is used to test the replacement parameter to L{deprecated}.
    Nr,r,r$r"�dummyReplacementMethodr�Hr�r$c�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�DeprecationWarningsTestsc�z�tdddd�}|jt|j|�t�d��y)z�
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted.
        ryrzrzZ.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0N)rrJr� test_getDeprecationWarningStringr(�r!r]s  r"r�z9DeprecationWarningsTests.test_getDeprecationWarningStringQs:��
�)�Q��1�-�����'��(M�(M�w�W�19�
<�	
r$c��tdddd�}tdz}|jt|j||�t
�d��y)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.
        ryrzrz: This is a messagezm.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0: This is a messageN)rr	rJrr�r()r!r]�formats   r"�*test_getDeprecationWarningStringWithFormatzCDeprecationWarningsTests.test_getDeprecationWarningStringWithFormat]sO���)�Q��1�-��+�.C�C�����'��5�5�w��
�AI�
K�		
r$c����tdddd�}t|�t���fd�}td��5}t	d�|�|j|djt�|jt|dj�tt|��|j|djjd�tjd��d	d	d	�y	#1swYy	xYw)
zK
        Decorating a callable with L{deprecated} emits a warning.
        ryrzrc�����yrr,)�dummys�r"rhzJDeprecationWarningsTests.test_deprecateEmitsWarning.<locals>.addStackLevelts����Gr$T��record�always�coN)rrr�rrrJrirm�strr^rr��rstripr�)r!r]rh�caughtr�s    @r"�test_deprecateEmitsWarningz3DeprecationWarningsTests.test_deprecateEmitsWarningms�����)�Q��1�-��#�
�7�#�M�2��	��4�
(�		U�F���"��O����V�A�Y�/�/�1C�D�����F�1�I�%�%�&�+�M�7�C�
�

���V�A�Y�/�/�6�6�t�<�h�o�o�d�>S�T�		U�		U�		U�s�B-C,�,C5c���tdddd�}t|�t�}|jtj|j�|jtt�t|��y)zK
        The decorated function has the same name as the original.
        ryrzrN)rrr�rJr(�fullyQualifiedName�r!r]r�s   r"�test_deprecatedPreservesNamez5DeprecationWarningsTests.test_deprecatedPreservesName�s[���)�Q��1�-��#�
�7�#�M�2������/�/����@����+�M�:�<N�u�<U�Vr$c�X�tdddd�}|jdt|d��y)zr
        L{_getDeprecationDocstring} returns a note about the deprecation to go
        into a docstring.
        ryrzrzDeprecated in Twisted 8.0.0.�N)rrJrr�s  r"�test_getDeprecationDocstringz5DeprecationWarningsTests.test_getDeprecationDocstring�s/��
�)�Q��1�-�����*�,D�W�b�,Q�	
r$c��d�}tdddd�}t|�|�}t|t|d��|j	|j
|j
�y)zv
        The docstring of the deprecated function is appended with information
        about the deprecation.
        c��y)zc
            Do nothing.

            This is used to test the deprecation decorators.
            Nr,r,r$r"�localDummyCallablezTDeprecationWarningsTests.test_deprecatedUpdatesDocstring.<locals>.localDummyCallable�r�r$ryrzrrN)rrr
rrJr+)r!rr]r�s    r"�test_deprecatedUpdatesDocstringz8DeprecationWarningsTests.test_deprecatedUpdatesDocstring�sZ��	��)�Q��1�-��#�
�7�#�$6�7���-�/G��QS�/T�U����+�3�3�U�]�]�Cr$c��tdddd�}t|�t�}|j||j�y)zt
        Deprecating a function adds version information to the decorated
        version of that function.
        ryrzrN)rrr�rJ�deprecatedVersionrs   r"�test_versionMetadataz-DeprecationWarningsTests.test_versionMetadata�s;��
�)�Q��1�-��#�
�7�#�M�2������%�"9�"9�:r$c��tdddd�}t|j|d��}|j|t	|j��d��y)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.
        ryrzr�something.foobar��replacementzE was deprecated in Twisted 8.0.0; please use something.foobar insteadN)rrr�rJr�r!r]�
warningStrings   r"�+test_getDeprecationWarningStringReplacementzDDeprecationWarningsTests.test_getDeprecationWarningStringReplacement�sT���)�Q��1�-��3��1�1��*�
�
�
	
����+�D�,Q�,Q�R�
U�	
r$c��tdddd�}t|j|t��}|j	|t|j��dt�d��y)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.
        ryrzrrz- was deprecated in Twisted 8.0.0; please use z.dummyReplacementMethod insteadN)rrr�r�rJrr(rs   r"�7test_getDeprecationWarningStringReplacementWithCallablezPDeprecationWarningsTests.test_getDeprecationWarningStringReplacementWithCallable�sX���)�Q��1�-��3��1�1��.�
�
�
	
����"�$�"G�"G�H�(�
T�	
r$N)r(r)r*r�r�rrr	r
rrrr,r$r"r�r�Ps2��

�
� U�*W�
�D�(;�
�&
r$r�ryrPrx�c��eZdZdZy)�DeprecatedClasszJ
    Class which is entirely deprecated without having a replacement.
    N)r(r)r*r+r,r$r"rr�s��r$rc�f�eZdZdZdZeedddd��d��Zejd��Zy)	�ClassWithDeprecatedPropertyz2
    Class with a single deprecated property.
    NryrPrxrc��|jS)zC
        Getter docstring.

        @return: The property.
        ��_someProtectedValuer&s r"�somePropertyz(ClassWithDeprecatedProperty.someProperty�s���'�'�'r$c��||_y)z#
        Setter docstring.
        Nr r s  r"r"z(ClassWithDeprecatedProperty.someProperty�s��
$)�� r$)	r(r)r*r+r!rrr"�setterr,r$r"rr�sK�������	�1�a��3�4�(�5�(����)��)r$r�r0c��y)z7
    Function with a deprecated keyword parameter.
    Nr,)�a�b�cr0�bars     r"�functionWithDeprecatedParameterr+�r�r$c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�DeprecatedDecoratorTestsz*
    Tests for deprecated decorators.
    c��|j||jj�D�cgc]#}|j�s�|j���%c}�ycc}w)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}
        N)rJr+�
splitlines�strip)r!�target�expectedr�s    r"�assertDocstringz(DeprecatedDecoratorTests.assertDocstrings@��	
����&�.�.�*C�*C�*E�S�Q�����q�w�w�y�S�	
��Ss
�A
�A
c��t�}|j|jtjgd��tdddd�tj_d}|j|jg�}|jdt|��|jt|dd�|j||dd	�y
)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.ryrPrxr�ktwisted.python.test.test_deprecate.ClassWithDeprecatedProperty.someProperty was deprecated in Twisted 1.2.3rrir^N)
rr"r3rrrk�test_propertyGetterrJrnrm)r!�objr^r�s    r"r7z,DeprecatedDecoratorTests.test_propertyGetters���*�+��������'�4�4�
�	
�FM��q�!�Q�F
�#�0�0�B�

;�	��%�%�t�'?�'?�&@�A������C��M�*����+�X�a�[��-D�E�����(�1�+�i�"8�9r$c�L�t�}t�}||_|j||j�d}|j|jg�}|jdt|��|jt|dd�|j||dd�y)z}
        When L{deprecatedProperty} is used on a C{property}, setter accesses
        raise a L{DeprecationWarning}.
        r6rPrrir^N)
rHrr"r>r!rk�test_propertySetterrJrnrm)r!�newValuer8r^r�s     r"r:z,DeprecatedDecoratorTests.test_propertySetter4s���
�8��)�+��#����
�
�h�� 7� 7�8�
;�	��%�%�t�'?�'?�&@�A������C��M�*����+�X�a�[��-D�E�����(�1�+�i�"8�9r$c�P�t�|jtddg�tdddd�t_d}|j	|j
g�}|j
dt|��|j
t|dd	�|j
||dd
�y)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.r5ryrPrxrzRtwisted.python.test.test_deprecate.DeprecatedClass was deprecated in Twisted 1.2.3rrir^N)	rr3rrrk�
test_classrJrnrm)r!r^r�s   r"r=z#DeprecatedDecoratorTests.test_classHs���	������V�.�
�	
�-4�I�q�!�Q�,G��)�
.�	��%�%�t���&7�8������C��M�*����+�X�a�[��-D�E�����(�1�+�i�"8�9r$c��tdddd�}t|d�t�}|j|jd�y)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.
        ryrzrrz�
    Do nothing.

    This is used to test the deprecation decorators.

    Deprecated in Twisted 8.0.0; please use something.foobar instead.
    N)rrr�rJr+rs   r"�test_deprecatedReplacementz3DeprecatedDecoratorTests.test_deprecatedReplacementcsB���)�Q��1�-��7�
�7�$6�7�
�F������M�M�
�		
r$c��tdddd�}t|t��}|t�}|j	|j
dt�d��y)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.
        ryrzrrzt
    Do nothing.

    This is used to test the deprecation decorators.

    Deprecated in Twisted 8.0.0; please use z%.dummyReplacementMethod instead.
    N)rrr�r�rJr+r()r!r]�	decoratorr�s    r"�&test_deprecatedReplacementWithCallablez?DeprecatedDecoratorTests.test_deprecatedReplacementWithCallablewsJ���)�Q��1�-���w�4J�K�	��-�(������M�M��
!�	
r$c�
�d}td��5}td�tdd�|j|g�tddd�|j|g�tddd�	�|jt	|�d
�|j|dj
t�|jt|dj�|�|j�tddd�
�|j|g�tdddd�|jt	|�d
�|j|dj
t�|jt|dj�|�ddd�y#1swYyxYw)NzzThe 'foo' parameter to twisted.python.test.test_deprecate.functionWithDeprecatedParameter was deprecated in Twisted 19.2.0Tr�r��
���()r0rPr�2)r*)
rrr+rJrnrirmr�r^r�)r!r^�wss   r"�test_deprecatedKeywordParameterz8DeprecatedDecoratorTests.test_deprecatedKeywordParameter�s>��
/�	��4�
(�	:�B���"�+�B��3����R��$�+�B��B�7����R��$�+�B���;����S��W�a�(����R��U�^�^�-?�@����S��A����/��9��H�H�J�+�B���;����R��$�+�B��B��;����S��W�a�(����R��U�^�^�-?�@����S��A����/��9�+	:�	:�	:�s�E!E9�9FN)r(r)r*r+r3r7r:r=r?rBrJr,r$r"r-r-s+���

�:�@:�(:�6
�(
�(:r$r-c�"�eZdZdZd�Zd�Zd�Zy)�AppendToDocstringTestszk
    Test the _appendToDocstring function.

    _appendToDocstring is used to add text to a docstring.
    c�Z�d�}t|d�|jd|j�y)zP
        Appending to an empty docstring simply replaces the docstring.
        c��yrr,r,r$r"�noDocstringzGAppendToDocstringTests.test_appendToEmptyDocstring.<locals>.noDocstring�r�r$�Appended text.N�r
rJr+)r!rOs  r"�test_appendToEmptyDocstringz2AppendToDocstringTests.test_appendToEmptyDocstring�s+��
	�	�;�(8�9����)�;�+>�+>�?r$c���d�}t|d�|jgd�|jj��|j	|jjd��y)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.
        c��y)�;This doesn't comply with standards, but is here for a test.Nr,r,r$r"�singleLineDocstringzTAppendToDocstringTests.test_appendToSingleLineDocstring.<locals>.singleLineDocstring�r�r$rP)rUrrP�
N)r
rJr+r/r�r�)r!rVs  r"� test_appendToSingleLineDocstringz7AppendToDocstringTests.test_appendToSingleLineDocstring�s]��	N�	�.�0@�A����
�

 �'�'�2�2�4�
	
�	
���+�3�3�<�<�T�B�Cr$c�t�d�}d�}t|d�|j|j|j�y)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.
        c��y)z9
            This is a multi-line docstring.
            Nr,r,r$r"�multiLineDocstringzRAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.multiLineDocstring�r�r$c��y)zU
            This is a multi-line docstring.

            Appended text.
            Nr,r,r$r"�expectedDocstringzQAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.expectedDocstring�r�r$rPNrQ)r!r[r]s   r"�test_appendToMultilineDocstringz6AppendToDocstringTests.test_appendToMultilineDocstring�s8��	�
	�	�-�/?�@����*�2�2�4F�4N�4N�Or$N)r(r)r*r+rRrXr^r,r$r"rLrL�s���	@�D�2Pr$rLc�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�MutualArgumentExclusionTestsz2
    Tests for L{mutuallyExclusiveArguments}.
    c��ttdd�r ttj|�||�St	tj
|�||�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)rA�inspectrrbr�
getargspec�r!�func�args�kws    r"�checkPassedz(MutualArgumentExclusionTests.checkPassed�sF���7�K��.�#�G�$5�$5�d�$;�T�2�F�F�"�'�"4�"4�T�":�D�"�E�Er$c�f�d�}|j|j|dd�tdd���y)z`
        L{passed} identifies the arguments passed by a simple
        positional test.
        c��yrr,�r'r(s  r"rfzGMutualArgumentExclusionTests.test_passed_simplePositional.<locals>.funcr�r$rPrxrlN�rJrir��r!rfs  r"�test_passed_simplePositionalz9MutualArgumentExclusionTests.test_passed_simplePositional
s.��	�	
����)�)�$��1�5�t�a�1�~�Fr$c�R�d�}|jt|j|ddd�y)z[
        L{passed} raises a L{TypeError} if too many arguments are
        passed.
        c��yrr,rls  r"rfzBMutualArgumentExclusionTests.test_passed_tooManyArgs.<locals>.funcr�r$rPrxrN�r?�	TypeErrorrirns  r"�test_passed_tooManyArgsz4MutualArgumentExclusionTests.test_passed_tooManyArgss'��	�	
���)�T�%5�%5�t�Q��1�Er$c�R�d�}|jt|j|dd��y)zs
        L{passed} raises a L{TypeError} if a argument is passed both
        positionally and by keyword.
        c��yrr,�r's r"rfzHMutualArgumentExclusionTests.test_passed_doublePassKeyword.<locals>.func&r�r$rPrxrwNrrrns  r"�test_passed_doublePassKeywordz:MutualArgumentExclusionTests.test_passed_doublePassKeyword �(��	�	
���)�T�%5�%5�t�Q�!��Dr$c�R�d�}|jt|j|dd��y)z�
        L{passed} raises a L{TypeError} if a keyword argument not
        present in the function's declaration is passed.
        c��yrr,rws r"rfzIMutualArgumentExclusionTests.test_passed_unspecifiedKeyword.<locals>.func1r�r$rPrx)�zNrrrns  r"�test_passed_unspecifiedKeywordz;MutualArgumentExclusionTests.test_passed_unspecifiedKeyword+ryr$c�h�d�}|j|j|ddd�tdd���y)z|
        L{passed} places additional positional arguments into a tuple
        under the name of the star argument.
        c��yrr,rls  r"rfz;MutualArgumentExclusionTests.test_passed_star.<locals>.func<r�r$rPrxr)rxrrlNrmrns  r"�test_passed_starz-MutualArgumentExclusionTests.test_passed_star6s1��	�	
����)�)�$��1�a�8�$��f�:M�Nr$c��d�}|j|j|dddd��tdtddd�����y)	zn
        Additional keyword arguments are passed as a dict to the star star
        keyword argument.
        c��yrr,rls  r"rfz?MutualArgumentExclusionTests.test_passed_starStar.<locals>.funcGr�r$rPrxr�)r��yr|rlNrmrns  r"�test_passed_starStarz1MutualArgumentExclusionTests.test_passed_starStarAsC��	�	
������T�1��Q�!��4�d�Q�$��a�ST�BU�6V�	
r$c�n�dd�}|j|j|ddd��tddd���y)	zp
        The results of L{passed} only include arguments explicitly
        passed, not default values.
        rPrxc��yrr,�r'r(r)�d�es     r"rfzFMutualArgumentExclusionTests.test_passed_noDefaultValues.<locals>.funcTr�r$�)r�)r'r(r�N�rPrxrrmrns  r"�test_passed_noDefaultValuesz8MutualArgumentExclusionTests.test_passed_noDefaultValuesNs6��	�	
����)�)�$��1��)�:�D�1��Q�<O�Pr$c���tdg�dd��}|j|dd�d�|j|ddd�d�|j|ddd��d	�y
)z�
        L{mutuallyExclusiveArguments} does not interfere in its
        decoratee's operation, either its receipt of arguments or its return
        value.
        rlc��||z|z|zSrr,)r�r�r'r(s    r"rfzMMutualArgumentExclusionTests.test_mutualExclusionPrimeDirective.<locals>.func`s���q�5�1�9�q�=� r$rPrxrDr���r(�
N�rr�)rrJrns  r"�"test_mutualExclusionPrimeDirectivez?MutualArgumentExclusionTests.test_mutualExclusionPrimeDirectiveYse��
%�j�\�	2�	!�
3�	!�	
����a���R�(�����a��A���+�����a��a��"�-r$c�`�tddgg�dd��}|jt|dd��y)	z�
        L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
        decoratee is passed a pair of mutually exclusive arguments.
        r'r(rr�c��||zSrr,rls  r"rfzPMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeyword.<locals>.funcns���q�5�Lr$rlNr�)rr?rsrns  r"�%test_mutualExclusionExcludesByKeywordzBMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeywordhs:��
%�s�C�j�\�	2�	�
3�	�	
���)�T�Q�!��4r$c��Gd�d�}Gd�d�}d�}|dd�tj|�j}|j�}|dd�|d	<||�}|j	t
t|d
i�y)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��eZdZd�Zy)�MMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignaturec��||_yr)�
parameters)r!r�s  r"r#zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignature.__init__|s	��",��r$N�r(r)r*r#r,r$r"�
FakeSignaturer�{s��
-r$r�c��eZdZd�Zy)�MMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameterc� �||_||_yr)ro�kind)r!ror�s   r"r#zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameter.__init__�s�� ��	� ��	r$Nr�r,r$r"�
FakeParameterr�s��
!r$r�c��yrr,rls  r"rfzDMutualArgumentExclusionTests.test_invalidParameterType.<locals>.func�r�r$rPrx�faker)�rPrxN)rcrbr�r�r?rsr)r!r�r�rfr��dummyParameters�fakeSigs       r"�test_invalidParameterTypez6MutualArgumentExclusionTests.test_invalidParameterTypetsz��	-�	-�	!�	!�
	�	
�Q��
��&�&�t�,�7�7�
�$�/�/�+��,�V�V�<������0�����)�%5�w���Kr$N)r(r)r*r+rirortrxr}r�r�r�r�r�r�r,r$r"r`r`�sF���F�,	G�	F�	E�	E�	O�
�	Q�
.�
5�Lr$r`c��eZdZdZd�Zd�Zy)�KeywordOnlyTestsz,
    Keyword only arguments (PEP 3102).
    c�B�ttj|�||�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}
        )rrcrbres    r"rizKeywordOnlyTests.checkPassed�s�� �� 1� 1�$� 7��r�B�Br$c��dd�d�}dd�d�}|j|j|ddd�tdd�	��|j|j|dddd
��tdd
�	��|j|j|ddd
ddd��tdd
ddd�
��|jt|j|ddd
dd��y)z`
        Keyword only arguments follow varargs.
        They are specified in PEP 3102.
        Tr�c��y)zM
            b is a keyword-only argument, with a default value.
            Nr,)r(r's  r"�func1z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func1�r�r$c��y)zd
            b, c, d, e  are keyword-only arguments.
            b has a default value.
            Nr,)r(r)r�r�r's     r"�func2z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func2�r�r$rPrxrr�rlF)r(r)r�r�r�r�)r(r)r�N)rJrir�r?rs)r!r�r�s   r"�test_passedKeywordOnlyz'KeywordOnlyTests.test_passedKeywordOnly�s����	�
�	�	
����)�)�%��A�q�9�4�)�t�;T�U�������U�A�q�!�u��5�t�i�5�7Q�	
�	
������U�A�q�E�Q�!�q��A��6�U�a�1��2�	
�	
���)�T�%5�%5�u�a��e�q�TU��Vr$N)r(r)r*r+rir�r,r$r"r�r��s���C�"Wr$r�r�)7r+rcr{r1r��os.pathrrr�	importlibr�ImportError�incrementalr�twisted.pythonr�twisted.python.deprecater	r
rrrr
rrrrrrr�twisted.python.filepathr�twisted.python.runtimer�twisted.python.testr�#twisted.python.test.modules_helpersr�twisted.trial.unittestrrr.r[r�r�r�r�r�rrr+r-rLr`r�r,r$r"�<module>r�ss���
�
����1��+� �$�
�
�
�
�-�+�4�C�6���"DY�*�DY�N_@�2�_@�Dl%�#6�8K�l%�^c
�0�c
�L��G
�2�G
�T�G�I�q�!�Q�'�(���)��)�)�0�G�I�r�1�a�8�%�@��A��h:�2�h:�VAP�0�AP�H]L�#6�]L�@/W�*�/W��{#�����s�D$�$D/�.D/

Zerion Mini Shell 1.0