
    tfd                     L   d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZ ddlmZ  G d	 d
e
j                  Z G d de          Z G d de          Z ee           G d de
j                              Z ee           G d de
j                              Z G d de
j                  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! eee e!           G d! d"e
j                              Z" ee           G d# d$                      Z# G d% d&          Z$ G d' d(ej%        e$          Z& G d) d*ej%                  Z' G d+ d,e          Z( ee(           G d- d.e
j                              Z) ee(           G d/ d0e
j                              Z* G d1 d2          Z+ G d3 d4e
j                  Z, ee(           G d5 d6e
j                              Z- G d7 d8e          Z. G d9 d:e          Z/ ee.           G d; d<                      Z0e G d= d>                      Z1 G d? d@e$ej%                  Z2 G dA dBe$ej%                  Z3 G dC dDe          Z4 G dE dFe4          Z5 ee4           G dG dH                      Z6 ee5           G dI dJ                      Z7 G dK dLe          Z8 G dM dN          Z9 G dO dPej%                  Z:dQS )Rz0
Test cases for Twisted component architecture.
    )wraps)	Attribute	Interfaceimplementer)AdapterRegistry)
components)cmp
comparable)_addHook_removeHookproxyForInterface)unittestc                       e Zd ZdZd ZdS )Compor   c                 .    | j         dz   | _         | j         S N   numselfs    b/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/test_components.pyincz	Compo.inc   s    8a<x    N)__name__
__module____qualname__r   r    r   r   r   r      s(        
C    r   r   c                       e Zd Zd ZdS )IAdeptc                      t                      N)NotImplementedErrorr   r   r   adaptorFunczIAdept.adaptorFunc   s    !###r   N)r   r   r   r$   r   r   r   r    r       s#        $ $ $ $ $r   r    c                       e Zd Zd ZdS )IElapsedc                      dS )z
        1!
        Nr   r   r   r   elapsedFunczIElapsed.elapsedFunc#         r   Nr   r   r   r(   r   r   r   r&   r&   "   s#            r   r&   c                       e Zd Zd Zd ZdS )Adeptc                 "    || _         d| _        d S Nr   originalr   r   origs     r   __init__zAdept.__init__+   s    r   c                 `    | j         dz   | _         | j         | j                                        fS r   )r   r0   r   r   s    r   r$   zAdept.adaptorFunc/   s*    8a<x**,,,,r   N)r   r   r   r3   r$   r   r   r   r,   r,   )   s2          - - - - -r   r,   c                       e Zd Zd ZdS )Elapsedc                     dS r   r   r   s    r   r(   zElapsed.elapsedFunc6   s    qr   Nr*   r   r   r   r6   r6   4   s#            r   r6   c                       e Zd ZdS )ACompNr   r   r   r   r   r   r9   r9   :           Dr   r9   c                       e Zd ZdS )BCompNr:   r   r   r   r=   r=   >   r;   r   r=   c                       e Zd ZdS )CCompNr:   r   r   r   r?   r?   B   r;   r   r?   c                       e Zd ZdS )ITestNr:   r   r   r   rA   rA   F   r;   r   rA   c                       e Zd ZdS )ITest2Nr:   r   r   r   rC   rC   J   r;   r   rC   c                       e Zd ZdS )ITest3Nr:   r   r   r   rE   rE   N   r;   r   rE   c                       e Zd ZdS )ITest4Nr:   r   r   r   rG   rG   R   r;   r   rG   c                       e Zd Zd ZdS )Testc                     d S r"   r   r1   s     r   r3   zTest.__init__X       r   Nr   r   r   r3   r   r   r   rI   rI   V   s#            r   rI   c                       e Zd ZdZd ZdS )Test2r   c                     d S r"   r   r1   s     r   r3   zTest2.__init__`   rK   r   N)r   r   r   temporaryAdapterr3   r   r   r   rN   rN   \   s)            r   rN   c                       e Zd ZdZd ZdS )RegistryUsingMixinzH
    Mixin for test cases which modify the global registry somehow.
    c                     t                      }|                     t          d|           t          |          }|                     t
          |           dS )z
        Configure L{twisted.python.components.registerAdapter} to mutate an
        alternate registry to improve test isolation.
        globalRegistryN)r   patchr   r   
addCleanupr   )r   scratchRegistryhooks      r   setUpzRegistryUsingMixin.setUpi   sO     *++

:/AAA ((T*****r   N)r   r   r   __doc__rY   r   r   r   rR   rR   d   s-         + + + + +r   rR   c                   N    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S )ComponentizedTestsz8
    Simple test case for caching in Componentized.
    c                    t                               |            t          j        t          t
          t                     t          j        t          t
          t                     t          j        t          t
          t                     d S r"   )
