
    Vhd                        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
j0                               Z ee       G d de
j0                               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
j0                               Z" ee       G d# d$             Z# G d% d&      Z$ G d' d(ejJ                  e$      Z& G d) d*ejJ                        Z' G d+ d,e      Z( ee(       G d- d.e
j0                               Z) ee(       G d/ d0e
j0                               Z* G d1 d2      Z+ G d3 d4e
j(                        Z, ee(       G d5 d6e
j0                               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jJ                        Z2 G dA dBe$ejJ                        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jJ                        Z:yQ)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y)Compor   c                 B    | j                   dz   | _         | j                   S N   numselfs    S/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_components.pyincz	Compo.inc   s    88a<xx    N)__name__
__module____qualname__r   r    r   r   r   r      s    
Cr   r   c                       e Zd Zd Zy)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y)IElapsedc                       y)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y)Adeptc                      || _         d| _        y Nr   originalr   r   origs     r   __init__zAdept.__init__+   s    r   c                 v    | j                   dz   | _         | j                   | j                  j                         fS r   )r   r0   r   r   s    r   r$   zAdept.adaptorFunc/   s-    88a<xx**,,,r   N)r   r   r   r3   r$   r   r   r   r,   r,   )   s    -r   r,   c                       e Zd Zd Zy)Elapsedc                      yr   r   r   s    r   r(   zElapsed.elapsedFunc6   s    r   Nr*   r   r   r   r6   r6   4   s    r   r6   c                       e Zd Zy)ACompNr   r   r   r   r   r   r9   r9   :       r   r9   c                       e Zd Zy)BCompNr:   r   r   r   r=   r=   >   r;   r   r=   c                       e Zd Zy)CCompNr:   r   r   r   r?   r?   B   r;   r   r?   c                       e Zd Zy)ITestNr:   r   r   r   rA   rA   F   r;   r   rA   c                       e Zd Zy)ITest2Nr:   r   r   r   rC   rC   J   r;   r   rC   c                       e Zd Zy)ITest3Nr:   r   r   r   rE   rE   N   r;   r   rE   c                       e Zd Zy)ITest4Nr:   r   r   r   rG   rG   R   r;   r   rG   c                       e Zd Zd Zy)Testc                      y 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y)Test2r   c                      y 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y)RegistryUsingMixinzH
    Mixin for test cases which modify the global registry somehow.
    c                     t               }| j                  t        d|       t        |      }| j	                  t
        |       y)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   s7     *+

:/A (T*r   N)r   r   r   __doc__rY   r   r   r   rR   rR   d   s    +r   rR   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)ComponentizedTestsz8
    Simple test case for caching in Componentized.
    c                     t         j                  |        t        j                  t        t
        t               t        j                  t        t
        t               t        j                  t        t
        t               y r"   )
