
    tf                        d Z ddlZddlZddlZddlZddlmZ ddlmZmZ 	 ddl	m
Z
 n# e$ r dZ
Y nw xY wddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ dd	lmZ dd
l m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'  G d d          Z( G d de'          Z) G d de'          Z* G d de%e'          Z+ G d de'          Z,d Z-d Z. G d de'          Z/ e edddd                     G d  d!                      Z0 G d" d#          Z1 e edd$dd          d%          d/d&            Z2 G d' d(e'          Z3 G d) d*e'          Z4 G d+ d,e'          Z5 G d- d.e'          Z6dS )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                       e Zd ZdZd Zd ZdS )_MockDeprecatedAttributezq
    Mock of L{twisted.python.deprecate._DeprecatedAttribute}.

    @ivar value: The value of the attribute.
    c                     || _         d S Nvalueselfr   s     a/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/test_deprecate.py__init__z!_MockDeprecatedAttribute.__init__8   s    


    c                     | j         S )z$
        Get a known value.
        r   r!   s    r"   getz_MockDeprecatedAttribute.get;   s     zr$   N)__name__
__module____qualname____doc__r#   r'    r$   r"   r   r   1   s<               r$   r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	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                     t          j        d          }|                                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keyr   s        r"   
_makeProxyzModuleProxyTests._makeProxyI   sU     u%%++-- 	% 	%JCCe$$$$%c***r$   c                     |                      d          }|                     |j        d           |                     t          t
          |d           dS )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_getattrPassthroughV   sO     w77e*G444.'5:JKKKKKr$   c                     |                                  }t                              |d          }t          d          |d<   |                     |j        d           dS )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*   r0   N)r9   object__getattribute__r   assertEqualr0   )r!   rC   rF   s      r"   test_getattrInterceptz&ModuleProxyTests.test_getattrIntercept`   s[     !! & 7 7?V W W'?'C'Ce$B'''''r$   c                     |                                  }|                     t          t          |d           |                     t          t          |d           dS )z
        Private attributes of L{twisted.python.deprecate._ModuleProxy} are
        inaccessible when regular attribute access is used.
        _modulerF   N)r9   r?   r@   rA   rB   s     r"   test_privateAttributesz'ModuleProxyTests.test_privateAttributesk   sN    
 !!.'5)DDD.'5:QRRRRRr$   c                     |                                  }d|_        |                     t                              |d          d           |                     |j        d           dS )z
        Setting attributes on L{twisted.python.deprecate._ModuleProxy} proxies
        them through to the wrapped module.
           rM   N)r9   rM   assertNotEqualrH   rI   rJ   rB   s     r"   test_setattrzModuleProxyTests.test_setattrt   s^    
 !!F33E9EEqIII*****r$   c                     |                                  }t                              |d          }|                     t	          |          dt          |          j         d|d           dS )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)r9   rH   rI   rJ   reprtyper(   )r!   rC   
realModules      r"   	test_reprzModuleProxyTests.test_repr~   sg     !!,,UI>>
e&W$u++*>&W&W
&W&W&WXXXXXr$   N)
r(   r)   r*   r+   r9   rD   rK   rN   rR   rY   r,   r$   r"   r.   r.   B   s         + + +L L L	( 	( 	(S S S+ + +Y Y Y Y Yr$   r.   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )DeprecatedAttributeTestsz
    Tests for L{twisted.python.deprecate._DeprecatedAttribute} and
    L{twisted.python.deprecate.deprecatedModuleAttribute}, which issue
    warnings for deprecated module-level attributes.
    c                 h    t           j        | _        t           j        | _        t          dz   | _        d S )Nz.foo)r   versionmessager(   _testModuleNamer&   s    r"   setUpzDeprecatedAttributeTests.setUp   s)    +3+3'&0r$   c                     t          t          j        dz   |z   t          j        t          dz   t          j        z             S )zJ
        Create the warning string used by deprecated attributes.
        .z: )r   r   r(   r]   r	   r^   )r!   attrs     r"   _getWarningStringz*DeprecatedAttributeTests._getWarningString   s=     , )C/$6 (&-0D0LL
 
 	
r$   c                    d}t          t          |d           t          j        t          || j        | j                  |                     j        |           fd} |             |                     | j	        g          }| 
                    |d         d         t                     |                     |d         d         |                     |                     |                     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_ATTRIBUTErG   c                  0                                       d S r   )r'   )rc   s   r"   addStackLevelzNDeprecatedAttributeTests.test_deprecatedAttributeHelper.<locals>.addStackLevel   s    HHJJJJJr$   r   categoryr^   rP   N)r4   r   r   _DeprecatedAttributer]   r^   rJ   r(   flushWarningstest_deprecatedAttributeHelperr>   DeprecationWarningrd   len)r!   namerh   warningsShownrc   s       @r"   rl   z7DeprecatedAttributeTests.test_deprecatedAttributeHelper   s    .$dB///- $dl
 
 	---	 	 	 	 	 	**D,O+PQQmA&z24FGGGq))4d6L6LT6R6RSSS]++Q/////r$   c                    t           j         |                     | j        g          }|                     t          |          d           d}t          t           |           |                     | j        g          }|                     t          |          d           |                     |d         d         t                     |                     |d         d         | 	                    |                     dS )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_ATTRIBUTErP   ri   r^   N)
r   ANOTHER_ATTRIBUTErk   test_deprecatedAttributerJ   rn   rA   r>   rm   rd   )r!   rp   ro   s      r"   rt   z1DeprecatedAttributeTests.test_deprecatedAttribute   s     	..**D,I+JKK]++Q///% 	$d+++**D,I+JKK]++Q///mA&z24FGGGq))4d6L6LT6R6RSSSSSr$   c                 N   t          j        d          xt          j        | j        <   }|                     t          j        j        | j                   t          |dd           t          |dd           t          j	        t          dddd          d	| j        d           t          j        | j                 }|                     ||           t          j	        t          dddd          d	| j        d           |                     |t          j        | 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.
        r0   firstrP   second   Twisted   r   r^   N)r1   r2   sysmodulesr_   
addCleanuppopr4   r   deprecatedModuleAttributer   rQ   r>   )r!   r7   rC   s      r"   test_wrappedModulez+DeprecatedAttributeTests.test_wrappedModule   s    382B52I2IID()C)=>>>Wa   Xq!!!+Iq!Q''D4H'	
 	
 	
 D01E3'''+Iq!Q''D4H(	
 	
 	
 	eS[)=>?????r$   N)	r(   r)   r*   r+   r`   rd   rl   rt   r   r,   r$   r"   r[   r[      sq         1 1 1

 
 
0 0 04T T T.@ @ @ @ @r$   r[   c                   4    e Zd ZdZdZd Zd Zd Zd Zd Z	dS )	ImportedModuleAttributeTestsza
    Tests for L{deprecatedModuleAttribute} which involve loading a module via
    'import'.
    zfrom twisted.python.deprecate import deprecatedModuleAttribute
from incremental import Version

deprecatedModuleAttribute(
    Version('Package', 1, 2, 3), 'message', __name__, 'module')
c                    fdt          |                                                     d                    }|                                  ||          }|                     |j                            d          gt          j        z              |                     t          j	        
                                           |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                 X   i }|                                 D ]\  }}|                     |          }t          |t                    r|||<   |                    |           Jt          |t
                    r$|                                  ||          ||<   t          d          |S )Nz(only strings and dicts allowed as values)r3   child
isinstancebytes
setContentdictcreateDirectory
ValueError)pathobjdirdictpathdictr8   r   r   makeSomeFiless         r"   r   zAImportedModuleAttributeTests.pathEntryTree.<locals>.makeSomeFiles  s    H%mmoo 	Q 	Q
Uc**eU++ Q$)HSM$$U++++t,, Q))+++$1M%$?$?HSMM$%OPPPOr$   utf-8)r   mktempencodemakedirsreplaceSysPathpathdecoder{   replaceSysModulesr|   copy)r!   treebaseresultr   s       @r"   pathEntryTreez*ImportedModuleAttributeTests.pathEntryTree   s    	 	 	 	 	 ,,W5566tT**TY--g667#(BCCCs{//11222r$   c                     |                      d| j                            d          ddi          }|d         d         S )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}.
        s   packager   r$   )s   __init__.py	   module.pyr   )r   _packageInitr   )r!   pathss     r"   simpleModuleEntryz.ImportedModuleAttributeTests.simpleModuleEntry  sT    
 ""$($5$<$<W$E$E"% 
 
 Z ..r$   c                    ddl m} |                     t          |j                            d                    |           |                     | j        g          }|                     t          |          d           |                     |d         d         d           |                     |d         d         t                     dS )	zB
        Verification logic for L{test_deprecatedModule}.
        r   moduler   rP   r^   z7package.module was deprecated in Package 1.2.3: messageri   N)
packager   rJ   r   __file__r   rk   checkOneWarningrn   rm   )r!   
modulePathr   emitteds       r"   r   z,ImportedModuleAttributeTests.checkOneWarning.  s     	#"""""&/"8"8"A"ABBJOOO$$d&:%;<<Wq)))AJy!H	
 	
 	
 	J/1CDDDDDr$   c                 T    |                      |                                            dS )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566666r$   c                     |                                  }|                     |           |                     |           t          d          D ]}|                     |           dS )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.
        rx   N)r   r   range)r!   mpxs      r"   "test_deprecatedModuleMultipleTimesz?ImportedModuleAttributeTests.test_deprecatedModuleMultipleTimesE  sw     ##%%R    	R    q 	% 	%A  $$$$	% 	%r$   N)
r(   r)   r*   r+   r   r   r   r   r   r   r,   r$   r"   r   r      st         
L$ $ $L/ / /E E E7 7 7% % % % %r$   r   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )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          |                                                               d          | _        | j                                         | j                            d                              d           | j                            d                              d           | j                            d                              d           | j                                        j        }t          j        	                    d|           | 
                    t          j        j        |           t          j                                        | 
                    fd	           t          j                    r|                                  d
S d
S )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")
r   c                  ~    t           j                                        t           j                                       fS r   )r{   r|   clearupdate)r|   s   r"   <lambda>z.WarnAboutFunctionTests.setUp.<locals>.<lambda>  s*    !2!2!4!4ck6H6H6Q6Q R r$   N)r   r   r   r   r   r   parentr   r{   insertr}   remover|   r   r   	isWindowsrk   )r!   packagePathr|   s     @r"   r`   zWarnAboutFunctionTests.setUp`  si     ..445MNN=))44S999;''22	
 	
 	
" 	;''22	
 	
 	
0 l))++0;'''555+""$$RRRRSSS
  	!     	! 	!r$   c                    d }t          j        |d           |                                 }t          }|                                                    d          r
|dd         }|                     t          |d         d                   t          |                     |                     |d         d         d           dS )	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                      d S r   r,   r,   r$   r"   aFuncz2WarnAboutFunctionTests.test_warning.<locals>.aFunc      Dr$   zA Warning Messagez.pycNr   filenamer^   )	r   warnAboutFunctionrk   r   lowerendswithassertSamePathr   rJ   )r!   r   rp   r   s       r"   test_warningz#WarnAboutFunctionTests.test_warning  s    	 	 	 	#E+>???**,,>>$$V,, 	%}HH]1%5j%ABBHXDVDVWWWq))46IJJJJJr$   c                 
   ddl m} |                                 |                                 }|                     t          |d         d                             d                    | j                            d          	                    d                     | 
                    |d         d         d           | 
                    |d         d	         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.
        r   r   r   r      twisted_private_helperr   lineno	   r^   A Warning StringrP   N)r   r   callTestFunctionrk   r   r   r   r   siblingr   rJ   rn   r!   r   rp   s      r"   test_warningLineNumberz-WarnAboutFunctionTests.test_warningLineNumber  s    
 	211111!!!**,,]1%j188AABBL  !:;;AA,OO	
 	
 	
 	q)(3Q777q))46HIII]++Q/////r$   c                 
   ddl m} |                                 |                                 }|                     t          |d         d                             d                    | j                            d          	                    d                     | 
                    |d         d         d           | 
                    |d         d	         d
           | 
                    t          |          d           dS )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   rP   N)r   r   r   rk   r   r   r   r   r   r   rJ   rn   )r!   r   rp   s      r"   'test_warningLineNumberDisFindlinestartsz>WarnAboutFunctionTests.test_warningLineNumberDisFindlinestarts  s     	211111!!!**,,]1%j188AABBL  !:;;AA,OO	
 	
 	
 	q)(3R888q))46HIII]++Q/////r$   c                     |                      t          |j                  t          |j                  k    |d|           dS )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)
assertTruer   r   )r!   rv   rw   s      r"   r   z%WarnAboutFunctionTests.assertSamePath  sQ     	UZ  HV[$9$99&&F&&	
 	
 	
 	
 	
r$   c                    ddl m} t          j        d= t          j        |j        = | j                            | j                            d                     t          rt                       ddl	m} | 
                    t          j        j        d           | 
                    t          j        j        |j                   |                                 |                     |j        g          }t          |d         d                             d                    }| j                            d                              d          }|                     ||           |                     |d         d	         d
           |                     |d         d         d           |                     t)          |          d           dS )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.
        r   r   r   s   twisted_renamed_helpertwisted_renamed_helperr   r   r   r   r   r^   r   rP   N)r   r   r{   r|   r(   r   moveTor   r   r   r}   r~   r   rk   testFunctionr   r   r   r   rJ   rn   )r!   r   rp   
warnedPathexpectedPaths        r"   test_renamedFilez'WarnAboutFunctionTests.test_renamedFile  s    	211111 K01K( 	DL001JKKLLL  	  	211111)ABBB999!!!**F,?+@AAmA.z:AA'JJKK
|++,EFFLL
 
 	J555q)(3Q777q))46HIII]++Q/////r$   c                     t           j        dd= t          j        dd           ddlm} |                                 |                                 }|                     t          |          d           dS )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   r   r   )	warningsfiltersfilterwarningsr   r   r   rk   rJ   rn   r   s      r"   test_filteredWarningz+WarnAboutFunctionTests.test_filteredWarning  s     QQQx8PQQQQ111111!!!**,,]++Q/////r$   c                    t           j        dd= t          j        dd           ddlm} |                                 |                                 |                                 }|                     t          |          d           |d         d         }|d         d	         }|d         d
         }|d         d         }t          j	        ||||          }| 
                    |                    d          d|           dS )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   r   r   rP   r^   ri   r   r   z=module.py:9: DeprecationWarning: A Warning String
  return a
zUnexpected warning string: )r   r   r   r   r   r   rk   rJ   rn   formatwarningr   r   )r!   r   rp   r^   ri   r   r   msgs           r"   test_filteredOnceWarningz/WarnAboutFunctionTests.test_filteredOnceWarning  s"    QQQx8PQQQQ111111!!!!!!**,,]++Q///"9- #J/ #J/q!(+$Wh&IILLT  2#11		
 	
 	
 	
 	
r$   N)r(   r)   r*   r+   r`   r   r   r   r   r   r   r   r,   r$   r"   r   r   Z  s         
;! ;! ;!zK K K$0 0 0&0 0 0(
 
 
$0 $0 $0L0 0 0(
 
 
 
 
r$   r   c                      dS )zK
    Do nothing.

    This is used to test the deprecation decorators.
    Nr,   r,   r$   r"   dummyCallabler   @        r$   c                      dS )z[
    Do nothing.

    This is used to test the replacement parameter to L{deprecated}.
    Nr,   r,   r$   r"   dummyReplacementMethodr   H  r   r$   c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )DeprecationWarningsTestsc                     t          dddd          }|                     t          | j        |          t          d           dS )z
        L{getDeprecationWarningString} returns a string that tells us that a
        callable was deprecated at a certain released version of Twisted.
        ry   rz   r   zZ.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0N)r   rJ   r    test_getDeprecationWarningStringr(   r!   r]   s     r"   r   z9DeprecationWarningsTests.test_getDeprecationWarningStringQ  sU    
 )Q1--'(MwWW19<	
 	
 	
 	
 	