rR   rY   r   registerAdapterrI   r9   rA   rE   rN   rC   r   s    r   rY   zComponentizedTests.setUp~   s[      &&&"4666"4777"5%88888r   c                    t          j        t          t          t                     t          j        t
          t          t                     t                      }|                    t                                                    dk    sJ |                    t                                                    dk    sJ t          t	          |                    	                                dk    sJ d S )N)r   r   )   r`   r   )
r   r^   r,   r   r    r6   r&   getComponentr$   r(   r   cs     r   testComponentizedz$ComponentizedTests.testComponentized   s    "5%888"7E8<<<GG~~f%%1133v====~~f%%1133v====q		""..00A555555r   c                    t                      }|                    t                    }|                    t                    }|                    t                    }|                    t                    }||u sJ ||usJ |                    |           |                    t                    }|                    t                    }||u sJ ||usJ d S r"   )r?   ra   rA   rC   removeComponent)r   rc   co1co2co3co4co5co6s           r   testInheritanceAdaptationz,ComponentizedTests.testInheritanceAdaptation   s    GGnnU##nnU##nnV$$nnV$$czzzz#~~~~	#nnU##nnU##czzzz#~~~~~~r   c                    t                      }|                    t                    }|                    t                    }|                    t                    }|                     |           |                     ||           d S r"   )r?   ra   rA   rE   rG   assertIsNoneassertIs)r   rc   rg   ri   rj   s        r   testMultiAdapterz#ComponentizedTests.testMultiAdapter   sl    GGnnU##nnV$$nnV$$#c3r   c                 b   t          j                    }t                      }|                     |                    t
          |          |           |                     |                    t
          |          |           |                     |                    t
                    d           dS )z
        Test that a default value specified to Componentized.getComponent if
        there is no component for the requested interface.
        )defaultN)r   Componentizedobjectrp   ra   rA   )r   componentizedrs   s      r   test_getComponentDefaultsz,ComponentizedTests.test_getComponentDefaults   s    
 #022((m00@@'JJJm000HH'RRRm0077>>>>>r   c                    t          j                    }|                    t          t                     |                    t                    }|                     |j        |           |                     |t                     dS )z
        C{Componentized.setAdapter} sets a component for an interface by
        wrapping the instance with the given adapter class.
        N)	r   rt   
setAdapterr    r,   ra   assertEqualr0   assertIsInstancer   rv   	components      r   test_setAdapterz"ComponentizedTests.test_setAdapter   sp    
 #022  ///!..v66	+];;;i/////r   c                    t          j                    }|                    t          d           |                    t
                    }|                     |j        |           |                     |t                     dS )z
        C{Componentized.setAdapter} adapts the instance by wrapping it with
        given adapter class, then stores it using C{addComponent}.
        T)ignoreClassN)	r   rt   
addAdapterr,   ra   r    rz   r0   r{   r|   s      r   test_addAdapterz"ComponentizedTests.test_addAdapter   ss    
 #022  D 999!..v66	+];;;i/////r   c                     t          j                    }t                      }|                    t          |           |                     |                    t                    |           dS )zx
        C{Componentized.setComponent} stores the given component using the
        given interface as the key.
        N)r   rt   ru   setComponentrA   rp   ra   r   rv   objs      r   test_setComponentz$ComponentizedTests.test_setComponent   sY    
 #022hh""5#...m0077=====r   c                    t          j                    }t                      }|                    t          |           |                    t                     |                     |                    t                               dS )zm
        C{Componentized.setComponent} removes the cached component for the
        given interface.
        N)r   rt   ru   r   rA   unsetComponentro   ra   r   s      r   test_unsetComponentz&ComponentizedTests.test_unsetComponent   sm    
 #022hh""5#...$$U+++-44U;;<<<<<r   c                     t          j                    }|                    t          d           t	          |          }|                     d|           |                     d|           dS )zR
        C{ReprableComponentized} has a C{__repr__} that lists its cache.
        hellorA   N)r   ReprableComponentizedr   rA   reprassertIn)r   rcresults      r   test_reprableComponentizedz-ComponentizedTests.test_reprableComponentized   s_     -//
w'''bgv&&&gv&&&&&r   N)r   r   r   rZ   rY   rd   rm   rq   rw   r~   r   r   r   r   r   r   r   r\   r\   y   s         9 9 96 6 6       	? 	? 	?	0 	0 	0	0 	0 	0> > >	= 	= 	=' ' ' ' 'r   r\   c                       e Zd ZdZd ZdS )AdapterTestszTest adapters.c                     t                      }t          |          }|                     t          j        t
          |           |                     t          |d                      d S r"   )ru   r,   assertRaisesr   CannotAdaptrA   ro   )r   oas      r   testAdapterGetComponentz$AdapterTests.testAdapterGetComponent   sS    HH!HH*0%;;;%4..)))))r   N)r   r   r   rZ   r   r   r   r   r   r      s)        * * * * *r   r   c                       e Zd ZdS )IMetaNr:   r   r   r   r   r      r;   r   r   c                       e Zd Zd ZdS )	MetaAdderc                      | j         j        |z   S r"   r/   r   r   s     r   addzMetaAdder.add       } 3&&r   Nr   r   r   r   r   r   r   r   r      #        ' ' ' ' 'r   r   c                       e Zd Zd ZdS )BackwardsAdderc                      | j         j        |z
  S r"   r/   r   s     r   r   zBackwardsAdder.add   r   r   Nr   r   r   r   r   r      r   r   r   c                       e Zd ZdZd ZdS )
MetaNumberz9
    Integer wrapper for Interface adaptation tests.
    c                     || _         d S r"   r   r   s     r   r3   zMetaNumber.__init__  s    r   N)r   r   r   rZ   r3   r   r   r   r   r      s-             r   r   c                       e Zd Zd ZdS )ComponentNumberc                 R    d| _         t          j                            |            d S r.   )r   r   rt   r3   r   s    r   r3   zComponentNumber.__init__	  s&     ))$/////r   NrL   r   r   r   r   r     s#        0 0 0 0 0r   r   c                       e Zd ZdZd Zd ZdS )ComponentAdderz0
    Adder for componentized adapter tests.
    c                 h    t           j                            | |           | j        j        | _        d S r"   )r   Adapterr3   r0   r   r   r0   s     r   r3   zComponentAdder.__init__  s+    ##D(333=$r   c                 0    | xj         |z  c_         | j         S r"   r   r   s     r   r   zComponentAdder.add  s    Cxr   N)r   r   r   rZ   r3   r   r   r   r   r   r     s<         % % %    r   r   c                       e Zd ZdZd ZdS )IAttrXz=
    Base interface for test of adapter with C{__cmp__}.
    c                      dS )z!
        Return a value.
        Nr   r   r   r   xzIAttrX.x"  r)   r   Nr   r   r   rZ   r   r   r   r   r   r     -             r   r   c                       e Zd ZdZd ZdS )IAttrXXz@
    Adapted interface for test of adapter with C{__cmp__}.
    c                      dS )z+
        Return a tuple of values.
        Nr   r   r   r   xxz
IAttrXX.xx-  r)   r   N)r   r   r   rZ   r   r   r   r   r   r   (  r   r   r   c                       e Zd ZdZd ZdS )XcellentzG
    L{IAttrX} implementation for test of adapter with C{__cmp__}.
    c                     dS )z;
        Return a value.

        @return: a value
        x!r   r   s    r   r   z
Xcellent.x9  s	     tr   Nr   r   r   r   r   r   3  s-             r   r   c                   (    e Zd ZdZdZd Zd Zd ZdS )DoubleXAdapterz
    Adapter with __cmp__.
    *   c                     || _         d S r"   )r0   r   s     r   r3   zDoubleXAdapter.__init__J  s     r   c                 f    | j                                         | j                                         fS r"   )r0   r   r   s    r   r   zDoubleXAdapter.xxM  s%    !!4=??#4#455r   c                 6    t          | j        |j                  S r"   )r	   r   )r   others     r   __cmp__zDoubleXAdapter.__cmp__P  s    48UY'''r   N)r   r   r   rZ   r   r3   r   r   r   r   r   r   r   B  sR          C! ! !6 6 6( ( ( ( (r   r   c                        e Zd Zd Zd Zd ZdS )MetaInterfaceTestsc                     t          j        t          t          t                     t          d          }|                     t	          |                              d          d           dS )zS
        Registered adapters can be used to adapt classes to an interface.
        r   r`   N)r   r^   r   r   r   rz   r   )r   ns     r   