rR   rY   r   registerAdapterrI   r9   rA   rE   rN   rC   r   s    r   rY   zComponentizedTests.setUp~   sF      &""46""47""5%8r   c                    t        j                  t        t        t               t        j                  t
        t        t               t               }|j                  t              j                         dk(  sJ |j                  t              j                         dk(  sJ t        t	        |            j                         dk(  sJ y )N)r   r   )   r`   r   )
r   r^   r,   r   r    r6   r&   getComponentr$   r(   r   cs     r   testComponentizedz$ComponentizedTests.testComponentized   s    ""5%8""7E8<G~~f%113v===~~f%113v===q	"..0A555r   c                 f   t               }|j                  t              }|j                  t              }|j                  t              }|j                  t              }||u sJ ||usJ |j	                  |       |j                  t              }|j                  t              }||u sJ ||usJ y r"   )r?   ra   rA   rC   removeComponent)r   rc   co1co2co3co4co5co6s           r   testInheritanceAdaptationz,ComponentizedTests.testInheritanceAdaptation   s    GnnU#nnU#nnV$nnV$czz#~~	#nnU#nnU#czz#~~r   c                     t               }|j                  t              }|j                  t              }|j                  t              }| j                  |       | j                  ||       y r"   )r?   ra   rA   rE   rG   assertIsNoneassertIs)r   rc   rg   ri   rj   s        r   testMultiAdapterz#ComponentizedTests.testMultiAdapter   sO    GnnU#nnV$nnV$#c3r   c                 $   t        j                         }t               }| j                  |j	                  t
        |      |       | j                  |j	                  t
        |      |       | j                  |j	                  t
              d       y)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   sk    
 #002(m00@'Jm000H'Rm007>r   c                     t        j                         }|j                  t        t               |j                  t              }| j                  |j                  |       | j                  |t               y)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   sX    
 #002  /!..v6	++];i/r   c                     t        j                         }|j                  t        d       |j	                  t
              }| j                  |j                  |       | j                  |t               y)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   s[    
 #002  D 9!..v6	++];i/r   c                     t        j                         }t               }|j                  t        |       | j                  |j                  t              |       y)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   sB    
 #002h""5#.m007=r   c                     t        j                         }t               }|j                  t        |       |j                  t               | j                  |j                  t                     y)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   sP    
 #002h""5#.$$U+-44U;<r   c                     t        j                         }|j                  t        d       t	        |      }| j                  d|       | j                  d|       y)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   sE     --/
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   s9    96 	?	0	0>	='r   r\   c                       e Zd ZdZd Zy)AdapterTestszTest adapters.c                     t               }t        |      }| j                  t        j                  t
        |       | j                  t        |d              y r"   )ru   r,   assertRaisesr   CannotAdaptrA   ro   )r   oas      r   testAdapterGetComponentz$AdapterTests.testAdapterGetComponent   s>    H!H*00%;%4.)r   N)r   r   r   rZ   r   r   r   r   r   r      s
    *r   r   c                       e Zd Zy)IMetaNr:   r   r   r   r   r      r;   r   r   c                       e Zd Zd Zy)	MetaAdderc                 4    | 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y)BackwardsAdderc                 4    | 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y)
MetaNumberz9
    Integer wrapper for Interface adaptation tests.
    c                     || _         y 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y)ComponentNumberc                 P    d| _         t        j                  j                  |        y r.   )r   r   rt   r3   r   s    r   r3   zComponentNumber.__init__	  s      ))$/r   NrL   r   r   r   r   r     s    0r   r   c                       e Zd ZdZd Zd Zy)ComponentAdderz0
    Adder for componentized adapter tests.
    c                 z    t         j                  j                  | |       | j                  j                  | _        y r"   )r   Adapterr3   r0   r   r   r0   s     r   r3   zComponentAdder.__init__  s)    ##D(3==$$r   c                 D    | xj                   |z  c_         | j                   S r"   r   r   s     r   r   zComponentAdder.add  s    Cxx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y)IAttrXz=
    Base interface for test of adapter with C{__cmp__}.
    c                       y)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y)IAttrXXz@
    Adapted interface for test of adapter with C{__cmp__}.
    c                       y)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y)XcellentzG
    L{IAttrX} implementation for test of adapter with C{__cmp__}.
    c                      y)z;
        Return a value.

        @return: a value
        x!r   r   s    r   r   z
Xcellent.x9  s     r   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y)DoubleXAdapterz
    Adapter with __cmp__.
    *   c                     || _         y r"   )r0   r   s     r   r3   zDoubleXAdapter.__init__J  s	     r   c                 j    | j                   j                         | j                   j                         fS r"   )r0   r   r   s    r   r   zDoubleXAdapter.xxM  s#    !4==??#455r   c                 B    t        | j                  |j                        S r"   )r	   r   )r   others     r   __cmp__zDoubleXAdapter.__cmp__P  s    488UYY''r   N)r   r   r   rZ   r   r3   r   r   r   r   r   r   r   B  s     C!6(r   r   c                       e Zd Zd Zd Zd Zy)MetaInterfaceTestsc                     t        j                  t        t        t               t        d      }| j                  t	        |      j                  d      d       y)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  s;     	""9j%@qMqa!,r   c                    t        j                  t        t        t               t               }t	        |      j                  d       t	        |      j                  d       | j                  t	        |      j                  d      d       y )Nr      )r   r^   r   r   r   r   rz   rb   s     r   testComponentizedInteractionz/MetaInterfaceTests.testComponentizedInteraction]  sV    "">?EJaQaQqa!,r   c                     t        j                  t        t        t               t	        t                     }| j                  d|j                                y )N)r   r   )r   r^   r   r   r   r   rz   r   )r   r   s     r   testAdapterWithCmpz%MetaInterfaceTests.testAdapterWithCmpd  s6    "">67CXZ ruuw/r   N)r   r   r   r   r   r   r   r   r   r   r   T  s    --0r   r   c                   j    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y)RegistrationTestsz)
    Tests for adapter registration.
    c                     d }t        j                  ||t               | j                  t        j                  |t        d      |       y)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                      y r"   r   r   s    r   <lambda>zGRegistrationTests._registerAdapterForClassOrInterface.<locals>.<lambda>v  r)   r   Nr   r^   rA   rp   getAdapterFactoryr   r0   adapters      r   #_registerAdapterForClassOrInterfacez5RegistrationTests._registerAdapterForClassOrInterfacep  s8     !""7He<j228UDI7Sr   c                 8     G d d      }| j                  |      S )za
        Test that an adapter from a class can be registered and then looked
        up.
        c                       e Zd Zy)CRegistrationTests.test_registerAdapterForClass.<locals>.TheOriginalNr:   r   r   r   TheOriginalr         r   r   )r   r   r   s     r   test_registerAdapterForClassz.RegistrationTests.test_registerAdapterForClassz  s    	 	 77DDr   c                 ,    | j                  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               | j                  t        t         j                  ||t               | j                  t        j                  |t        d      |       y)z
        Verify that L{components.registerAdapter} raises L{ValueError} if the
        from-type/interface and to-interface pair is not unique.
        c                      yNFr   r   s    r   r   zHRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>  r)   r   c                      yNTr   r   s    r   r   zHRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>  r)   r   N)r   r^   rA   r   
ValueErrorrp   r   )r   r0   firstAdaptersecondAdapters       r   $_duplicateAdapterForClassOrInterfacez6RegistrationTests._duplicateAdapterForClassOrInterface  s^    
 '&""<5A
22M8U	
 	j228UDI<Xr   c                 8     G d d      }| j                  |      S )zz
        Test that attempting to register a second adapter from a class
        raises the appropriate exception.
        c                       e Zd Zy)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Er   c                 ,    | j                  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                  |||       | j	                  t        j
                  ||d      |       dt        _        | j                  t        t        j                  |||       | j	                  t        j
                  ||d      |       y# dt        _        w xY w)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                      yr   r   r   s    r   r   zORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>  r)   r   c                      yr   r   r   s    r   r   zORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>  r)   r   c                       e Zd Zy)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&*
#	0&&}hMMM,,X|TJ
 +0J' 	
22L(L	
 	((<F	
 +0J's   >C Cc                 8     G d d      }| j                  |      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y)KRegistrationTests.test_duplicateAdapterForClassAllowed.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r   r   s     r   $test_duplicateAdapterForClassAllowedz6RegistrationTests.test_duplicateAdapterForClassAllowed  s    	 	 ??LLr   c                 B     G d dt               }| j                  |      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y)ORegistrationTests.test_duplicateAdapterForInterfaceAllowed.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r   r   r   s     r   (test_duplicateAdapterForInterfaceAllowedz:RegistrationTests.test_duplicateAdapterForInterfaceAllowed  s!    	) 	 ??LLr   c                     d }t        j                  ||t        t               | j	                  t        j
                  |t        d      |       | j	                  t        j
                  |t        d      |       y)zh
        Verify that an adapter can be registered for multiple to-interfaces at a
        time.
        c                      y r"   r   r   s    r   r   zJRegistrationTests._multipleInterfacesForClassOrInterface.<locals>.<lambda>  r)   r   N)r   r^   rA   rC   rp   r   r   s      r   &_multipleInterfacesForClassOrInterfacez8RegistrationTests._multipleInterfacesForClassOrInterface  sW    
 !""7HeVDj228UDI7Sj228VTJGTr   c                 8     G d d      }| j                  |      S )zi
        Test the registration of an adapter from a class to several
        interfaces at once.
        c                       e Zd Zy)FRegistrationTests.test_multipleInterfacesForClass.<locals>.TheOriginalNr:   r   r   r   r   r    r   r   r   )r	  r   s     r   test_multipleInterfacesForClassz1RegistrationTests.test_multipleInterfacesForClass  s    	 	 ::;GGr   c                 ,    | j                  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Br   c                 >   d }d } G d d|      }t        j                  ||t               t        j                  ||t               | j                  t        j                  |t        d      |       | j                  t        j                  |t        d      |       y)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                      yr   r   r   s    r   r   zSRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>  r)   r   c                      yr   r   r   s    r   r   zSRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>  r)   r   c                       e Zd Zy)VRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.TheSubclassNr:   r   r   r   TheSubclassr  
  r   r   r  Nr   )r   r0   r   r   r  s        r   /_subclassAdapterRegistrationForClassOrInterfacezARegistrationTests._subclassAdapterRegistrationForClassOrInterface   s}     &'	( 	 	""<5A""=+uEj228UDI<X((eTBM	
r   c                 8     G d d      }| j                  |      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y)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Pr   c                 ,    | j                  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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	E@Y	FA
@
M
MU	HC
(	QLr   r   c                   &    e Zd ZdZ ed      Zd Zy)IProxiedInterfacez=
    An interface class for use by L{proxyForInterface}.
    z@
        An example declared attribute, which should be proxied.c                       y)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  '  s     	CN
r   r  c                       e Zd ZdZd Zy)IProxiedSubInterfacezS
    An interface that derives from another for use with L{proxyForInterface}.
    c                       y)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y)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 | _        y r.   )yaysyayArgsr   s    r   r3   zYayable.__init__M  s    	r   c                 ~    | xj                   dz  c_         | j                  j                  ||f       | j                   S )z)
        Increment C{self.yays}.
        r   )r+  r,  appendr   r   r   s      r   r!  zYayable.yayQ  s1     			Q	QG$yy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y)Booablez3
    An implementation of IProxiedSubInterface
    Fc                     d| _         y)z;
        Mark the fact that 'yay' has been called.
        TN)yayedr/  s      r   r!  zBooable.yaye       
r   c                     d| _         y)z<
        Mark the fact that 'boo' has been called.1
        TN)booedr   s    r   r&  zBooable.book  r4  r   N)r   r   r   rZ   r3  r6  r!  r&  r   r   r   r1  r1  Z  s     EEr   r1  c                       e Zd ZdZd Zd Zy)IMultipleMethodsz-
    An interface with multiple methods.
    c                       y)z4
        The first method. Should return 1.
        Nr   r   r   r   	methodOnezIMultipleMethods.methodOnew  r)   r   c                       y)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   r8  r8  r  s    
r   r8  c                       e Zd ZdZd Zd Zy)MultipleMethodImplementorz:
    A precise implementation of L{IMultipleMethods}.
    c                      y)z
        @return: 1
        r   r   r   s    r   r:  z#MultipleMethodImplementor.methodOne       r   c                      y)z
        @return: 2
        r`   r   r   s    r   r<  z#MultipleMethodImplementor.methodTwo  rA  r   Nr=  r   r   r   r?  r?    s    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
 Zd Zd Zd Zd Zd Zy)ProxyForInterfaceTestsz)
    Tests for L{proxyForInterface}.
    c                 z    t               } t        t              |      }| j                  |j                  |       y)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  s0    
 84!"34X>ennh/r   c                     t        t              }t               } ||      }|j                          | j	                  |j                         d       | j	                  |j
                  d       y)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yayablerF  s       r   test_proxyMethodz'ProxyForInterfaceTests.test_proxyMethod  sR    
 ""34)g		a(q)r   c                     t        t               G fdd      }t               } ||      }|j                          | j	                  d|j
                         y)z
        Methods of the class created from L{proxyForInterface} can be used with
        the decorator-helper L{functools.wraps}.
        c                   D    e Zd Z eW  j                         fd       Zy)?ProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klassc                 d    | j                   xj                  dz  c_        j                  |       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!  )rQ  s   r   rJ  rO    s    488_& &r   rJ  r`   NrI  )r   rJ  r0   rK  rQ  s       @r   test_decoratedProxyMethodz0ProxyForInterfaceTests.test_decoratedProxyMethod  sK    
 !!23	&D 	& 9/HMM*r   c                     t               }t               |_         t        t              |      | j                  j                  |j                         | j                  t        fd       y)zc
        Proxy objects should proxy declared attributes, but not other
        attributes.
        c                       j                   S r"   )r+  )rF  s   r   r   z<ProxyForInterfaceTests.test_proxyAttribute.<locals>.<lambda>  s    %** r   N)r)  ru   r"  r   r  rp   r   AttributeErrorr   rK  rF  s     @r   test_proxyAttributez*ProxyForInterfaceTests.test_proxyAttribute  sT    
 )!'4!"34W=e**G,B,BC.*<=r   c                     t               } t        t              |      }t               }||_        | j                  |j                  |       y)zv
        The attributes that proxy objects proxy should be assignable and affect
        the original object.
        N)r)  r   r  ru   r"  rp   r   rK  rF  thingys       r   test_proxySetAttributez-ProxyForInterfaceTests.test_proxySetAttribute  sA    
 )4!"34W=%g,,f5r   c                     t               }d|_         t        t              |      }|`| j	                  t        |d             y)zu
        The attributes that proxy objects proxy should be deletable and affect
        the original object.
        Nr"  )r)  r"  r   r  assertFalsehasattrrV  s      r   test_proxyDeleteAttributez0ProxyForInterfaceTests.test_proxyDeleteAttribute  sB    
 )!%4!"34W= *:;<r   c                     t               } t        t              |      }| j                  |j	                         d       | j                  |j                         d       y)z
        [Regression test] The proxy should send its method calls to the correct
        method, not the incorrect one.
        r   r`   N)r?  r   r8  rz   r:  r<  )r   multirF  s      r   test_multipleMethodsz+ProxyForInterfaceTests.test_multipleMethods  sM    
 *+3!"23E:*A.*A.r   c                      G d dt        t                    }t               } ||      }| j                  |j                  d       |j                          | j                  |j                  d       y)zP
        It is possible to subclass the result of L{proxyForInterface}.
        c                       e Zd ZdZd Zy)AProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxyzU
            A specialized proxy which can decrement the number of yays.
            c                 B    | j                   xj                  dz  c_        y)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   SpecializedProxyre    s    (r   rg  r   N)r   r  r)  rz   r+  r&  )r   rg  rK  specials       r   test_subclassingz'ProxyForInterfaceTests.test_subclassing  sY    
		(01BC 		( )"7+q)r*r   c                 Z    t        t              }| j                  |j                  d       y)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   rF  s     r   test_proxyNamez%ProxyForInterfaceTests.test_proxyName  s'     ""34NNR	
r   c                 j    t        t              }| j                  t        j                  |             y)zO
        The resulting proxy implements the interface that it proxies.
        N)r   r  
assertTrueimplementedByrl  s     r   test_implementsz&ProxyForInterfaceTests.test_implements  s'     ""34)77>?r   c                 ,    G d d      } |       } |       }||_         t        j                  dd      }| j                  |j	                  |      |j
                         |j	                  d      } ||       | j                  |j                         y)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y)>ProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.SampleFc                     d| _         y r   )calledr   s    r   r   zDProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.Sample.hello&  s	    "r   N)r   r   r   rv  r   r   r   r   Samplert  #  s    F#r   rw  r   r0   N)r0   r   _ProxyDescriptorrz   __get__r   ro  rv  )r   rw  	fakeProxy
testObjectpdfakeClassMethods         r   test_proxyDescriptorGetz.ProxyForInterfaceTests.test_proxyDescriptorGet  s}    "	# 	# H	X
'	((*=I.
0@0@A**T*	"
))*r   c                     G d dt        t                     G fdd      }t               } ||      }| j                  |j	                  dddd	      d
       | j                  |j
                  dt        dd	      fg       y)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y)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y)EProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapperz@
            This class overrides the 'yay' method.
            r   c                 `    | xj                   dz  c_          j                  | g|i |dz   S )Nr      )wrappedYaysr!  )r   r   kr  s      r   r!  zIProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapper.yayE  s6      A% )~))$88a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  rK  wrapperr  s       @r   test_proxyInheritancez,ProxyForInterfaceTests.test_proxyInheritance2  sx    	./@A 	
		=n 		= )!'*QQ!4a8FD1N+C*DEr   c                     t        t              }t               } ||      }|j                          |j	                          | j                  |j                         | j                  |j                         y)z
        Proxies of subinterfaces generated with proxyForInterface should allow
        access to attributes of both the child and the base interfaces.
        N)r   r$  r1  r!  r&  ro  r3  r6  )r   