r$   c                     t          dddd          }t          dz   }|                     t          | j        ||          t
          d           dS )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.
        ry   rz   r   z: This is a messagezm.DeprecationWarningsTests.test_getDeprecationWarningString was deprecated in Twisted 8.0.0: This is a messageN)r   r	   rJ   r   r   r(   )r!   r]   formats      r"   *test_getDeprecationWarningStringWithFormatzCDeprecationWarningsTests.test_getDeprecationWarningStringWithFormat]  sl     )Q1--+.CC'5w  AIK		
 	
 	
 	
 	
r$   c                 Z   t          dddd          } t          |          t                    fd}t          d          5 }t	          d            |             |                     |d         j        t                     |                     t          |d         j	                  t          t          |                     |                     |d         j                            d          t                              d                     d	d	d	           d	S # 1 swxY w Y   d	S )
zK
        Decorating a callable with L{deprecated} emits a warning.
        ry   rz   r   c                                     d S r   r,   )dummys   r"   rh   zJDeprecationWarningsTests.test_deprecateEmitsWarning.<locals>.addStackLevelt  s    EGGGGGr$   TrecordalwayscoN)r   r   r   r   r   rJ   ri   rm   strr^   r   r   rstripr   )r!   r]   rh   caughtr   s       @r"   test_deprecateEmitsWarningz3DeprecationWarningsTests.test_deprecateEmitsWarningm  sv    )Q1--#