test_basiczMetaInterfaceTests.test_basicU  sP     	"9j%@@@qMMqa!,,,,,r   c                 `   t          j        t          t          t                     t                      }t	          |                              d           t	          |                              d           |                     t	          |                              d          d           d S )Nr      )r   r^   r   r   r   r   rz   rb   s     r   testComponentizedInteractionz/MetaInterfaceTests.testComponentizedInteraction]  sx    ">?EJJJaQaQqa!,,,,,r   c                     t          j        t          t          t                     t	          t                                }|                     d|                                           d S )N)r   r   )r   r^   r   r   r   r   rz   r   )r   r   s     r   testAdapterWithCmpz%MetaInterfaceTests.testAdapterWithCmpd  sL    ">67CCCXZZ  ruuww/////r   N)r   r   r   r   r   r   r   r   r   r   r   T  sA        - - -- - -0 0 0 0 0r   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d Zd Zd Zd Zd ZdS )RegistrationTestsz)
    Tests for adapter registration.
    c                     d }t          j        ||t                     |                     t          j        |t          d          |           dS )z
        Register an adapter with L{components.registerAdapter} for the given
        class or interface and verify that the adapter can be looked up with
        L{components.getAdapterFactory}.
        c                     d S r"   r   r   s    r   <lambda>zGRegistrationTests._registerAdapterForClassOrInterface.<locals>.<lambda>v      D r   Nr   r^   rA   rp   getAdapterFactoryr   r0   adapters      r   #_registerAdapterForClassOrInterfacez5RegistrationTests._registerAdapterForClassOrInterfacep  sI     !."7He<<<j28UDII7SSSSSr   c                 F     G d d          }|                      |          S )za
        Test that an adapter from a class can be registered and then looked
        up.
        c                       e Zd ZdS )CRegistrationTests.test_registerAdapterForClass.<locals>.TheOriginalNr:   r   r   r   TheOriginalr             Dr   r   )r   r   r   s     r   test_registerAdapterForClassz.RegistrationTests.test_registerAdapterForClassz  s@    	 	 	 	 	 	 	 	 77DDDr   c                 6    |                      t                    S )zf
        Test that an adapter from an interface can be registered and then
        looked up.
        )r   rC   r   s    r    test_registerAdapterForInterfacez2RegistrationTests.test_registerAdapterForInterface  s    
 77???r   c                     d }d }t          j        ||t                     |                     t          t           j        ||t                     |                     t          j        |t          d          |           dS )z
        Verify that L{components.registerAdapter} raises L{ValueError} if the
        from-type/interface and to-interface pair is not unique.
        c                     dS NFr   r   s    r   r   zHRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>       r   c                     dS NTr   r   s    r   r   zHRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>      $ r   N)r   r^   rA   r   