proxyClassbooablerF  s       r   test_interfaceInheritancez0ProxyForInterfaceTests.test_interfaceInheritanceN  sR    
 '';<
)7#				&&r   c                    t               }t               |_         t        t        d      |      }| j                  |j                  |       | j                  |j                         d       | j                  |j                  |j                         t               }||_        | j                  |j                  |       |`| j                  t        |d             y)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]  r^  rY  s       r   test_attributeCustomizationz2ProxyForInterfaceTests.test_attributeCustomization[  s     )!'M!"3uMgVeii) 	a(e**G,B,BC%g,,f5 *:;<r   N)r   r   r   rZ   rG  rL  rR  rW  r[  r_  rb  rj  rm  rq  r~  r  r  r  r   r   r   rD  rD    sP    0
*+$	>	6	=/+,
@+@F8'=r   rD  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)  r1  r8  r?  rD  r   r   r   <module>r     s  

  < < 2 % 1 N N "J$$ $Y $
y  V-J - - Xj    
	J$$ 		E 		E 		I 		Y 		Y 		Y 	 UFF#:  $
 V  + +*i'557I i'X*8// *	I 	 U'
"" ' '
 U'Z'' ' '
 0j.. 0 UZ''  Y i  V   ( ( ("0+X-I-I 0.yL*H,H,H yLx	  ,     . !"  #.y   $Z=X99 Z=r   