7##M22	 	 	 	 	 4((( 		UF"""MOOOVAY/1CDDDF1I%&&+M7CC  
 VAY/66t<<hood>S>STTT		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		U 		Us   CD  D$'D$c                    t          dddd          } t          |          t                    }|                     t          j        |j                   |                     t          t                    t          |                     dS )zK
        The decorated function has the same name as the original.
        ry   rz   r   N)r   r   r   rJ   r(   fullyQualifiedNamer!   r]   r   s      r"   test_deprecatedPreservesNamez5DeprecationWarningsTests.test_deprecatedPreservesName  sw     )Q1--#
7##M22/@@@+M::<Nu<U<UVVVVVr$   c                 r    t          dddd          }|                     dt          |d                     dS )zr
        L{_getDeprecationDocstring} returns a note about the deprecation to go
        into a docstring.
        ry   rz   r   zDeprecated in Twisted 8.0.0. N)r   rJ   r   r   s     r"   test_getDeprecationDocstringz5DeprecationWarningsTests.test_getDeprecationDocstring  sI    
 )Q1--*,DWb,Q,Q	
 	
 	
 	
 	
r$   c                     d }t          dddd          } t          |          |          }t          |t          |d                     |                     |j        |j                   dS )zv
        The docstring of the deprecated function is appended with information
        about the deprecation.
        c                      dS )zc
            Do nothing.

            This is used to test the deprecation decorators.
            Nr,   r,   r$   r"   localDummyCallablezTDeprecationWarningsTests.test_deprecatedUpdatesDocstring.<locals>.localDummyCallable  r   r$   ry   rz   r   r  N)r   r   r
   r   rJ   r+   )r!   r  r]   r   s       r"   test_deprecatedUpdatesDocstringz8DeprecationWarningsTests.test_deprecatedUpdatesDocstring  s}    	 	 	 )Q1--#