ValueErrorrp   r   )r   r0   firstAdaptersecondAdapters       r   $_duplicateAdapterForClassOrInterfacez6RegistrationTests._duplicateAdapterForClassOrInterface  sx    
 '&"<5AAA
2M8U	
 	
 	
 	j28UDII<XXXXXr   c                 F     G d d          }|                      |          S )zz
        Test that attempting to register a second adapter from a class
        raises the appropriate exception.
        c                       e Zd ZdS )DRegistrationTests.test_duplicateAdapterForClass.<locals>.TheOriginalNr:   r   r   r   r   r     r   r   r   )r   r   s     r   test_duplicateAdapterForClassz/RegistrationTests.test_duplicateAdapterForClass  s@    	 	 	 	 	 	 	 	 88EEEr   c                 6    |                      t                    S )z
        Test that attempting to register a second adapter from an interface
        raises the appropriate exception.
        )r   rC   r   s    r   !test_duplicateAdapterForInterfacez3RegistrationTests.test_duplicateAdapterForInterface  s    
 88@@@r   c                    d }d } G d dt                     }t          j        |||           dt          _        	 t          j        |||           |                     t          j        ||d          |           dt          _        n# dt          _        w xY w|                     t          t          j        |||           |                     t          j        ||d          |           dS )z
        Verify that when C{components.ALLOW_DUPLICATES} is set to C{True}, new
        adapter registrations for a particular from-type/interface and
        to-interface pair replace older registrations.
        c                     dS r   r   r   s    r   r   zORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>  r   r   c                     dS r   r   r   s    r   r   zORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>  r   r   c                       e Zd ZdS )SRegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.TheInterfaceNr:   r   r   r   TheInterfacer     r   r   r   TNF)r   r   r^   ALLOW_DUPLICATESrp   r   r   r   )r   r0   r   r   r   s        r   +_duplicateAdapterForClassOrInterfaceAllowedz=RegistrationTests._duplicateAdapterForClassOrInterfaceAllowed  s    '&	 	 	 	 	9 	 	 	 	"<<HHH&*
#	0&}hMMMMM,X|TJJ  
 +0J''%J'//// 	
