Ë
    oj”_  ã                   óú  — d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ  G d„ d«      Z G d	„ d
e«      Z G d„ d«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ d«      Z G d„ de«      Z G d„ d«      Z G d„ dee«      Z edefdddœ«      Z G d „ d!e«      Z G d"„ d#e«      Z G d$„ d%e«      Z G d&„ d'e«      Z  G d(„ d)e«      Z! G d*„ d+e«      Z" G d,„ d-e«      Z#y).z6
Test cases for the L{twisted.python.reflect} module.
é    N)Údeque)Úreflect)ÚaccumulateMethodsÚaddMethodNamesToDictÚfullyQualifiedNameÚprefixedMethodNamesÚprefixedMethods)ÚSynchronousTestCasec                   ó   — e Zd ZdZd„ Zy)ÚBasez`
    A no-op class which can be used to verify the behavior of
    method-discovering APIs.
    c                  ó   — y)z9
        A no-op method which can be discovered.
        N© ©Úselfs    ú;/usr/lib/python3/dist-packages/twisted/test/test_reflect.pyÚmethodzBase.method   ó   � ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   „ ñó
r   r   c                   ó   — e Zd ZdZy)ÚSubzF
    A subclass of a class with a method which can be discovered.
    N)r   r   r   r   r   r   r   r   r   $   s   „ òr   r   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚSeparatez=
    A no-op class with methods with differing prefixes.
    c                  ó   — y)zJ
        A no-op method which a matching prefix to be discovered.
        Nr   r   s    r   Úgood_methodzSeparate.good_method/   r   r   c                  ó   — y)zO
        A no-op method with a mismatched prefix to not be discovered.
        Nr   r   s    r   Ú
bad_methodzSeparate.bad_method4   r   r   N)r   r   r   r   r   r    r   r   r   r   r   *   s   „ ñòó
r   r   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚAccumulateMethodsTestszt
    Tests for L{accumulateMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 óp   — t        «       }i }t        ||«       | j                  d|j                  i|«       y)zí
        If x is and instance of Base and Base defines a method named method,
        L{accumulateMethods} adds an item to the given dictionary with
        C{"method"} as the key and a bound method object for Base.method value.
        r   N)r   r   ÚassertEqualr   ©r   ÚxÚoutputs      r   Útest_ownClassz$AccumulateMethodsTests.test_ownClass@   s3   € ô ‹FˆØˆÜ˜!˜VÔ$Ø×Ñ˜( A§H¡HÐ-¨vÕ6r   c                 óp   — t        «       }i }t        ||«       | j                  d|j                  i|«       y)a  
        If x is an instance of Sub and Sub is a subclass of Base and Base
        defines a method named method, L{accumulateMethods} adds an item to the
        given dictionary with C{"method"} as the key and a bound method object
        for Base.method as the value.
        r   N)r   r   r$   r   r%   s      r   Útest_baseClassz%AccumulateMethodsTests.test_baseClassK   s3   € ô ‹EˆØˆÜ˜!˜VÔ$Ø×Ñ˜( A§H¡HÐ-¨vÕ6r   c                 ór   — t        «       }i }t        ||d«       | j                  d|j                  i|«       y)zÐ
        If a prefix is given, L{accumulateMethods} limits its results to
        methods beginning with that prefix.  Keys in the resulting dictionary
        also have the prefix removed from them.
        Úgood_r   N)r   r   r$   r   r%   s      r   Útest_prefixz"AccumulateMethodsTests.test_prefixW   s5   € ô ‹JˆØˆÜ˜!˜V WÔ-Ø×Ñ˜( A§M¡MÐ2°FÕ;r   N)r   r   r   r   r(   r*   r-   r   r   r   r"   r"   :   s   „ ñò
	7ò
7ó	<r   r"   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚPrefixedMethodsTestszr
    Tests for L{prefixedMethods} which finds methods on a class hierarchy and
    adds them to a dictionary.
    c                 óh   — t        «       }t        |«      }| j                  |j                  g|«       y)zc
        L{prefixedMethods} returns a list of the methods discovered on an
        object.
        N)r   r	   r$   r   r%   s      r   Útest_onlyObjectz$PrefixedMethodsTests.test_onlyObjecti   s+   € ô
 ‹FˆÜ  Ó#ˆØ×Ñ˜!Ÿ(™(˜ VÕ,r   c                 ój   — t        «       }t        |d«      }| j                  |j                  g|«       y)zo
        If a prefix is given, L{prefixedMethods} returns only methods named
        with that prefix.
        r,   N)r   r	   r$   r   r%   s      r   r-   z PrefixedMethodsTests.test_prefixr   s-   € ô
 ‹JˆÜ   GÓ,ˆØ×Ñ˜!Ÿ-™-˜¨&Õ1r   N)r   r   r   r   r1   r-   r   r   r   r/   r/   c   s   „ ñò
-ó2r   r/   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚPrefixedMethodNamesTestsz+
    Tests for L{prefixedMethodNames}.
    c                 óF   — | j                  dgt        t        d«      «       y)zŠ
        L{prefixedMethodNames} returns a list including methods with the given
        prefix defined on the class passed to it.
        r   r,   N)r$   r   r   r   s    r   Útest_methodz$PrefixedMethodNamesTests.test_method�   s   € ð
 	×Ñ˜(˜Ô%8¼À7Ó%KÕLr   c                 ó\   —  G d„ dt         «      }| j                  dgt        |d«      «       y)z™
        L{prefixedMethodNames} returns a list included methods with the given
        prefix defined on base classes of the class passed to it.
        c                   ó   — e Zd Zy)ú<PrefixedMethodNamesTests.test_inheritedMethod.<locals>.ChildN©r   r   r   r   r   r   ÚChildr9   Ž   ó   „ Ør   r;   r   r,   N)r   r$   r   )r   r;   s     r   Útest_inheritedMethodz-PrefixedMethodNamesTests.test_inheritedMethodˆ   s*   € ô	”Hô 	ð 	×Ñ˜(˜Ô%8¸ÀÓ%HÕIr   N)r   r   r   r   r6   r=   r   r   r   r4   r4   |   s   „ ñòMó	Jr   r4   c                   ó   — e Zd ZdZd„ Zy)ÚAddMethodNamesToDictTestsz,
    Tests for L{addMethodNamesToDict}.
    c                 ó€   —  G d„ d«      } G d„ dt         |«      }i }t        ||d|«       | j                  ddi|«       y)	z¥
        If C{baseClass} is passed to L{addMethodNamesToDict}, only methods which
        are a subclass of C{baseClass} are added to the result dictionary.
        c                   ó   — e Zd Zy)ú;AddMethodNamesToDictTests.test_baseClass.<locals>.AlternateNr:   r   r   r   Ú	AlternaterB   Ÿ   r<   r   rC   c                   ó   — e Zd Zd„ Zy)ú7AddMethodNamesToDictTests.test_baseClass.<locals>.Childc                  ó   — y ©Nr   r   s    r   Úgood_alternatezFAddMethodNamesToDictTests.test_baseClass.<locals>.Child.good_alternate£   ó   € Ør   N)r   r   r   rH   r   r   r   r;   rE   ¢   ó   „ ór   r;   r,   Ú	alternateé   N)r   r   r$   )r   rC   r;   Úresults       r   r*   z(AddMethodNamesToDictTests.test_baseClass™   sD   € ÷	ñ 	ô	”H˜iô 	ð ˆÜ˜U F¨G°YÔ?Ø×Ñ˜+ qÐ)¨6Õ2r   N)r   r   r   r   r*   r   r   r   r?   r?   ”   s   „ ñó3r   r?   c                   ó   — e Zd ZdZd„ Zy)ÚSummerz9
    A class we look up as part of the LookupsTests.
    c                  ó   — y)z
        Do something.
        Nr   r   s    r   Ú	reallySetzSummer.reallySet°   r   r   N)r   r   r   r   rQ   r   r   r   rO   rO   «   s   „ ñór   rO   c                   ó^   — 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„ Zd„ Zy)ÚLookupsTestszC
    Tests for L{namedClass}, L{namedModule}, and L{namedAny}.
    c                 óV   — | j                  t        j                  d«      t        «       y)zY
        L{namedClass} should return the class object for the name it is passed.
        ú twisted.test.test_reflect.SummerN)ÚassertIsr   Ú
namedClassrO   r   s    r   Útest_namedClassLookupz"LookupsTests.test_namedClassLookup»   s   € ð 	�‰”g×(Ñ(Ð)KÓLÌfÕUr   c                 óZ   — ddl m} | j                  t        j                  d«      |«       y)zc
        L{namedModule} should return the module object for the name it is
        passed.
        r   ©Úmonkeyútwisted.python.monkeyN)Útwisted.pythonr[   rV   r   ÚnamedModule©r   r[   s     r   Útest_namedModuleLookupz#LookupsTests.test_namedModuleLookupÁ   s!   € õ
 	*à�‰”g×)Ñ)Ð*AÓBÀFÕKr   c                 ój   — ddl }| j                  t        j                  d«      |j                  «       y)zY
        L{namedAny} should return the package object for the name it is passed.
        r   Nútwisted.python)r]   rV   r   ÚnamedAnyÚpython©r   Útwisteds     r   Útest_namedAnyPackageLookupz'LookupsTests.test_namedAnyPackageLookupÊ   s%   € ó 	à�‰”g×&Ñ&Ð'7Ó8¸'¿.¹.ÕIr   c                 óZ   — ddl m} | j                  t        j                  d«      |«       y)zX
        L{namedAny} should return the module object for the name it is passed.
        r   rZ   r\   N)r]   r[   rV   r   rc   r_   s     r   Útest_namedAnyModuleLookupz&LookupsTests.test_namedAnyModuleLookupÒ   s!   € õ 	*à�‰”g×&Ñ&Ð'>Ó?ÀÕHr   c                 óV   — | j                  t        j                  d«      t        «       y)zW
        L{namedAny} should return the class object for the name it is passed.
        rU   N)rV   r   rc   rO   r   s    r   Útest_namedAnyClassLookupz%LookupsTests.test_namedAnyClassLookupÚ   s   € ð 	�‰”g×&Ñ&Ð'IÓJÌFÕSr   c                 ój   — | j                  t        j                  d«      t        j                  «       y)z–
        L{namedAny} should return the object an attribute of a non-module,
        non-package object is bound to for the name it is passed.
        z*twisted.test.test_reflect.Summer.reallySetN)r$   r   rc   rO   rQ   r   s    r   Útest_namedAnyAttributeLookupz)LookupsTests.test_namedAnyAttributeLookupà   s*   € ð 	×ÑÜ×ÑÐIÓJÜ×Ñõ	
r   c                 ó~   — | j                  t        j                  d«      t        j                  j
                  «       y)zÉ
        L{namedAny} should return the object an attribute of an object which
        itself was an attribute of a non-module, non-package object is bound to
        for the name it is passed.
        z2twisted.test.test_reflect.Summer.reallySet.__doc__N)rV   r   rc   rO   rQ   r   r   s    r   Ú"test_namedAnySecondAttributeLookupz/LookupsTests.test_namedAnySecondAttributeLookupí   s.   € ð 	�‰Ü×ÑÐTÓUÜ×Ñ×$Ñ$õ	
r   c                 ó,  — | j                  t        t        j                  d«       | j                  t        t        j                  d«       | j                  t        t        j                  d«       | j                  t
        t        j                  d«       y)z�
        Exceptions raised by modules which L{namedAny} causes to be imported
        should pass through L{namedAny} to the caller.
        ztwisted.test.reflect_helper_ZDEztwisted.test.reflect_helper_VEztwisted.test.reflect_helper_IEN)ÚassertRaisesÚZeroDivisionErrorr   rc   Ú
ValueErrorÚImportErrorr   s    r   Útest_importExceptionsz"LookupsTests.test_importExceptionsø   sz   € ð
 	×ÑÜœw×/Ñ/Ð1Rô	
ð 	×ÑÜœw×/Ñ/Ð1Rô	
ð 	×ÑÜœ×(Ñ(Ð*Jô	
ð
 	×ÑÜœ×)Ñ)Ð+Kõ	
r   c                 óâ   — | j                  t        t        j                  d«       | j                  t        t        j                  d«       | j                  t        t        j                  d«       y)zï
        If segments on the end of a fully-qualified Python name represents
        attributes which aren't actually present on the object represented by
        the earlier segments, L{namedAny} should raise an L{AttributeError}.
        ztwisted.nosuchmoduleintheworldz twisted.nosuch.modulein.theworldz0twisted.test.test_reflect.Summer.nosuchattributeN)rq   ÚAttributeErrorr   rc   r   s    r   Útest_attributeExceptionsz%LookupsTests.test_attributeExceptions  s]   € ð 	×ÑÜœG×,Ñ,Ð.Nô	
ð 	×ÑÜœG×,Ñ,Ð.Pô	
ð 	×ÑÜÜ×ÑØ>õ	
r   c                 óü  — | j                  t        j                  t        j                  d«      }| j	                  t        |«      d«       | j                  t        j                  t        j                  d«      }| j	                  t        |«      d«       | j                  t        j                  t        j                  d«      }| j	                  t        |«      d«       | j                  t        j                  t        j                  d«      }| j	                  t        |«      d«       d	D ]O  }| j                  t        j                  t        j                  |«      }| j	                  t        |«      d
|›�«       ŒQ y)a•  
        Passing a name which isn't a fully-qualified Python name to L{namedAny}
        should result in one of the following exceptions:
         - L{InvalidName}: the name is not a dot-separated list of Python
           objects
         - L{ObjectNotFound}: the object doesn't exist
         - L{ModuleNotFound}: the object doesn't exist and there is only one
           component in the name
        Únosuchmoduleintheworldz(No module named 'nosuchmoduleintheworld'z@#$@(#.!@(#!@#z('@#$@(#.!@(#!@#' does not name an objectztcelfer.nohtyp.detsiwtz0'tcelfer.nohtyp.detsiwt' does not name an objectÚ zEmpty module name)z.twistedztwisted.ztwisted..pythonzMname must be a string giving a '.'-separated list of Python identifiers, not N)rq   r   ÚModuleNotFoundrc   r$   ÚstrÚObjectNotFoundÚInvalidName)r   ÚerrÚinvalidNames      r   Útest_invalidNameszLookupsTests.test_invalidNames"  s8  € ð ×ÑÜ×"Ñ"¤G×$4Ñ$4Ð6Nó
ˆð 	×Ñœ˜S›Ð#MÔNð ×ÑÜ×"Ñ"¤G×$4Ñ$4Ð6Fó
ˆð 	×Ñœ˜S›Ð#MÔNà×ÑÜ×"Ñ"¤G×$4Ñ$4Ð6Nó
ˆð 	×Ñœ˜S›Ð#UÔVà×Ñ¤× 3Ñ 3´W×5EÑ5EÀrÓJˆØ×Ñœ˜S›Ð#6Ô7àFò 	ˆKØ×#Ñ#¤G×$7Ñ$7¼×9IÑ9IÈ;ÓWˆCØ×ÑÜ�C”á)4ð7õñ	r   c                 óx   — dD ]5  }t        «       }t        j                  ||¬«      }| j                  ||«       Œ7 y)zk
        When module import fails with ImportError it returns the specified
        default value.
        )Únosuchmtopoduleúno.such.module©ÚdefaultN)Úobjectr   ÚrequireModulerV   )r   Únamer‡   rM   s       r   Útest_requireModuleImportErrorz*LookupsTests.test_requireModuleImportErrorG  s:   € ð
 :ò 	+ˆDÜ“hˆGä×*Ñ*¨4¸ÔAˆFà�M‰M˜& 'Õ*ñ	+r   c                 óP   — t        j                  d«      }| j                  |«       y)zI
        When module import fails it returns L{None} by default.
        r…   N)r   r‰   ÚassertIsNone)r   rM   s     r   Útest_requireModuleDefaultNonez*LookupsTests.test_requireModuleDefaultNoneS  s#   € ô ×&Ñ&Ð'7Ó8ˆà×Ñ˜&Õ!r   c                 ór   — ddl m} t        «       }| j                  t	        j
                  d|¬«      |«       y)ze
        When module import succeed it returns the module and not the default
        value.
        r   rZ   r\   r†   N)r]   r[   rˆ   rV   r   r‰   )r   r[   r‡   s      r   Ú!test_requireModuleRequestedImportz.LookupsTests.test_requireModuleRequestedImport[  s.   € õ
 	*ä“(ˆà�‰Ü×!Ñ!Ð"9À7ÔKØõ	
r   N)r   r   r   r   rX   r`   rg   ri   rk   rm   ro   ru   rx   r‚   r‹   rŽ   r�   r   r   r   rS   rS   ¶   sN   „ ñòVòLòJòIòTò
ò	
ò
ò*
ò*#òJ
+ò"ó
r   rS   c                   ó,   — e Zd ZdZdZdefd„Zdefd„Zy)Ú	BreakableFÚreturnc                 ó2   — | j                   rt        d«      ‚y)Nzstr!z<Breakable>)ÚbreakStrÚRuntimeErrorr   s    r   Ú__str__zBreakable.__str__n  s   € Ø�=Š=Ü˜vÓ&Ð&à r   c                 ó2   — | j                   rt        d«      ‚y)Nzrepr!zBreakable())Ú	breakReprr–   r   s    r   Ú__repr__zBreakable.__repr__t  s   € Ø�>Š>Ü˜wÓ'Ð'à r   N)r   r   r   r™   r•   r}   r—   rš   r   r   r   r’   r’   j  s$   „ Ø€IØ€Hð!˜ó !ð!˜#ô !r   r’   c                   ó    — e Zd ZdZed„ «       Z y)Ú
BrokenTypeFc                 ó2   — | j                   rt        d«      ‚y)Nzno namerœ   )Ú	breakNamer–   r   s    r   r   zBrokenType.__name__~  s   € à�>Š>Ü˜yÓ)Ð)Ør   N)r   r   r   rž   Úpropertyr   r   r   rœ   rœ   {  s   „ Ø€Iàñó ñr   rœ   ÚBTBaseT)r™   r•   c                   ó   — e Zd Z ed„ «      Zy)ÚNoClassAttrc                 ó   — | j                   S rG   )Ú	not_class)r&   s    r   ú<lambda>zNoClassAttr.<lambda>‰  s
   €  1§;¡;€ r   N)r   r   r   rŸ   Ú	__class__r   r   r   r¢   r¢   ˆ  s   „ ÙÑ.Ó/�Ir   r¢   c                   ó@   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zy
)ÚSafeReprTestsz2
    Tests for L{reflect.safe_repr} function.
    c           	      ó¤   — g d¢df}| j                  t        t        t        j                  |«      «      t        t        t
        |«      «      «       y)zg
        L{reflect.safe_repr} produces the same output as C{repr} on a working
        object.
        ©rL   é   é   ó   aN)r$   ÚlistÚmapr   Ú	safe_reprÚrepr)r   Úxss     r   Útest_workingReprzSafeReprTests.test_workingRepr‘  s;   € ò
 ˜ÐˆØ×Ñœœc¤'×"3Ñ"3°RÓ8Ó9¼4ÄÄDÈ"ÃÓ;NÕOr   c                 ó  — t        «       }d|_        t        j                  |«      }| j	                  d|«       | j	                  t
        j                  j                  t        «      d   |«       | j	                  d|«       y)z‚
        L{reflect.safe_repr} returns a string with class name, address, and
        traceback when the repr call failed.
        TzBreakable instance at 0xr   úRuntimeError: repr!N)	r’   r™   r   r°   ÚassertInÚosÚpathÚsplitextÚ__file__©r   ÚbÚbReprs      r   Útest_brokenReprzSafeReprTests.test_brokenRepr™  sd   € ô
 ‹KˆØˆŒÜ×!Ñ! !Ó$ˆØ�‰Ð0°%Ô8ð 	�‰”b—g‘g×&Ñ&¤xÓ0°Ñ3°UÔ;Ø�‰Ð+¨UÕ3r   c                 ó‚   — t        «       }d|_        | j                  t        j                  |«      t        |«      «       y)zT
        L{reflect.safe_repr} isn't affected by a broken C{__str__} method.
        TN)r’   r•   r$   r   r°   r±   ©r   r¼   s     r   Útest_brokenStrzSafeReprTests.test_brokenStr§  s1   € ô ‹KˆØˆŒ