7##$677-/GQS/T/TUUU+3U]CCCCCr$   c                     t          dddd          } t          |          t                    }|                     ||j                   dS )zt
        Deprecating a function adds version information to the decorated
        version of that function.
        ry   rz   r   N)r   r   r   rJ   deprecatedVersionr  s      r"   test_versionMetadataz-DeprecationWarningsTests.test_versionMetadata  sM    
 )Q1--#
7##M22%"9:::::r$   c                     t          dddd          }t          | j        |d          }|                     |t	          | j                  d           dS )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.
        ry   rz   r   something.foobarreplacementzE was deprecated in Twisted 8.0.0; please use something.foobar insteadN)r   r   r   rJ   r  r!   r]   warningStrings      r"   +test_getDeprecationWarningStringReplacementzDDeprecationWarningsTests.test_getDeprecationWarningStringReplacement  sx     )Q1--31*
 
 

 	+D,QRRRRU	
 	
 	
 	
 	
r$   c                     t          dddd          }t          | j        |t                    }|                     |t          | j                  dt          d           dS )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.
        ry   rz   r   r  z- was deprecated in Twisted 8.0.0; please use z.dummyReplacementMethod insteadN)r   r   r   r   rJ   r  r(   r  s      r"   7test_getDeprecationWarningStringReplacementWithCallablezPDeprecationWarningsTests.test_getDeprecationWarningStringReplacementWithCallable  s     )Q1--31.
 
 

 	 "$"GHHHH(((T	
 	
 	
 	
 	
r$   N)r(   r)   r*   r   r   r  r  r	  r  r  r  r  r,   r$   r"   r   r   P  s        

 

 


 
 
 U U U*W W W
 
 
D D D(; ; ;
 
 
&
 
 
 
 
r$   r   ry   rP   rx      c                       e Zd ZdZdS )DeprecatedClasszJ
    Class which is entirely deprecated without having a replacement.
    N)r(   r)   r*   r+   r,   r$   r"   r  r    s           r$   r  c                   v    e Zd ZdZdZ e edddd                    d             Zej        d             ZdS )	ClassWithDeprecatedPropertyz2
    Class with a single deprecated property.
    Nry   rP   rx   r  c                     | j         S )zC
        Getter docstring.

        @return: The property.
        _someProtectedValuer&   s    r"   somePropertyz(ClassWithDeprecatedProperty.someProperty  s     ''r$   c                     || _         dS )z#
        Setter docstring.
        Nr   r    s     r"   r"  z(ClassWithDeprecatedProperty.someProperty  s    
 $)   r$   )	r(   r)   r*   r+   r!  r   r   r"  setterr,   r$   r"   r  r    sz          	1a3344( ( 54( ) ) ) ) )r$   r     r0   c                     dS )z7
    Function with a deprecated keyword parameter.
    Nr,   )abcr0   bars        r"   functionWithDeprecatedParameterr+    r   r$   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