2L(L	
 	
 	
 	(<FF	
 	
 	
 	
 	
s   A B
 
Bc                 F     G d d          }|                      |          S )z
        Test that when L{components.ALLOW_DUPLICATES} is set to a true
        value, duplicate registrations from classes are allowed to override
        the original registration.
        c                       e Zd ZdS )KRegistrationTests.test_duplicateAdapterForClassAllowed.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r  r   s     r   $test_duplicateAdapterForClassAllowedz6RegistrationTests.test_duplicateAdapterForClassAllowed  s@    	 	 	 	 	 	 	 	 ??LLLr   c                 R     G d dt                     }|                     |          S )z
        Test that when L{components.ALLOW_DUPLICATES} is set to a true
        value, duplicate registrations from interfaces are allowed to
        override the original registration.
        c                       e Zd ZdS )ORegistrationTests.test_duplicateAdapterForInterfaceAllowed.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r   r  r   s     r   (test_duplicateAdapterForInterfaceAllowedz:RegistrationTests.test_duplicateAdapterForInterfaceAllowed  sB    	 	 	 	 	) 	 	 	 ??LLLr   c                 
   d }t          j        ||t          t                     |                     t          j        |t          d          |           |                     t          j        |t          d          |           dS )zh
        Verify that an adapter can be registered for multiple to-interfaces at a
        time.
        c                     d S r"   r   r   s    r   r   zJRegistrationTests._multipleInterfacesForClassOrInterface.<locals>.<lambda>  r   r   N)r   r^   rA   rC   rp   r   r   s      r   &_multipleInterfacesForClassOrInterfacez8RegistrationTests._multipleInterfacesForClassOrInterface  sn    
 !."7HeVDDDj28UDII7SSSj28VTJJGTTTTTr   c                 F     G d d          }|                      |          S )zi
        Test the registration of an adapter from a class to several
        interfaces at once.
        c                       e Zd ZdS )FRegistrationTests.test_multipleInterfacesForClass.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r  r   s     r   test_multipleInterfacesForClassz1RegistrationTests.test_multipleInterfacesForClass  s@    	 	 	 	 	 	 	 	 ::;GGGr   c                 6    |                      t                    S )zn
        Test the registration of an adapter from an interface to several
        interfaces at once.
        )r  rE   r   s    r   #test_multipleInterfacesForInterfacez5RegistrationTests.test_multipleInterfacesForInterface  s    
 ::6BBBr   c                 V   d }d } G d d|          }t          j        ||t                     t          j        ||t                     |                     t          j        |t          d          |           |                     t          j        |t          d          |           dS )a   
        Verify that a new adapter can be registered for a particular
        to-interface from a subclass of a type or interface which already has an
        adapter registered to that interface and that the subclass adapter takes
        precedence over the base class adapter.
        c                     dS r   r   r   s    r   r   zSRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>  s     r   c                     dS r   r   r   s    r   r   zSRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>  s    % r   c                       e Zd ZdS )VRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.TheSubclassNr:   r   r   r   TheSubclassr  
  r   r   r  Nr   )r   r0   r   r   r  s        r   /_subclassAdapterRegistrationForClassOrInterfacezARegistrationTests._subclassAdapterRegistrationForClassOrInterface   s     &~'	 	 	 	 	( 	 	 	 	"<5AAA"=+uEEEj28UDII<XXX(eTBBM	
 	
 	
 	
 	
r   c                 F     G d d          }|                      |          S )z~
        Test that an adapter to a particular interface can be registered
        from both a class and its subclass.
        c                       e Zd ZdS )ORegistrationTests.test_subclassAdapterRegistrationForClass.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r  r   s     r   (test_subclassAdapterRegistrationForClassz:RegistrationTests.test_subclassAdapterRegistrationForClass  s@    	 	 	 	 	 	 	 	 CCKPPPr   c                 6    |                      t                    S )z
        Test that an adapter to a particular interface can be registered
        from both an interface and its subclass.
        )r  rC   r   s    r   ,test_subclassAdapterRegistrationForInterfacez>RegistrationTests.test_subclassAdapterRegistrationForInterface  s    
 CCFKKKr   N)r   r   r   rZ   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r   r   r   r   r   k  s)        T T T	E 	E 	E@ @ @Y Y Y	F 	F 	FA A A
 
 