Ø×Ñœ×*Ñ*¨1Ó-¬t°A«wÕ7r   c                 ó€   —  G d„ dt         «      }t        j                  |«       t        j                   |«       «       y )Nc                   ó   — e Zd ZdZy)ú-SafeReprTests.test_brokenClassRepr.<locals>.XTN©r   r   r   r™   r   r   r   ÚXrÄ   °  ó   „ Ø‰Ir   rÆ   ©r    r   r°   ©r   rÆ   s     r   Útest_brokenClassReprz"SafeReprTests.test_brokenClassRepr¯  s.   € ô	”ô 	ô 	×Ñ˜!ÔÜ×Ñ™!›#Õr   c                 ó´   —  G d„ dt         «      }t        j                  |«      }dt        |«      d›d�}| j	                  ||j                  d«      d   «       y)	zË
        C{id} is used to print the ID of the object in case of an error.

        L{safe_repr} includes a traceback after a newline, so we only check
        against the first line of the repr.
        c                   ó   — e Zd ZdZy)ú2SafeReprTests.test_brokenReprIncludesID.<locals>.XTNrÅ   r   r   r   rÆ   rÍ   ¾  rÇ   r   rÆ   z<BrokenType instance at 0xr&   z with repr error:ú
r   N)r    r   r°   Úidr$   Úsplit)r   rÆ   ÚxReprÚxReprExpecteds       r   Útest_brokenReprIncludesIDz'SafeReprTests.test_brokenReprIncludesID¶  sS   € ô	”ô 	ô ×!Ñ! !Ó$ˆØ4´R¸³U¸1°IÐ=NÐOˆØ×Ñ˜¨¯©°DÓ(9¸!Ñ(<Õ=r   c                 ó€   —  G d„ dt         «      }t        j                  |«       t        j                   |«       «       y )Nc                   ó   — e Zd ZdZy)ú,SafeReprTests.test_brokenClassStr.<locals>.XTN©r   r   r   r•   r   r   r   rÆ   rÖ   Æ  ó   „ Ø‰Hr   rÆ   rÈ   rÉ   s     r   Útest_brokenClassStrz!SafeReprTests.test_brokenClassStrÅ  s.   € ô	”ô 	ô 	×Ñ˜!ÔÜ×Ñ™!›#Õr   c                 ó  — t        «       }d|_        t        j                  |«      }| j	                  d|«       | j	                  t
        j                  j                  t        «      d   |«       | j	                  d|«       y)z­
        If an object raises an exception when accessing its C{__class__}
        attribute, L{reflect.safe_repr} uses C{type} to retrieve the class
        object.
        TúNoClassAttr instance at 0xr   rµ   N)	r¢   r™   r   r°   r¶   r·   r¸   r¹   rº   r»   s      r   Útest_brokenClassAttributez'SafeReprTests.test_brokenClassAttributeÌ  sb   € ô ‹MˆØˆŒÜ×!Ñ! !Ó$ˆØ�‰Ð2°EÔ:Ø�‰”b—g‘g×&Ñ&¤xÓ0°Ñ3°UÔ;Ø�‰Ð+¨UÕ3r   c                 ó
  —  G d„ dt         «      }t        j                   |«       «      }| j                  d|«       | j                  t        j
                  j                  t        «      d   |«       | j                  d|«       y)zã
        If a class raises an exception when accessing its C{__name__} attribute
        B{and} when calling its C{__str__} implementation, L{reflect.safe_repr}
        returns 'BROKEN CLASS' instead of the class name.
        c                   ó   — e Zd ZdZy)ú6SafeReprTests.test_brokenClassNameAttribute.<locals>.XTN©r   r   r   rž   r   r   r   rÆ   rß   à  rÇ   r   rÆ   ú<BROKEN CLASS AT 0xr   rµ   N)r    r   r°   r¶   r·   r¸   r¹   rº   )r   rÆ   rÑ   s      r   Útest_brokenClassNameAttributez+SafeReprTests.test_brokenClassNameAttributeÙ  sb   € ô	”ô 	ô ×!Ñ!¡!£#Ó&ˆØ�‰Ð+¨UÔ3Ø�‰”b—g‘g×&Ñ&¤xÓ0°Ñ3°UÔ;Ø�‰Ð+¨UÕ3r   N)r   r   r   r   r³   r¾   rÁ   rÊ   rÓ   rÙ   rÜ   râ   r   r   r   r¨   r¨   Œ  s0   „ ñòPò4ò8òò>òò4ó4r   r¨   c                   óL   — 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y)ÚSafeStrTestsz1
    Tests for L{reflect.safe_str} function.
    c                 óh   — g d¢}| j                  t        j                  |«      t        |«      «       y )Nrª   )r$   r   Úsafe_strr}   ©r   r&   s     r   Útest_workingStrzSafeStrTests.test_workingStrî  s&   € ÚˆØ×Ñœ×)Ñ)¨!Ó,¬c°!«fÕ5r   c                 óP   — t        «       }d|_        t        j                  |«       y ©NT)r’   r•   r   ræ   rÀ   s     r   rÁ   zSafeStrTests.test_brokenStrò  s   € Ü‹KˆØˆŒ