DeprecatedDecoratorTestsz*
    Tests for deprecated decorators.
    c                 t    |                      |d |j                                        D                        dS )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}
        c                 ^    g | ]*}|                                 |                                 +S r,   )strip).0r   s     r"   
<listcomp>z<DeprecatedDecoratorTests.assertDocstring.<locals>.<listcomp>  s-    SSSQSqwwyySSSr$   N)rJ   r+   
splitlines)r!   targetexpecteds      r"   assertDocstringz(DeprecatedDecoratorTests.assertDocstring  sH     	SS&.*C*C*E*ESSS	
 	
 	
 	
 	
r$   c                    t                      }|j         |                     t           j        g d           t          dddd          t           j        _        d}|                     | j        g          }|                     dt          |                     |                     t          |d         d                    |                     ||d         d	                    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.
        )zGetter docstring.z@return: The property.Deprecated in Twisted 1.2.3.ry   rP   rx   r  ktwisted.python.test.test_deprecate.ClassWithDeprecatedProperty.someProperty was deprecated in Twisted 1.2.3r   ri   r^   N)
r  r"  r6  r   r  rk   test_propertyGetterrJ   rn   rm   )r!   objr^   r   s       r"   r:  z,DeprecatedDecoratorTests.test_propertyGetter  s     *++'4  	
 	
 	
 FMq!QF
 F
#0B
; 	 %%t'?&@AACMM***+Xa[-DEEE(1+i"899999r$   c                    t                      }t                      }||_        |                     ||j                   d}|                     | j        g          }|                     dt          |                     |                     t          |d         d                    |                     ||d         d                    dS )z}
        When L{deprecatedProperty} is used on a C{property}, setter accesses
        raise a L{DeprecationWarning}.
        r9  rP   r   ri   r^   N)
rH   r  r"  r>   r!  rk   test_propertySetterrJ   rn   rm   )r!   newValuer;  r^   r   s        r"   r=  z,DeprecatedDecoratorTests.test_propertySetter4  s    
 88)++#h 7888; 	 %%t'?&@AACMM***+Xa[-DEEE(1+i"899999r$   c                    t                       |                     t           ddg           t          dddd          t           _        d}|                     | j        g          }|                     dt          |                     |                     t          |d         d	                    |                     ||d         d
                    dS )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.r8  ry   rP   rx   r  zRtwisted.python.test.test_deprecate.DeprecatedClass was deprecated in Twisted 1.2.3r   ri   r^   N)	r  r6  r   r  rk   