@
M 
M 
M
M 
M 
MU U U	H 	H 	HC C C
 
 
(	Q 	Q 	QL L L L Lr   r   c                   .    e Zd ZdZ ed          Zd ZdS )IProxiedInterfacez=
    An interface class for use by L{proxyForInterface}.
    z@
        An example declared attribute, which should be proxied.c                      dS )z:
        A sample method which should be proxied.
        Nr   )r   kws     r   yayzIProxiedInterface.yay1  r)   r   N)r   r   r   rZ   r   ifaceAttributer$  r   r   r   r!  r!  '  sF          Y	C N
    r   r!  c                       e Zd ZdZd ZdS )IProxiedSubInterfacezS
    An interface that derives from another for use with L{proxyForInterface}.
    c                      dS )zD
        A different sample method which should be proxied.
        Nr   r   r   r   boozIProxiedSubInterface.boo<  r)   r   Nr   r   r   rZ   r)  r   r   r   r'  r'  7  r   r   r'  c                       e Zd ZdZd Zd ZdS )Yayablez
    A provider of L{IProxiedInterface} which increments a counter for
    every call to C{yay}.

    @ivar yays: The number of times C{yay} has been called.
    c                 "    d| _         g | _        d S r.   )yaysyayArgsr   s    r   r3   zYayable.__init__M  s    	r   c                 h    | xj         dz  c_         | j                            ||f           | j         S )z)
        Increment C{self.yays}.
        r   )r.  r/  appendr   r   r#  s      r   r$  zYayable.yayQ  s5     			Q		QG$$$yr   N)r   r   r   rZ   r3   r$  r   r   r   r,  r,  B  s<               r   r,  c                   &    e Zd ZdZdZdZd Zd ZdS )Booablez3
    An implementation of IProxiedSubInterface
    Fc                     d| _         dS )z;
        Mark the fact that 'yay' has been called.
        TN)yayedr2  s      r   r$  zBooable.yaye       