Ü×Ñ˜Õr   c                 óR   — d}| j                  t        j                  |«      d«       y)zh
        L{safe_str} for C{str} with ascii-only data should return the
        value unchanged.
        ÚaN)r$   r   ræ   rç   s     r   Útest_workingAsciizSafeStrTests.test_workingAscii÷  s$   € ð
 ˆØ×Ñœ×)Ñ)¨!Ó,¨cÕ2r   c                 óp   — d}| j                  t        j                  |«      |j                  d«      «       y)zw
        L{safe_str} for C{bytes} with utf-8 encoded data should return
        the value decoded into C{str}.
        s   tÃ¼stúutf-8N)r$   r   ræ   Údecoderç   s     r   Útest_workingUtf8_3zSafeStrTests.test_workingUtf8_3ÿ  s-   € ð
 ˆØ×Ñœ×)Ñ)¨!Ó,¨a¯h©h°wÓ.?Õ@r   c                 óh   — d}t        j                  |«      }| j                  |t        |«      «       y)z=
        Use str() for non-utf8 bytes: "b'non-utf8'"
        ó   ÿN)r   ræ   r$   r}   )r   r&   ÚxStrs      r   Útest_brokenUtf8zSafeStrTests.test_brokenUtf8  s-   € ð ˆÜ×Ñ Ó"ˆØ×Ñ˜œs 1›vÕ&r   c                 óP   — t        «       }d|_        t        j                  |«       y rê   )r’   r™   r   ræ   rÀ   s     r   r¾   zSafeStrTests.test_brokenRepr  s   € Ü‹KˆØˆŒÜ×Ñ˜Õr   c                 ó€   —  G d„ dt         «      }t        j                  |«       t        j                   |«       «       y )Nc                   ó   — e Zd ZdZy)ú+SafeStrTests.test_brokenClassStr.<locals>.XTNr×   r   r   r   rÆ   rù     rØ   r   rÆ   ©r    r   ræ   rÉ   s     r   rÙ   z SafeStrTests.test_brokenClassStr  s.   € ô	”ô 	ô 	×Ñ˜ÔÜ×Ñ™›Õr   c                 ó€   —  G d„ dt         «      }t        j                  |«       t        j                   |«       «       y )Nc                   ó   — e Zd ZdZy)ú,SafeStrTests.test_brokenClassRepr.<locals>.XTNrÅ   r   r   r   rÆ   rý     rÇ   r   rÆ   rú   rÉ   s     r   rÊ   z!SafeStrTests.test_brokenClassRepr  s.   € ô	”ô 	ô 	×Ñ˜ÔÜ×Ñ™›Õr   c                 ó  — t        «       }d|_        t        j                  |«      }| j	                  d|«       | j	                  t
        j                  j                  t        «      d   |«       | j	                  d|«       y)z¬
        If an object raises an exception when accessing its C{__class__}
        attribute, L{reflect.safe_str} uses C{type} to retrieve the class
        object.
        TrÛ   r   úRuntimeError: str!N)	r¢   r•   r   ræ   r¶   r·   r¸   r¹   rº   )r   r¼   ÚbStrs      r   rÜ   z&SafeStrTests.test_brokenClassAttribute"  sb   € ô ‹MˆØˆŒ