test_classrJ   rn   rm   )r!   r^   r   s      r"   r@  z#DeprecatedDecoratorTests.test_classH  s     	V.	
 	
 	
 -4Iq!Q,G,G). 	 %%t&788CMM***+Xa[-DEEE(1+i"899999r$   c                     t          dddd          } t          |d          t                    }|                     |j        d           dS )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.
        ry   rz   r   r  z
Do nothing.

This is used to test the deprecation decorators.

Deprecated in Twisted 8.0.0; please use something.foobar instead.
N)r   r   r   rJ   r+   r  s      r"   test_deprecatedReplacementz3DeprecatedDecoratorTests.test_deprecatedReplacementc  s]     )Q1--7
7$677FFM	
 	
 	
 	
 	
r$   c                     t          dddd          }t          |t                    } |t                    }|                     |j        d                    t                               dS )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.
        ry   rz   r   r  z
Do nothing.

This is used to test the deprecation decorators.

Deprecated in Twisted 8.0.0; please use {}.dummyReplacementMethod instead.
N)r   r   r   r   rJ   r+   r   r(   )r!   r]   	decoratorr   s       r"   &test_deprecatedReplacementWithCallablez?DeprecatedDecoratorTests.test_deprecatedReplacementWithCallablev  st     )Q1--w4JKKK		-((M3 4:6(3C3C	
 	
 	
 	
 	
r$   c                    d}t          d          5 }t          d           t          dd           |                     |g            t          ddd           |                     |g            t          ddd	           |                     t	          |          d
           |                     |d         j        t                     |                     t          |d         j                  |           |	                                 t          ddd           |                     |g            t          dddd           |                     t	          |          d
           |                     |d         j        t                     |                     t          |d         j                  |           d d d            d S # 1 swxY w Y   d S )NzzThe 'foo' parameter to twisted.python.test.test_deprecate.functionWithDeprecatedParameter was deprecated in Twisted 19.2.0Tr   r   
         (   )r0   rP   r   2   )r*  )
r   r   r+  rJ   rn   ri   rm   r   r^   r   )r!   r^   wss      r"   test_deprecatedKeywordParameterz8DeprecatedDecoratorTests.test_deprecatedKeywordParameter  s   / 	 4((( 	:B"""+B333R$$$+BB777R$$$+B;;;;SWWa(((RU^-?@@@SA//999HHJJJ+B;;;;R$$$+BB;;;SWWa(((RU^-?@@@SA//999+	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   F+GGGN)r(   r)   r*   r+   r6  r:  r=  r@  rB  rE  rM  r,   r$   r"   r-  r-     s         
 
 
: : :@: : :(: : :6
 
 
&
 
 
&: : : : :r$   r-  c                   $    e Zd ZdZd Zd Zd ZdS )AppendToDocstringTestszk
    Test the _appendToDocstring function.

    _appendToDocstring is used to add text to a docstring.
    c                 b    d }t          |d           |                     d|j                   dS )zP
        Appending to an empty docstring simply replaces the docstring.
        c                      d S r   r,   r,   r$   r"   noDocstringzGAppendToDocstringTests.test_appendToEmptyDocstring.<locals>.noDocstring  r   r$   Appended text.Nr
   rJ   r+   )r!   rR  s     r"   test_appendToEmptyDocstringz2AppendToDocstringTests.test_appendToEmptyDocstring  sD    
	 	 	 	;(8999);+>?????r$   c                     d }t          |d           |                     g d|j                                                   |                     |j                            d                     dS )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                      dS );This doesn't comply with standards, but is here for a test.Nr,   r,   r$   r"   singleLineDocstringzTAppendToDocstringTests.test_appendToSingleLineDocstring.<locals>.singleLineDocstring  r   r$   rS  )rX  r  rS  
N)r
   rJ   r+   r3  r   r   )r!   rY  s     r"    test_appendToSingleLineDocstringz7AppendToDocstringTests.test_appendToSingleLineDocstring  s    	N 	N 	N 	.0@AAA  
  '2244	
 	
 	
 	+3<<TBBCCCCCr$   c                 b    d }t          |d           |                     d|j                   dS )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                      dS )z9
            This is a multi-line docstring.
            Nr,   r,   r$   r"   multiLineDocstringzRAppendToDocstringTests.test_appendToMultilineDocstring.<locals>.multiLineDocstring  r   r$   rS  z1
This is a multi-line docstring.

Appended text.
NrT  )r!   r^  s     r"   test_appendToMultilineDocstringz6AppendToDocstringTests.test_appendToMultilineDocstring  sP    	 	 	
 	-/?@@@L&	
 	
 	
 	
 	
r$   N)r(   r)   r*   r+   rU  r[  r_  r,   r$   r"   rO  rO    sQ         	@ 	@ 	@D D D2
 
 
 
 
r$   rO  c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )MutualArgumentExclusionTestsz2
    Tests for L{mutuallyExclusiveArguments}.
    c                     t          t          dd          r#t          t          j        |          ||          S t	          t          j        |          ||          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   inspectr   rc  r   