r   c                     d| _         dS )z<
        Mark the fact that 'boo' has been called.1
        TN)booedr   s    r   r)  zBooable.book  r7  r   N)r   r   r   rZ   r6  r9  r$  r)  r   r   r   r4  r4  Z  sH          EE      r   r4  c                       e Zd ZdZd Zd ZdS )IMultipleMethodsz-
    An interface with multiple methods.
    c                      dS )z4
        The first method. Should return 1.
        Nr   r   r   r   	methodOnezIMultipleMethods.methodOnew  r)   r   c                      dS )z5
        The second method. Should return 2.
        Nr   r   r   r   	methodTwozIMultipleMethods.methodTwo|  r)   r   Nr   r   r   rZ   r=  r?  r   r   r   r;  r;  r  s<           
    r   r;  c                       e Zd ZdZd Zd ZdS )MultipleMethodImplementorz:
    A precise implementation of L{IMultipleMethods}.
    c                     dS )z
        @return: 1
        r   r   r   s    r   r=  z#MultipleMethodImplementor.methodOne  	     qr   c                     dS )z
        @return: 2
        r`   r   r   s    r   r?  z#MultipleMethodImplementor.methodTwo  rD  r   Nr@  r   r   r   rB  rB    s<               r   rB  c                   f    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d ZdS )ProxyForInterfaceTestsz)
    Tests for L{proxyForInterface}.
    c                     t                      } t          t                    |          }|                     |j        |           dS )z
        Proxy objects should have an C{original} attribute which refers to the
        original object passed to the constructor.
        N)ru   r   r!  rp   r0   )r   r0   proxys      r   test_originalz$ProxyForInterfaceTests.test_original  sB    
 884!"344X>>enh/////r   c                    t          t                    }t                      } ||          }|                                 |                     |                                d           |                     |j        d           dS )z
        The class created from L{proxyForInterface} passes methods on an
        interface to the object which is passed to its constructor.
        r`   Nr   r!  r,  r$  rz   r.  )r   klassyayablerI  s       r   test_proxyMethodz'ProxyForInterfaceTests.test_proxyMethod  sq    
 ""344))g		a(((q)))))r   c                     t          t                     G fdd          }t                      } ||          }|                                 |                     d|j                   dS )z
        Methods of the class created from L{proxyForInterface} can be used with
        the decorator-helper L{functools.wraps}.
        c                   F    e Zd Z e j                   fd            ZdS )?ProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klassc                 X    | j         xj        dz  c_                            |           S r   )r0   r.  r$  )r   bases    r   r$  zCProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klass.yay  s)    ""a'""xx~~%r   N)r   r   r   r   r$  )rT  s   r   rM  rR    sB        U48__& & & & _& & &r   rM  r`   NrL  )r   rM  r0   rN  rT  s       @r   test_decoratedProxyMethodz0ProxyForInterfaceTests.test_decoratedProxyMethod  s    
 !!233	& 	& 	& 	& 	& 	& 	&D 	& 	& 	& 99%//HM*****r   c                     t                      }t                      |_         t          t                    |          |                     j        |j                   |                     t          fd           dS )zc
        Proxy objects should proxy declared attributes, but not other
        attributes.
        c                       j         S r"   )r.  )rI  s   r   r   z<ProxyForInterfaceTests.test_proxyAttribute.<locals>.<lambda>  s	    %* r   N)r,  ru   r%  r   r!  rp   r   AttributeErrorr   rN  rI  s     @r   test_proxyAttributez*ProxyForInterfaceTests.test_proxyAttribute  ss    
 ))!'4!"344W==e*G,BCCC.*<*<*<*<=====r   c                     t                      } t          t                    |          }t                      }||_        |                     |j        |           dS )zv
        The attributes that proxy objects proxy should be assignable and affect
        the original object.
        N)r,  r   r!  ru   r%  rp   r   rN  rI  thingys       r   test_proxySetAttributez-ProxyForInterfaceTests.test_proxySetAttribute  sT    
 ))4!"344W==%g,f55555r   c                     t                      }d|_         t          t                    |          }|`|                     t          |d                     dS )zu
        The attributes that proxy objects proxy should be deletable and affect
        the original object.
        Nr%  )r,  r%  r   r!  assertFalsehasattrrY  s      r   test_proxyDeleteAttributez0ProxyForInterfaceTests.test_proxyDeleteAttribute  sY    
 ))!%4!"344W== *:;;<<<<<r   c                     t                      } t          t                    |          }|                     |                                d           |                     |                                d           dS )z
        [Regression test] The proxy should send its method calls to the correct
        method, not the incorrect one.
        r   r`   N)rB  r   r;  rz   r=  r?  )r   multirI  s      r   test_multipleMethodsz+ProxyForInterfaceTests.test_multipleMethods  sn    
 *++3!"233E::**A...**A.....r   c                     G d dt          t                              }t                      } ||          }|                     |j        d           |                                 |                     |j        d           dS )zP
        It is possible to subclass the result of L{proxyForInterface}.
        c                       e Zd ZdZd ZdS )AProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxyzU
            A specialized proxy which can decrement the number of yays.
            c                 0    | j         xj        dz  c_        dS )z?
                Decrement the number of yays.
                r   N)r0   r.  r   s    r   r)  zEProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxy.boo  s      ""a'""""r   Nr*  r   r   r   SpecializedProxyrh    s-         ( ( ( ( (r   rj  r   N)r   r!  r,  rz   r.  r)  )r   rj  rN  specials       r   test_subclassingz'ProxyForInterfaceTests.test_subclassing  s    
		( 		( 		( 		( 		(01BCC 		( 		( 		( ))""7++q)))r*****r   c                 d    t          t                    }|                     |j        d           dS )zQ
        The name of a proxy class indicates which interface it proxies.
        zA(Proxy for twisted.python.test.test_components.IProxiedInterface)N)r   r!  rz   r   r   rI  s     r   test_proxyNamez%ProxyForInterfaceTests.test_proxyName  s<     ""344NR	
 	
 	
 	
 	
r   c                     t          t                    }|                     t                              |                     dS )zO
        The resulting proxy implements the interface that it proxies.
        N)r   r!  
assertTrueimplementedByro  s     r   test_implementsz&ProxyForInterfaceTests.test_implements  s9     ""344)77>>?????r   c                 P    G d d          } |            } |            }||_         t          j        dd          }|                     |                    |          |j                   |                    d          } ||           |                     |j                   dS )a\  
        _ProxyDescriptor's __get__ method should return the appropriate
        attribute of its argument's 'original' attribute if it is invoked with
        an object.  If it is invoked with None, it should return a false
        class-method emulator instead.

        For some reason, Python's documentation recommends to define
        descriptors' __get__ methods with the 'type' parameter as optional,
        despite the fact that Python itself never actually calls the descriptor
        that way.  This is probably do to support 'foo.__get__(bar)' as an
        idiom.  Let's make sure that the behavior is correct.  Since we don't
        actually use the 'type' argument at all, this test calls it the
        idiomatic way to ensure that signature works; test_proxyInheritance
        verifies the how-Python-actually-calls-it signature.
        c                       e Zd ZdZd ZdS )>ProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.SampleFc                     d| _         d S r   )calledr   s    r   r   zDProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.Sample.hello&  s    "r   N)r   r   r   ry  r   r   r   r   Samplerw  #  s(        F# # # # #r   rz  r   r0   N)r0   r   _ProxyDescriptorrz   __get__r   rr  ry  )r   rz  	fakeProxy
testObjectpdfakeClassMethods         r   test_proxyDescriptorGetz.ProxyForInterfaceTests.test_proxyDescriptorGet  s    "	# 	# 	# 	# 	# 	# 	# 	# FHH	VXX
'	(*==I..
0@AAA**T**	"""
)*****r   c                 N    G d dt          t                               G fdd          }t                      } ||          }|                     |                    dddd	          d
           |                     |j        dt          dd	          fg           dS )z
        Subclasses of the class returned from L{proxyForInterface} should be
        able to upcall methods by reference to their superclass, as any normal
        Python class can.
        c                       e Zd ZdZdS )DProxyForInterfaceTests.test_proxyInheritance.<locals>.YayableWrapperzI
            This class does not override any functionality.
            N)r   r   r   rZ   r   r   r   YayableWrapperr  9  s           r   r  c                   "    e Zd ZdZdZ fdZdS )EProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapperz@
            This class overrides the 'yay' method.
            r   c                 L    | xj         dz  c_          j        | g|R i |dz   S )Nr      )wrappedYaysr$  )r   r   kr  s      r   r$  zIProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapper.yayE  s?      A%  )~)$8888a881<<r   N)r   r   r   rZ   r  r$  )r  s   r   EnhancedWrapperr  >  s?          K= = = = = = =r   r  r            )r   y   )r   r  N)r   r!  r,  rz   r$  r/  dict)r   r  rN  wrapperr  s       @r   test_proxyInheritancez,ProxyForInterfaceTests.test_proxyInheritance2  s    	 	 	 	 	./@AA 	 	 	
		= 		= 		= 		= 		= 		= 		=n 		= 		= 		= ))!/'**QQ!44a888FD1NNN+C*DEEEEEr   c                    t          t                    }t                      } ||          }|                                 |                                 |                     |j                   |                     |j                   dS )z
        Proxies of subinterfaces generated with proxyForInterface should allow
        access to attributes of both the child and the base interfaces.
        N)r   r'  r4  r$  r)  rr  r6  r9  )r   
proxyClassbooablerI  s       r   test_interfaceInheritancez0ProxyForInterfaceTests.test_interfaceInheritanceN  sr    
 '';<<
))
7##				&&&&&&&&r   c                    t                      }t                      |_         t          t          d          |          }|                     |j        |           |                     |                                d           |                     |j        |j                   t                      }||_        |                     |j        |           |`| 	                    t          |d                     dS )a  
        The original attribute name can be customized via the
        C{originalAttribute} argument of L{proxyForInterface}: the attribute
        should change, but the methods of the original object should still be
        callable, and the attributes still accessible.
        foo)originalAttributer   r%  N)r,  ru   r%  r   r!  rp   r  rz   r$  r`  ra  r\  s       r   test_attributeCustomizationz2ProxyForInterfaceTests.test_attributeCustomization[  s     ))!'M!"3uMMMgVVei))) 	a(((e*G,BCCC%g,f555 *:;;<<<<<r   N)r   r   r   rZ   rJ  rO  rU  rZ  r^  rb  re  rm  rp  rt  r  r  r  r  r   r   r   rG  rG    s         0 0 0
* 
* 
*+ + +$	> 	> 	>	6 	6 	6	= 	= 	=/ / /+ + +,
 
 
@ @ @+ + +@F F F8' ' '= = = = =r   rG  N);rZ   	functoolsr   zope.interfacer   r   r   zope.interface.adapterr   twisted.pythonr   twisted.python.compatr	   r
   twisted.python.componentsr   r   r   twisted.trialr   rt   r   r    r&   r   r,   r6   r9   r=   r?   rA   rC   rE   rG   rI   rN   rR   SynchronousTestCaser\   r   r   r   r   r   r   r   r   r   r   r   r   r   r!  r'  r,  r4  r;  rB  rG  r   r   r   <module>r     s  
 
       < < < < < < < < < < 2 2 2 2 2 2 % % % % % % 1 1 1 1 1 1 1 1 N N N N N N N N N N " " " " " "    J$   $ $ $ $ $Y $ $ $
    y    V- - - - -J - - - X    j    
	 	 	 	 	J$ 	 	 		 	 	 	 	E 	 	 		 	 	 	 	E 	 	 		 	 	 	 	I 	 	 		 	 	 	 	Y 	 	 		 	 	 	 	Y 	 	 		 	 	 	 	Y 	 	 	 UFF##    :   $#
 V       + + + + + + + +*i' i' i' i' i'57I i' i' i'X* * * * *8/ * * *	 	 	 	 	I 	 	 	 U' ' ' ' '
" ' ' '
 U' ' ' ' 'Z' ' ' '
       0 0 0 0 0j. 0 0 0 U    Z'       Y       i    V        ( ( ( ( ( ( ( ("0 0 0 0 0+X-I 0 0 0.yL yL yL yL yL*H,H yL yL yLx    	        ,            . !""       #".    y           $Z= Z= Z= Z= Z=X9 Z= Z= Z= Z= Z=r   