Ü×Ñ Ó"ˆØ�‰Ð2°DÔ9Ø�‰”b—g‘g×&Ñ&¤xÓ0°Ñ3°TÔ:Ø�‰Ð*¨DÕ1r   c                 ó
  —  G d„ dt         «      }t        j                   |«       «      }| j                  d|«       | j                  t        j
                  j                  t        «      d   |«       | j                  d|«       y)zâ
        If a class raises an exception when accessing its C{__name__} attribute
        B{and} when calling its C{__str__} implementation, L{reflect.safe_str}
        returns 'BROKEN CLASS' instead of the class name.
        c                   ó   — e Zd ZdZy)ú5SafeStrTests.test_brokenClassNameAttribute.<locals>.XTNrà   r   r   r   rÆ   r  6  rÇ   r   rÆ   rá   r   rÿ   N)r    r   ræ   r¶   r·   r¸   r¹   rº   )r   rÆ   rô   s      r   râ   z*SafeStrTests.test_brokenClassNameAttribute/  sb   € ô	”ô 	ô ×Ñ¡£Ó$ˆØ�‰Ð+¨TÔ2Ø�‰”b—g‘g×&Ñ&¤xÓ0°Ñ3°TÔ:Ø�‰Ð*¨DÕ1r   N)r   r   r   r   rè   rÁ   rí   rñ   rõ   r¾   rÙ   rÊ   rÜ   râ   r   r   r   rä   rä   é  s:   „ ñò6òò