getargspecr!   funcargskws       r"   checkPassedz(MutualArgumentExclusionTests.checkPassed  sU     7K.. 	F#G$5d$;$;T2FFF "'"4T":":D"EEEr$   c                     d }|                      |                     |dd          t          dd                     dS )z`
        L{passed} identifies the arguments passed by a simple
        positional test.
        c                     d S r   r,   r'  r(  s     r"   rg  zGMutualArgumentExclusionTests.test_passed_simplePositional.<locals>.func
  r   r$   rP   rx   rm  NrJ   rj  r   r!   rg  s     r"   test_passed_simplePositionalz9MutualArgumentExclusionTests.test_passed_simplePositional  sK    	 	 	 	))$155ta1~~~FFFFFr$   c                 T    d }|                      t          | j        |ddd           dS )z[
        L{passed} raises a L{TypeError} if too many arguments are
        passed.
        c                     d S r   r,   rm  s     r"   rg  zBMutualArgumentExclusionTests.test_passed_tooManyArgs.<locals>.func  r   r$   rP   rx   r  Nr?   	TypeErrorrj  ro  s     r"   test_passed_tooManyArgsz4MutualArgumentExclusionTests.test_passed_tooManyArgs  s:    	 	 	 	)T%5tQ1EEEEEr$   c                 T    d }|                      t          | j        |dd           dS )zs
        L{passed} raises a L{TypeError} if a argument is passed both
        positionally and by keyword.
        c                     d S r   r,   r'  s    r"   rg  zHMutualArgumentExclusionTests.test_passed_doublePassKeyword.<locals>.func   r   r$   rP   rx   rx  Nrs  ro  s     r"   test_passed_doublePassKeywordz:MutualArgumentExclusionTests.test_passed_doublePassKeyword  ;    	 	 	 	)T%5tQ!DDDDDr$   c                 T    d }|                      t          | j        |dd           dS )z
        L{passed} raises a L{TypeError} if a keyword argument not
        present in the function's declaration is passed.
        c                     d S r   r,   rx  s    r"   rg  zIMutualArgumentExclusionTests.test_passed_unspecifiedKeyword.<locals>.func+  r   r$   rP   rx   )zNrs  ro  s     r"   test_passed_unspecifiedKeywordz;MutualArgumentExclusionTests.test_passed_unspecifiedKeyword%  rz  r$   c                     d }|                      |                     |ddd          t          dd                     dS )z|
        L{passed} places additional positional arguments into a tuple
        under the name of the star argument.
        c                     d S r   r,   rm  s     r"   rg  z;MutualArgumentExclusionTests.test_passed_star.<locals>.func6  r   r$   rP   rx   r  )rx   r  rm  Nrn  ro  s     r"   test_passed_starz-MutualArgumentExclusionTests.test_passed_star0  sP    	 	 	 	))$1a88$f:M:M:MNNNNNr$   c                     d }|                      |                     |dddd          t          dt          ddd                               dS )	zn
        Additional keyword arguments are passed as a dict to the star star
        keyword argument.
        c                     d S r   r,   rm  s     r"   rg  z?MutualArgumentExclusionTests.test_passed_starStar.<locals>.funcA  r   r$   rP   rx   r     )r   yr}  rm  Nrn  ro  s     r"   test_passed_starStarz1MutualArgumentExclusionTests.test_passed_starStar;  sp    	 	 	 	T1Q!44dQ$aSTBUBUBU6V6V6V	
 	
 	
 	
 	
r$   c                     d	d}|                      |                     |ddd          t          ddd                     dS )
zp
        The results of L{passed} only include arguments explicitly
        passed, not default values.
        rP   rx   r  c                     d S r   r,   r'  r(  r)  des        r"   rg  zFMutualArgumentExclusionTests.test_passed_noDefaultValues.<locals>.funcN  r   r$      )r  )r'  r(  r  NrP   rx   r  rn  ro  s     r"   test_passed_noDefaultValuesz8MutualArgumentExclusionTests.test_passed_noDefaultValuesH  sZ    	 	 	 	 	))$1)::D1Q<O<O<OPPPPPr$   c                     t          dg          dd            }|                      |dd          d           |                      |ddd          d	           |                      |ddd
          d           dS )z
        L{mutuallyExclusiveArguments} does not interfere in its
        decoratee's operation, either its receipt of arguments or its return
        value.
        rm  r  r  c                     | |z   |z   |z   S r   r,   )r   r  r'  r(  s       r"   rg  zMMutualArgumentExclusionTests.test_mutualExclusionPrimeDirective.<locals>.funcZ  s    q519q= r$   rP   rx   rG  r     r(     Nr  r  )r   rJ   ro  s     r"   "test_mutualExclusionPrimeDirectivez?MutualArgumentExclusionTests.test_mutualExclusionPrimeDirectiveS  s     