3òAò'òò
òò2ó2r   rä   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚFilenameToModuleTestsz1
    Test L{filenameToModuleName} detection.
    c                 óL  — t         j                  j                  | j                  «       dd«      | _        t        j                  | j                  «       t        t         j                  j                  | j                  d«      d«      5 }|j                  d«       d d d «       t        t         j                  j                  t         j                  j                  | j                  «      d«      d«      5 }|j                  d«       d d d «       y # 1 sw Y   ŒuxY w# 1 sw Y   y xY w)NÚfakepackageÚtestz__init__.pyÚwr{   )r·   r¸   ÚjoinÚmktempÚmakedirsÚopenÚwriteÚdirname)r   Úfs     r   ÚsetUpzFilenameToModuleTests.setUpD  sÁ   € Ü—G‘G—L‘L §¡£°¸vÓFˆŒ	Ü
�‰�D—I‘IÔÜ”"—'‘'—,‘,˜tŸy™y¨-Ó8¸#Ó>ð 	À!Ø�G‰G�BŒK÷	ä”"—'‘'—,‘,œrŸw™wŸ™¨t¯y©yÓ9¸=ÓIÈ3ÓOð 	ÐSTØ�G‰G�BŒK÷	ð 	÷	ð 	ú÷	ð 	ús   ÂDÃ3DÄDÄD#c                 óþ   — t        j                  | j                  «      }| j                  |d«       t        j                  | j                  t        j                  j
                  z   «      }| j                  |d«       y)zk
        L{filenameToModuleName} returns the correct module (a package) given a
        directory.
        zfakepackage.testN)r   ÚfilenameToModuleNamer¸   r$   r·   Úsep©r   Úmodules     r   Útest_directoryz$FilenameToModuleTests.test_directoryL  s[   € ô
 ×-Ñ-¨d¯i©iÓ8ˆØ×Ñ˜Ð!3Ô4Ü×-Ñ-¨d¯i©i¼"¿'¹'¿+¹+Ñ.EÓFˆØ×Ñ˜Ð!3Õ4r   c                 ó¢   — t        j                  t        j                  j	                  | j                  d«      «      }| j                  |d«       y)zh
        L{filenameToModuleName} returns the correct module given the path to
        its file.
        ztest_reflect.pyúfakepackage.test.test_reflectN)r   r  r·   r¸   r
  r$   r  s     r   Ú	test_filezFilenameToModuleTests.test_fileV  s>   € ô
 ×-Ñ-Ü�G‰G�L‰L˜Ÿ™Ð$5Ó6ó