%j\	2	2	! 	! 	! 
3	2	! 	aR(((aA+++aa"-----r$   c                 z    t          ddgg          dd            }|                     t          |dd           dS )	z
        L{mutuallyExclusiveArguments} raises a L{TypeError}n if its
        decoratee is passed a pair of mutually exclusive arguments.
        r'  r(  r  r  c                     | |z   S r   r,   rm  s     r"   rg  zPMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeyword.<locals>.funch  s    q5Lr$   rm  Nr  )r   r?   rt  ro  s     r"   %test_mutualExclusionExcludesByKeywordzBMutualArgumentExclusionTests.test_mutualExclusionExcludesByKeywordb  sV     
%sCj\	2	2	 	 	 
3	2	 	)TQ!44444r$   c                 ,    G d d          } G d d          }d } |dd           t          j        |          j        }|                                } |dd          |d	<    ||          }|                     t
          t          |d
i            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                       e Zd Zd ZdS )MMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignaturec                     || _         d S r   )
parameters)r!   r  s     r"   r#   zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeSignature.__init__v  s    ",r$   Nr(   r)   r*   r#   r,   r$   r"   FakeSignaturer  u  s#        - - - - -r$   r  c                       e Zd Zd ZdS )MMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameterc                 "    || _         || _        d S r   )ro   kind)r!   ro   r  s      r"   r#   zVMutualArgumentExclusionTests.test_invalidParameterType.<locals>.FakeParameter.__init__z  s     	 			r$   Nr  r,   r$   r"   FakeParameterr  y  s#        ! ! ! ! !r$   r  c                     d S r   r,   rm  s     r"   rg  zDMutualArgumentExclusionTests.test_invalidParameterType.<locals>.func~  r   r$   rP   rx   faker)  rP   rx   N)rd  rc  r  r   r?   rt  r   )r!   r  r  rg  r  dummyParametersfakeSigs          r"   test_invalidParameterTypez6MutualArgumentExclusionTests.test_invalidParameterTypen  s    	- 	- 	- 	- 	- 	- 	- 	-	! 	! 	! 	! 	! 	! 	! 	!
	 	 	 	Q


&t,,7
$//++,}VV<<-00)%5wKKKKKr$   N)r(   r)   r*   r+   rj  rp  ru  ry  r~  r  r  r  r  r  r  r,   r$   r"   ra  ra    s         F F F,	G 	G 	G	F 	F 	F	E 	E 	E	E 	E 	E	O 	O 	O
 
 
	Q 	Q 	Q. . .
5 
5 
5L L L L Lr$   ra  c                       e Zd ZdZd Zd ZdS )KeywordOnlyTestsz,
    Keyword only arguments (PEP 3102).
    c                 H    t          t          j        |          ||          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}
        )r   rd  rc  rf  s       r"   rj  zKeywordOnlyTests.checkPassed  s!       1$ 7 7rBBBr$   c                    ddd}ddd}|                      |                     |ddd          t          dd	                     |                      |                     |dddd
          t          dd
	                     |                      |                     |ddd
ddd          t          dd
ddd                     |                     t          | j        |ddd
dd           dS )z`
        Keyword only arguments follow varargs.
        They are specified in PEP 3102.
        Tr  c                     dS )zM
            b is a keyword-only argument, with a default value.
            Nr,   )r(  r'  s     r"   func1z6KeywordOnlyTests.test_passedKeywordOnly.<locals>.func1  r   r$   c                     dS )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$   rP   rx   r  r  rm  F)r(  r)  r  r  r  r  )r(  r)  r  N)rJ   rj  r   r?   rt  )r!   r  r  s      r"   test_passedKeywordOnlyz'KeywordOnlyTests.test_passedKeywordOnly  s;     	 	 	 	 	
  	 	 	 	 	 	))%Aq994)t;T;T;TUUUUAq!u55ti57Q7Q7Q	
 	
 	
 	UAqEQ!qAA6Ua1222	
 	
 	
 	)T%5uaeqTUVVVVVr$   N)r(   r)   r*   r+   rj  r  r,   r$   r"   r  r    sD         C C C"W W W W Wr$   r  r  )7r+   rd  r{   r1   r   os.pathr   r   r   	importlibr   ImportErrorincrementalr   twisted.pythonr   twisted.python.deprecater	   r
   r   r  r   r   r   r   r   r   r   r   r   twisted.python.filepathr   twisted.python.runtimer   twisted.python.testr   #twisted.python.test.modules_helpersr   twisted.trial.unittestr   r   r.   r[   r   r   r   r   r   r  r  r+  r-  rO  ra  r  r,   r$   r"   <module>r     s   
  



         1 1 1 1 1 1 1 1+++++++           $ $ $ $ $ $                            - , , , , , + + + + + + 4 4 4 4 4 4 C C C C C C 6 6 6 6 6 6       "DY DY DY DY DY* DY DY DYN_@ _@ _@ _@ _@2 _@ _@ _@Dl% l% l% l% l%#68K l% l% l%^c
 c
 c
 c
 c
0 c
 c
 c
L    G
 G
 G
 G
 G
2 G
 G
 G
T GGIq!Q''((       )() ) ) ) ) ) ) )0 GGIr1a88%@@   A@f: f: f: f: f:2 f: f: f:R=
 =
 =
 =
 =
0 =
 =
 =
@]L ]L ]L ]L ]L#6 ]L ]L ]L@/W /W /W /W /W* /W /W /W /W /Ws   ) 33