ˆð 	×Ñ˜Ð!@ÕAr   c                 óÀ   — t        j                  t        j                  j	                  | j                  j                  d«      d«      «      }| j                  |d«       y)zo
        L{filenameToModuleName} returns the correct module given a C{bytes}
        path to its file.
        rï   s   test_reflect.pyr  N)r   r  r·   r¸   r
  Úencoder$   r  s     r   Ú
test_bytesz FilenameToModuleTests.test_bytes`  sI   € ô
 ×-Ñ-Ü�G‰G�L‰L˜Ÿ™×)Ñ)¨'Ó2Ð4FÓGó
ˆð 	×Ñ˜Ð!@ÕAr   N)r   r   r   r   r  r  r  r  r   r   r   r  r  ?  s   „ ñòò5òBó	Br   r  c                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
ÚFullyQualifiedNameTestsz)
    Test for L{fullyQualifiedName}.
    c                 ó:   — | j                  t        |«      |«       y)ze
        Helper to check that fully qualified name of C{obj} results to
        C{expected}.
        N)r$   r   )r   ÚobjÚexpecteds      r   Ú_checkFullyQualifiedNamez0FullyQualifiedNameTests._checkFullyQualifiedNameq  s   € ð
 	×ÑÔ+¨CÓ0°(Õ;r   c                 óp   — ddl }| j                  |d«       ddl}| j                  |j                  d«       y)zd
        L{fullyQualifiedName} returns the full name of a package and a
        subpackage.
        r   Nrf   rb   )rf   r#  r]   rd   re   s     r   Útest_packagez$FullyQualifiedNameTests.test_packagex  s/   € ó
 	à×%Ñ% g¨yÔ9Ûà×%Ñ% g§n¡nÐ6FÕGr   c                 óX   — ddl }| j                  |j                  j                  d«       y)zV
        L{fullyQualifiedName} returns the name of a module inside a package.
        r   Nztwisted.python.compat)Útwisted.python.compatr#  rd   Úcompatre   s     r   Útest_modulez#FullyQualifiedNameTests.test_module„  s"   € ó 	%à×%Ñ% g§n¡n×&;Ñ&;Ð=TÕUr   c                 ó>   — | j                  t        t        › d�«       y)zS
        L{fullyQualifiedName} returns the name of a class and its module.
        z.FullyQualifiedNameTestsN)r#  r  r   r   s    r   Ú
test_classz"FullyQualifiedNameTests.test_classŒ  s   € ð 	×%Ñ%Ü#¬ zÐ1IÐ%Jõ	
r   c                 ó0   — | j                  t        d«       y)zY
        L{fullyQualifiedName} returns the name of a function inside its module.
        z)twisted.python.reflect.fullyQualifiedNameN)r#  r   r   s    r   Útest_functionz%FullyQualifiedNameTests.test_function”  s   € ð 	×%Ñ%ÜÐ Kõ	
r   c                 óx   — | j                  | j                  t        › d| j                  j                  › d�«       y)zs
        L{fullyQualifiedName} returns the name of a bound method inside its
        class and its module.
        ú.z.test_boundMethodN)r#  Útest_boundMethodr   r¦   r   s    r   r0  z(FullyQualifiedNameTests.test_boundMethodœ  s7   € ð
 	×%Ñ%Ø×!Ñ!Üˆj˜˜$Ÿ.™.×1Ñ1Ð2Ð2CÐDõ	
r   c                 óŒ   — | j                  | j                  j                  t        › d| j                  j                  › d�«       y)zv
        L{fullyQualifiedName} returns the name of an unbound method inside its
        class and its module.
        r/  z.test_unboundMethodN)r#  r¦   Útest_unboundMethodr   r   s    r   r2  z*FullyQualifiedNameTests.test_unboundMethod¦  s;   € ð
 	×%Ñ%Ø�N‰N×-Ñ-Üˆj˜˜$Ÿ.™.×1Ñ1Ð2Ð2EÐFõ	
r   N)r   r   r   r   r#  r%  r)  r+  r-  r0  r2  r   r   r   r  r  l  s,   „ ñò<ò
HòVò
ò
ò
ó
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y
)ÚObjectGrepTestsc                 óü   — t        «       }d|i}|di}| j                  dt        j                  ||t        j                  «      «       | j                  dt        j                  ||t        j                  «      «       y)zV
        Test references search through a dictionary, as a key or as a value.
        Nz[None]z{None}©rˆ   r¶   r   ÚobjgrepÚisSame)r   ÚoÚd1Úd2s       r   Útest_dictionaryzObjectGrepTests.test_dictionary²  s[   € ô ‹HˆØ�AˆYˆØ�ˆYˆà�‰�h¤§¡°°A´w·~±~Ó FÔGØ�‰�h¤§¡°°A´w·~±~Ó FÕGr   c                 óŠ   — t        «       }d|g}| j                  dt        j                  ||t        j                  «      «       y)z8
        Test references search through a list.
        Nú[1]r6  )r   r9  ÚLs      r   Ú	test_listzObjectGrepTests.test_list½  s3   € ô ‹HˆØ�1ˆIˆà�‰�eœWŸ_™_¨Q°´7·>±>ÓBÕCr   c                 óŠ   — t        «       }|df}| j                  dt        j                  ||t        j                  «      «       y)z9
        Test references search through a tuple.
        Nú[0]r6  )r   r9  ÚTs      r   Ú
test_tuplezObjectGrepTests.test_tupleÆ  s3   € ô ‹HˆØ�ˆIˆà�‰�eœWŸ_™_¨Q°´7·>±>ÓBÕCr   c                 ó²   —  G d„ d«      }t        «       } |«       }||_        | j                  dt        j                  ||t        j
                  «      «       y)zE
        Test references search through an object attribute.
        c                   ó   — e Zd Zy)ú,ObjectGrepTests.test_instance.<locals>.DummyNr:   r   r   r   ÚDummyrG  Ô  r<   r   rH  z.oN)rˆ   r9  r¶   r   r7  r8  )r   rH  r9  Úds       r   Útest_instancezObjectGrepTests.test_instanceÏ  sB   € ÷
	ñ 	ô ‹HˆÙ‹GˆØˆŒà�‰�dœGŸO™O¨A¨q´'·.±.ÓAÕBr   c                 óº   —  G d„ d«      } |«       }t        j                  |«      }| j                  dt        j                  ||t        j
                  «      «       y)zB
        Test references search through a weakref object.
        c                   ó   — e Zd Zy)ú+ObjectGrepTests.test_weakref.<locals>.DummyNr:   r   r   r   rH  rM  â  r<   r   rH  z()N)ÚweakrefÚrefr¶   r   r7  r8  )r   rH  r9  Úw1s       r   Útest_weakrefzObjectGrepTests.test_weakrefÝ  sA   € ÷
	ñ 	ñ ‹GˆÜ�[‰[˜‹^ˆà�‰�dœGŸO™O¨B°´7·>±>ÓBÕCr   c                 óÌ  —  G d„ d«      } |«       }|j                   }| j                  dt        j                  ||j                  t        j
                  «      «       | j                  dt        j                  ||j                  j                  t        j
                  «      «       | j                  dt        j                  ||j                  t        j
                  «      «       y)zK
        Test references search through method special attributes.
        c                   ó   — e Zd Zd„ Zy)ú/ObjectGrepTests.test_boundMethod.<locals>.Dummyc                  ó   — y rG   r   r   s    r   Údummyz5ObjectGrepTests.test_boundMethod.<locals>.Dummy.dummyð  rI   r   N)r   r   r   rV  r   r   r   rH  rT  ï  rJ   r   rH  z	.__self__z.__self__.__class__z	.__func__N)rV  r¶   r   r7  Ú__self__r8  r¦   Ú__func__)r   rH  r9  Úms       r   r0  z ObjectGrepTests.test_boundMethodê  s“   € ÷
	ñ 	ñ ‹GˆØ�G‰Gˆà�‰�k¤7§?¡?°1°a·j±jÄ'Ç.Á.Ó#QÔRØ�‰Ø!Ü�O‰O˜A˜qŸz™z×3Ñ3´W·^±^ÓDô	
ð 	�‰�k¤7§?¡?°1°a·j±jÄ'Ç.Á.Ó#QÕRr   c                 ó*  —  G d„ d«      } |«       }dddd|di}dd|dg}|i  |«       f}d	d
|dœ} |«       }||_         |j                  }t        j                  |«      }	| j	                  dt        j                  |	|t
        j                  «      «       y)zF
        Test references search using complex set of objects.
        c                   ó   — e Zd Zd„ Zy)ú.ObjectGrepTests.test_everything.<locals>.Dummyc                  ó   — y rG   r   r   s    r   r   z5ObjectGrepTests.test_everything.<locals>.Dummy.method  rI   r   N)r   r   r   r   r   r   r   rH  r\    rJ   r   rH  r   ÚbazNÚQuuxÚFooshr¬   ÚfooÚbar)r   rL   r«   z"().__self__.attr[2][0][2]{'Foosh'})Úattrr   rN  rO  r¶   r   r7  r8  )
r   rH  r9  ÚD1r?  rC  ÚD2ÚirY  r	  s
             r   Útest_everythingzObjectGrepTests.test_everythingý  s•   € ÷
	ñ 	ñ ‹GˆØ�%˜˜v q¨'Ð2ˆØ�2�r˜1ÐˆØ�‘E“GÐˆØ˜5 QÑ'ˆÙ‹GˆØˆŒØ�H‰HˆÜ�K‰K˜‹Nˆà�‰Ø0´'·/±/À!ÀQÌÏÉÓ2Wõ	
r   c           	      ór  — g }|g}||g}||g}| j                  dgt        j                  ||t        j                  d¬«      «       | j                  ddgt        j                  ||t        j                  d¬«      «       | j                  g d¢t        j                  ||t        j                  d¬«      «       y)	z6
        Test the depth of references search.
        rB  rL   )ÚmaxDepthú[1][0]r«   )rB  rj  z	[1][1][0]r¬   N)r$   r   r7  r8  )r   rì   r¼   ÚcrI  s        r   Útest_depthLimitzObjectGrepTests.test_depthLimit  sœ   € ð ˆØˆCˆØ�ˆFˆØ�ˆFˆà×Ñ˜%˜¤'§/¡/°!°Q¼¿¹ÐQRÔ"SÔTØ×ÑØ�HÐœwŸ™¨q°!´W·^±^ÈaÔPô	
ð 	×ÑÚ*Ü�O‰O˜A˜q¤'§.¡.¸1Ô=õ	
r   c                 óÚ   — t        «       }t        «       }|j                  d«       |j                  |«       | j                  dt	        j
                  ||t        j                  «      «       y)z@
        Test references search through a deque object.
        Nr>  )rˆ   r   Úappendr¶   r   r7  r8  )r   r9  ÚDs      r   Ú
test_dequezObjectGrepTests.test_deque&  sG   € ô ‹HˆÜ‹GˆØ	�‰�ŒØ	�‰�Œà�‰�eœWŸ_™_¨Q°´7·>±>ÓBÕCr   N)r   r   r   r<  r@  rD  rJ  rQ  r0  rg  rl  rp  r   r   r   r4  r4  ±  s6   „ ò	HòDòDòCòDòSò&
ò.
ó$	Dr   r4  c                   ó   — e Zd Zd„ Zy)ÚGetClassTestsc                 óâ   —  G d„ d«      } |«       }| j                  t        j                  |«      j                  d«       | j                  t        j                  |«      j                  d«       y )Nc                   ó   — e Zd Zy)ú(GetClassTests.test_new.<locals>.NewClassNr:   r   r   r   ÚNewClassru  4  r<   r   rv  Útype)r$   r   ÚgetClassr   )r   rv  Únews      r   Útest_newzGetClassTests.test_new3  sW   € ÷	ñ 	ñ ‹jˆØ×Ñœ×)Ñ)¨(Ó3×<Ñ<¸fÔEØ×Ñœ×)Ñ)¨#Ó.×7Ñ7¸ÕDr   N)r   r   r   rz  r   r   r   rr  rr  2  s   „ óEr   rr  )$r   r·   rN  Úcollectionsr   r]   r   Útwisted.python.reflectr   r   r   r   r	   Útwisted.trial.unittestr
   ÚTestCaser   r   r   r"   r/   r4   r?   rO   rS   r’   rw  rœ   r    r¢   r¨   rä   r  r  r4  rr  r   r   r   ú<module>r     s*  ðñó
 
Û Ý å "÷õ õ C÷	ñ 	ôˆ$ô ÷ñ ô &<˜Xô &<ôR2˜8ô 2ô2J˜xô Jô03 ô 3÷.ñ ôq
�8ô q
÷h!ñ !ô"�˜Dô ñ 
�H˜y˜l¸$ÈDÑ,QÓ	R€ô0�)ô 0ôZ4�Hô Z4ôzS2�8ô S2ôl*B˜Hô *BôZB
˜hô B
ôJ~D�hô ~DôBE�Hõ Er   