+
    Dfjd                        R t ^ RIHt ^ RIHtHtHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^ RIHtHtHt ^ RIHt  ! R R	]
P(                  4      t ! R
 R]4      t ! R R]4      t]! ]4       ! R R]
P0                  4      4       t]! ]4       ! R R]
P0                  4      4       t ! R R]
P(                  4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t  ! R R]4      t!]! ]] ]!4       ! R  R!]
P0                  4      4       t"]! ]4       ! R" R#4      4       t# ! R$ R%4      t$ ! R& R']PJ                  ]$4      t& ! R( R)]PJ                  4      t' ! R* R+]4      t(]! ](4       ! R, R-]
P0                  4      4       t)]! ](4       ! R. R/]
P0                  4      4       t* ! R0 R14      t+ ! R2 R3]
P(                  4      t,]! ](4       ! R4 R5]
P0                  4      4       t- ! R6 R7]4      t. ! R8 R9]4      t/]! ].4       ! R: R;4      4       t0] ! R< R=4      4       t1 ! R> R?]$]PJ                  4      t2 ! R@ RA]$]PJ                  4      t3 ! RB RC]4      t4 ! RD RE]44      t5]! ]44       ! RF RG4      4       t6]! ]54       ! RH RI4      4       t7 ! RJ RK]4      t8 ! RL RM4      t9 ! RN RO]PJ                  4      t:RP# )Qz0
Test cases for Twisted component architecture.
)wraps)	Attribute	Interfaceimplementer)AdapterRegistry)
components)cmp
comparable)_addHook_removeHookproxyForInterface)unittestc                   *   a  ] tR t^t o ^ tR tRtV tR# )Compoc                J    V P                   ^,           V n         V P                   #    numselfs   &E/usr/lib/python3/dist-packages/twisted/python/test/test_components.pyinc	Compo.inc   s    88a<xx    r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      s     
C r   r   c                   &   a  ] tR t^t o R tRtV tR# )IAdeptc                     \        4       hN)NotImplementedError r   r   adaptorFuncIAdept.adaptorFunc   s    !##r   r(   N)r   r   r   r   r)   r   r    r!   s   @r   r$   r$      s     $ $r   r$   c                   &   a  ] tR t^"t o R tRtV tR# )IElapsedc                     R# )z
1!
Nr(   r(   r   r   elapsedFuncIElapsed.elapsedFunc#       r   r(   Nr   r   r   r   r.   r   r    r!   s   @r   r,   r,   "   s      r   r,   c                   ,   a  ] tR t^)t o R tR tRtV tR# )Adeptc                     Wn         ^ V n        R#     Noriginalr   r   origs   &&r   __init__Adept.__init__+   s    r   c                ~    V P                   ^,           V n         V P                   V P                  P                  4       3# r   )r   r8   r   r   s   &r   r)   Adept.adaptorFunc/   s-    88a<xx**,,,r   )r   r8   N)r   r   r   r   r;   r)   r   r    r!   s   @r   r3   r3   )   s     - -r   r3   c                   &   a  ] tR t^4t o R tRtV tR# )Elapsedc                    ^# r   r(   r   s   &r   r.   Elapsed.elapsedFunc6   s    r   r(   Nr1   r!   s   @r   r@   r@   4   s      r   r@   c                       ] tR t^:tRtR# )ACompr(   Nr   r   r   r   r   r(   r   r   rD   rD   :       r   rD   c                       ] tR t^>tRtR# )BCompr(   NrE   r(   r   r   rH   rH   >   rF   r   rH   c                       ] tR t^BtRtR# )CCompr(   NrE   r(   r   r   rJ   rJ   B   rF   r   rJ   c                       ] tR t^FtRtR# )ITestr(   NrE   r(   r   r   rL   rL   F   rF   r   rL   c                       ] tR t^JtRtR# )ITest2r(   NrE   r(   r   r   rN   rN   J   rF   r   rN   c                       ] tR t^NtRtR# )ITest3r(   NrE   r(   r   r   rP   rP   N   rF   r   rP   c                       ] tR t^RtRtR# )ITest4r(   NrE   r(   r   r   rR   rR   R   rF   r   rR   c                   &   a  ] tR t^Vt o R tRtV tR# )Testc                    R # r&   r(   r9   s   &&r   r;   Test.__init__X       r   r(   Nr   r   r   r   r;   r   r    r!   s   @r   rT   rT   V   s      r   rT   c                   *   a  ] tR t^\t o ^tR tRtV tR# )Test2c                    R # r&   r(   r9   s   &&r   r;   Test2.__init__`   rW   r   r(   N)r   r   r   r   temporaryAdapterr;   r   r    r!   s   @r   rZ   rZ   \   s      r   rZ   c                   *   a  ] tR t^dt o RtR tRtV tR# )RegistryUsingMixinz@
Mixin for test cases which modify the global registry somehow.
c                    \        4       pV P                  \        RV4       \        V4      pV P	                  \
        V4       R# )zs
Configure L{twisted.python.components.registerAdapter} to mutate an
alternate registry to improve test isolation.
globalRegistryN)r   patchr   r
   
addCleanupr   )r   scratchRegistryhooks   &  r   setUpRegistryUsingMixin.setUpi   s7     *+

:/A (T*r   r(   N)r   r   r   r   __doc__rf   r   r    r!   s   @r   r_   r_   d   s     + +r   r_   c                   `   a  ] tR t^yt o RtR tR tR tR tR t	R t
R tR	 tR
 tR tRtV tR# )ComponentizedTestsz0
Simple test case for caching in Componentized.
c                   \         P                  V 4       \        P                  ! \        \
        \        4       \        P                  ! \        \
        \        4       \        P                  ! \        \
        \        4       R # r&   )
r_   rf   r   registerAdapterrT   rD   rL   rP   rZ   rN   r   s   &r   rf   ComponentizedTests.setUp~   sF      &""46""47""5%8r   c                   \         P                  ! \        \        \        4       \         P                  ! \
        \        \        4       \        4       pVP                  \        4      P                  4       R8X  g   Q hVP                  \        4      P                  4       R8X  g   Q h\        \	        V4      4      P                  4       ^8X  g   Q hR# )r   N)r   r   )   ro   )
r   rl   r3   r   r$   r@   r,   getComponentr)   r.   r   cs   & r   testComponentized$ComponentizedTests.testComponentized   s    ""5%8""7E8<G~~f%113v===~~f%113v===q	"..0A555r   c                p   \        4       pVP                  \        4      pVP                  \        4      pVP                  \        4      pVP                  \        4      pW#J g   Q hWEJg   Q hVP	                  V4       VP                  \        4      pVP                  \        4      pWgJ g   Q hW&Jg   Q hR # r&   )rJ   rp   rL   rN   removeComponent)r   rr   co1co2co3co4co5co6s   &       r   testInheritanceAdaptation,ComponentizedTests.testInheritanceAdaptation   s    GnnU#nnU#nnV$nnV$zz~~	#nnU#nnU#zz~~r   c                    \        4       pVP                  \        4      pVP                  \        4      pVP                  \        4      pV P                  V4       V P                  W#4       R # r&   )rJ   rp   rL   rP   rR   assertIsNoneassertIs)r   rr   rw   ry   rz   s   &    r   testMultiAdapter#ComponentizedTests.testMultiAdapter   sM    GnnU#nnV$nnV$#cr   c                (   \         P                  ! 4       p\        4       pV P                  VP	                  \
        V4      V4       V P                  VP	                  \
        VR7      V4       V P                  VP	                  \
        4      R4       R# )zy
Test that a default value specified to Componentized.getComponent if
there is no component for the requested interface.
)defaultN)r   Componentizedobjectr   rp   rL   )r   componentizedr   s   &  r   test_getComponentDefaults,ComponentizedTests.test_getComponentDefaults   sk    
 #002(m00@'Jm000H'Rm007>r   c                    \         P                  ! 4       pVP                  \        \        4       VP                  \        4      pV P                  VP                  V4       V P                  V\        4       R# )zv
C{Componentized.setAdapter} sets a component for an interface by
wrapping the instance with the given adapter class.
N)	r   r   
setAdapterr$   r3   rp   assertEqualr8   assertIsInstancer   r   	components   &  r   test_setAdapter"ComponentizedTests.test_setAdapter   sX    
 #002  /!..v6	++];i/r   c                    \         P                  ! 4       pVP                  \        RR7       VP	                  \
        4      pV P                  VP                  V4       V P                  V\        4       R# )z
C{Componentized.setAdapter} adapts the instance by wrapping it with
given adapter class, then stores it using C{addComponent}.
T)ignoreClassN)	r   r   
addAdapterr3   rp   r$   r   r8   r   r   s   &  r   test_addAdapter"ComponentizedTests.test_addAdapter   s[    
 #002  D 9!..v6	++];i/r   c                    \         P                  ! 4       p\        4       pVP                  \        V4       V P                  VP                  \        4      V4       R# )z`
C{Componentized.setComponent} stores the given component using the
given interface as the key.
N)r   r   r   setComponentrL   r   rp   r   r   objs   &  r   test_setComponent$ComponentizedTests.test_setComponent   sB    
 #002h""5#.m007=r   c                    \         P                  ! 4       p\        4       pVP                  \        V4       VP                  \        4       V P                  VP                  \        4      4       R# )zU
C{Componentized.setComponent} removes the cached component for the
given interface.
N)r   r   r   r   rL   unsetComponentr   rp   r   s   &  r   test_unsetComponent&ComponentizedTests.test_unsetComponent   sP    
 #002h""5#.$$U+-44U;<r   c                    \         P                  ! 4       pVP                  \        R4       \	        V4      pV P                  RV4       V P                  RV4       R# )zB
C{ReprableComponentized} has a C{__repr__} that lists its cache.
hellorL   N)r   ReprableComponentizedr   rL   reprassertIn)r   rcresults   &  r   test_reprableComponentized-ComponentizedTests.test_reprableComponentized   sE     --/
w'bgv&gv&r   r(   N)r   r   r   r   rh   rf   rs   r}   r   r   r   r   r   r   r   r   r    r!   s   @r   rj   rj   y   sA     96 	?	0	0>	=' 'r   rj   c                   *   a  ] tR t^t o RtR tRtV tR# )AdapterTestszTest adapters.c                    \        4       p\        V4      pV P                  \        P                  \
        V4       V P                  \        VR 4      4       R # r&   )r   r3   assertRaisesr   CannotAdaptrL   r   )r   oas   &  r   testAdapterGetComponent$AdapterTests.testAdapterGetComponent   s>    H!H*00%;%4.)r   r(   N)r   r   r   r   rh   r   r   r    r!   s   @r   r   r      s     * *r   r   c                       ] tR t^tRtR# )IMetar(   NrE   r(   r   r   r   r      rF   r   r   c                   &   a  ] tR t^t o R tRtV tR# )	MetaAdderc                <    V P                   P                  V,           # r&   r7   r   r   s   &&r   addMetaAdder.add       }}  3&&r   r(   Nr   r   r   r   r   r   r    r!   s   @r   r   r           ' 'r   r   c                   &   a  ] tR t^t o R tRtV tR# )BackwardsAdderc                <    V P                   P                  V,
          # r&   r7   r   s   &&r   r   BackwardsAdder.add   r   r   r(   Nr   r!   s   @r   r   r      r   r   r   c                   *   a  ] tR t^t o RtR tRtV tR# )
MetaNumberz1
Integer wrapper for Interface adaptation tests.
c                    Wn         R # r&   r   r   s   &&r   r;   MetaNumber.__init__  s    r   r   N)r   r   r   r   rh   r;   r   r    r!   s   @r   r   r      s      r   r   c                   &   a  ] tR tRt o R tRtV tR# )ComponentNumberi  c                R    ^ V n         \        P                  P                  V 4       R# r5   )r   r   r   r;   r   s   &r   r;   ComponentNumber.__init__	  s      ))$/r   r   NrX   r!   s   @r   r   r     s     0 0r   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )ComponentAdderi  z(
Adder for componentized adapter tests.
c                z    \         P                  P                  W4       V P                  P                  V n        R # r&   )r   Adapterr;   r8   r   r   r8   s   &&r   r;   ComponentAdder.__init__  s'    ##D3==$$r   c                L    V ;P                   V,          un         V P                   # r&   r   r   s   &&r   r   ComponentAdder.add  s    Cxxr   r   N)	r   r   r   r   rh   r;   r   r   r    r!   s   @r   r   r     s     % r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )IAttrXi  z5
Base interface for test of adapter with C{__cmp__}.
c                     R# )z
Return a value.
Nr(   r(   r   r   xIAttrX.x"  r0   r   r(   Nr   r   r   r   rh   r   r   r    r!   s   @r   r   r           r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )IAttrXXi(  z8
Adapted interface for test of adapter with C{__cmp__}.
c                     R# )z
Return a tuple of values.
Nr(   r(   r   r   xx
IAttrXX.xx-  r0   r   r(   N)r   r   r   r   rh   r   r   r    r!   s   @r   r   r   (  r   r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )Xcellenti3  z?
L{IAttrX} implementation for test of adapter with C{__cmp__}.
c                    R# )z#
Return a value.

@return: a value
x!r(   r   s   &r   r   
Xcellent.x9  s     r   r(   Nr   r!   s   @r   r   r   3  s      r   r   c                   :   a  ] tR tRt o Rt^*tR tR tR tRt	V t
R# )DoubleXAdapteriB  z
Adapter with __cmp__.
c                    Wn         R # r&   r8   r   s   &&r   r;   DoubleXAdapter.__init__J  s     r   c                j    V P                   P                  4       V P                   P                  4       3# r&   )r8   r   r   s   &r   r   DoubleXAdapter.xxM  s#    !4==??#455r   c                B    \        V P                  VP                  4      # r&   )r   r   )r   others   &&r   __cmp__DoubleXAdapter.__cmp__P  s    488UYY''r   r   N)r   r   r   r   rh   r   r;   r   r   r   r    r!   s   @r   r   r   B  s%      C!6( (r   r   c                   2   a  ] tR tRt o R tR tR tRtV tR# )MetaInterfaceTestsiT  c                    \         P                  ! \        \        \        4       \        ^4      pV P                  \	        V4      P                  ^4      ^4       R# )zC
Registered adapters can be used to adapt classes to an interface.
N)r   rl   r   r   r   r   r   )r   ns   & r   
test_basicMetaInterfaceTests.test_basicU  s;     	""9j%@qMqa!,r   c                   \         P                  ! \        \        \        4       \        4       p\	        V4      P                  ^4       \	        V4      P                  ^4       V P                  \	        V4      P                  ^4      ^4       R# )r   N)r   rl   r   r   r   r   r   rq   s   & r   testComponentizedInteraction/MetaInterfaceTests.testComponentizedInteraction]  sV    "">?EJaQaQqa!,r   c                    \         P                  ! \        \        \        4       \	        \        4       4      pV P                  RVP                  4       4       R# )r   N)r   r   )r   rl   r   r   r   r   r   r   )r   r   s   & r   testAdapterWithCmp%MetaInterfaceTests.testAdapterWithCmpd  s6    "">67CXZ ruuw/r   r(   N)	r   r   r   r   r   r   r   r   r    r!   s   @r   r   r   T  s     --0 0r   r   c                   ~   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tRtV tR# )RegistrationTestsik  z!
Tests for adapter registration.
c                    R p\         P                  ! W!\        4       V P                  \         P                  ! V\        R4      V4       R# )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                     R # r&   r(   r   s   &r   <lambda>GRegistrationTests._registerAdapterForClassOrInterface.<locals>.<lambda>v      Dr   Nr   rl   rL   r   getAdapterFactoryr   r8   adapters   && r   #_registerAdapterForClassOrInterface5RegistrationTests._registerAdapterForClassOrInterfacep  s6     !""7e<j228UDI7Sr   c                8     ! R R4      pV P                  V4      # )zI
Test that an adapter from a class can be registered and then looked
up.
c                       ] tR tRtRtR# )CRegistrationTests.test_registerAdapterForClass.<locals>.TheOriginali  r(   NrE   r(   r   r   TheOriginalr        r   r  )r  r   r  s   & r   test_registerAdapterForClass.RegistrationTests.test_registerAdapterForClassz  s    	 	 77DDr   c                ,    V P                  \        4      # )zN
Test that an adapter from an interface can be registered and then
looked up.
)r  rN   r   s   &r    test_registerAdapterForInterface2RegistrationTests.test_registerAdapterForInterface  s    
 77??r   c                    R pR p\         P                  ! W!\        4       V P                  \        \         P                  W1\        4       V P                  \         P                  ! V\        R4      V4       R# )z
Verify that L{components.registerAdapter} raises L{ValueError} if the
from-type/interface and to-interface pair is not unique.
c                     R # Fr(   r   s   &r   r   HRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>      r   c                     R # Tr(   r   s   &r   r   r        $r   N)r   rl   rL   r   
ValueErrorr   r  )r   r8   firstAdaptersecondAdapters   &&  r   $_duplicateAdapterForClassOrInterface6RegistrationTests._duplicateAdapterForClassOrInterface  sZ    
 '&""<5A
22MU	
 	j228UDI<Xr   c                8     ! R R4      pV P                  V4      # )zb
Test that attempting to register a second adapter from a class
raises the appropriate exception.
c                       ] tR tRtRtR# )DRegistrationTests.test_duplicateAdapterForClass.<locals>.TheOriginali  r(   NrE   r(   r   r   r  r#    r  r   r  )r  r  s   & r   test_duplicateAdapterForClass/RegistrationTests.test_duplicateAdapterForClass  s    	 	 88EEr   c                ,    V P                  \        4      # )zg
Test that attempting to register a second adapter from an interface
raises the appropriate exception.
)r  rN   r   s   &r   !test_duplicateAdapterForInterface3RegistrationTests.test_duplicateAdapterForInterface  s    
 88@@r   c                   R pR p ! R R\         4      p\        P                  ! W!V4       R\        n         \        P                  ! W1V4       V P	                  \        P
                  ! WR4      V4       R\        n        V P                  \        \        P                  W!V4       V P	                  \        P
                  ! WR4      V4       R#   R\        n        i ; i)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                     R # r  r(   r   s   &r   r   ORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>  r  r   c                     R # r  r(   r   s   &r   r   r+    r  r   c                       ] tR tRtRtR# )SRegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.TheInterfacei  r(   NrE   r(   r   r   TheInterfacer.    r  r   r/  TNF)r   r   rl   ALLOW_DUPLICATESr   r  r   r  )r   r8   r  r  r/  s   &&   r   +_duplicateAdapterForClassOrInterfaceAllowed=RegistrationTests._duplicateAdapterForClassOrInterfaceAllowed  s     '&	9 	 	""<<H&*
#	0&&}MMM,,XTJ
 +0J' 	
22LL	
 	((F	
 +0J's   >C Cc                8     ! R R4      pV P                  V4      # )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                       ] tR tRtRtR# )KRegistrationTests.test_duplicateAdapterForClassAllowed.<locals>.TheOriginali  r(   NrE   r(   r   r   r  r5    r  r   r  )r1  r  s   & r   $test_duplicateAdapterForClassAllowed6RegistrationTests.test_duplicateAdapterForClassAllowed  s    	 	 ??LLr   c                B     ! R R\         4      pV P                  V4      # )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                       ] tR tRtRtR# )ORegistrationTests.test_duplicateAdapterForInterfaceAllowed.<locals>.TheOriginali  r(   NrE   r(   r   r   r  r:    r  r   r  )r   r1  r  s   & r   (test_duplicateAdapterForInterfaceAllowed:RegistrationTests.test_duplicateAdapterForInterfaceAllowed  s!    	) 	 ??LLr   c                    R p\         P                  ! W!\        \        4       V P	                  \         P
                  ! V\        R4      V4       V P	                  \         P
                  ! V\        R4      V4       R# )zP
Verify that an adapter can be registered for multiple to-interfaces at a
time.
c                     R # r&   r(   r   s   &r   r   JRegistrationTests._multipleInterfacesForClassOrInterface.<locals>.<lambda>  r  r   N)r   rl   rL   rN   r   r  r  s   && r   &_multipleInterfacesForClassOrInterface8RegistrationTests._multipleInterfacesForClassOrInterface  sU    
 !""7eVDj228UDI7Sj228VTJGTr   c                8     ! R R4      pV P                  V4      # )zQ
Test the registration of an adapter from a class to several
interfaces at once.
c                       ] tR tRtRtR# )FRegistrationTests.test_multipleInterfacesForClass.<locals>.TheOriginali  r(   NrE   r(   r   r   r  rD    r  r   r  )r@  r  s   & r   test_multipleInterfacesForClass1RegistrationTests.test_multipleInterfacesForClass  s    	 	 ::;GGr   c                ,    V P                  \        4      # )zV
Test the registration of an adapter from an interface to several
interfaces at once.
)r@  rP   r   s   &r   #test_multipleInterfacesForInterface5RegistrationTests.test_multipleInterfacesForInterface  s    
 ::6BBr   c                D   R pR p ! R RV4      p\         P                  ! W!\        4       \         P                  ! W4\        4       V P                  \         P                  ! V\        R4      V4       V P                  \         P                  ! V\        R4      V4       R# )z
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                     R # r  r(   r   s   &r   r   SRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>  s    r   c                     R # r  r(   r   s   &r   r   rL    s    %r   c                       ] tR tRtRtR# )VRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.TheSubclassi
  r(   NrE   r(   r   r   TheSubclassrO  
  r  r   rP  Nr  )r   r8   r  r  rP  s   &&   r   /_subclassAdapterRegistrationForClassOrInterfaceARegistrationTests._subclassAdapterRegistrationForClassOrInterface   sy     &'	( 	 	""<5A""=uEj228UDI<X((eTBM	
r   c                8     ! R R4      pV P                  V4      # )zf
Test that an adapter to a particular interface can be registered
from both a class and its subclass.
c                       ] tR tRtRtR# )ORegistrationTests.test_subclassAdapterRegistrationForClass.<locals>.TheOriginali  r(   NrE   r(   r   r   r  rU    r  r   r  )rQ  r  s   & r   (test_subclassAdapterRegistrationForClass:RegistrationTests.test_subclassAdapterRegistrationForClass  s    	 	 CCKPPr   c                ,    V P                  \        4      # )zk
Test that an adapter to a particular interface can be registered
from both an interface and its subclass.
)rQ  rN   r   s   &r   ,test_subclassAdapterRegistrationForInterface>RegistrationTests.test_subclassAdapterRegistrationForInterface  s    
 CCFKKr   r(   N)r   r   r   r   rh   r  r  r  r  r$  r'  r1  r6  r;  r@  rE  rH  rQ  rV  rY  r   r    r!   s   @r   r   r   k  si     T	E@Y	FA
@
M
MU	HC
(	QL Lr   r   c                   :   a  ] tR tRt o Rt]! R4      tR tRtV t	R# )IProxiedInterfacei'  z5
An interface class for use by L{proxyForInterface}.
z@
        An example declared attribute, which should be proxied.c                     R# )z*
A sample method which should be proxied.
Nr(   )r   kws   *,r   yayIProxiedInterface.yay1  r0   r   r(   N)
r   r   r   r   rh   r   ifaceAttributer_  r   r    r!   s   @r   r\  r\  '  s&      	CN
 r   r\  c                   *   a  ] tR tRt o RtR tRtV tR# )IProxiedSubInterfacei7  zK
An interface that derives from another for use with L{proxyForInterface}.
c                     R# )z4
A different sample method which should be proxied.
Nr(   r(   r   r   booIProxiedSubInterface.boo<  r0   r   r(   Nr   r   r   r   rh   re  r   r    r!   s   @r   rc  rc  7  r   r   rc  c                   0   a  ] tR tRt o RtR tR tRtV tR# )YayableiB  z
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                "    ^ V n         . V n        R# r5   )yaysyayArgsr   s   &r   r;   Yayable.__init__M  s    	r   c                    V ;P                   ^,          un         V P                  P                  W34       V P                   # )z
Increment C{self.yays}.
)rk  rl  appendr   r   r^  s   &*,r   r_  Yayable.yayQ  s/     			Q	QG$yyr   )rl  rk  N)	r   r   r   r   rh   r;   r_  r   r    r!   s   @r   ri  ri  B  s      r   ri  c                   8   a  ] tR tRt o RtRtRtR tR tRt	V t
R# )BooableiZ  z+
An implementation of IProxiedSubInterface
Fc                    RV n         R# )z+
Mark the fact that 'yay' has been called.
TN)yayedrp  s   &*,r   r_  Booable.yaye       
r   c                    RV n         R# )z,
Mark the fact that 'boo' has been called.1
TN)booedr   s   &r   re  Booable.book  rw  r   )ry  ru  N)r   r   r   r   rh   ru  ry  r_  re  r   r    r!   s   @r   rs  rs  Z  s%      EE r   rs  c                   0   a  ] tR tRt o RtR tR tRtV tR# )IMultipleMethodsir  z%
An interface with multiple methods.
c                     R# )z$
The first method. Should return 1.
Nr(   r(   r   r   	methodOneIMultipleMethods.methodOnew  r0   r   c                     R# )z%
The second method. Should return 2.
Nr(   r(   r   r   	methodTwoIMultipleMethods.methodTwo|  r0   r   r(   N	r   r   r   r   rh   r~  r  r   r    r!   s   @r   r|  r|  r  s     
 r   r|  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MultipleMethodImplementori  z2
A precise implementation of L{IMultipleMethods}.
c                    ^# )z
@return: 1
r(   r   s   &r   r~  #MultipleMethodImplementor.methodOne       r   c                    ^# )z
@return: 2
r(   r   s   &r   r  #MultipleMethodImplementor.methodTwo  r  r   r(   Nr  r!   s   @r   r  r    s      r   r  c                   x   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tRtV tR# )ProxyForInterfaceTestsi  z!
Tests for L{proxyForInterface}.
c                |    \        4       p\        \        4      ! V4      pV P                  VP                  V4       R# )zs
Proxy objects should have an C{original} attribute which refers to the
original object passed to the constructor.
N)r   r   r\  r   r8   )r   r8   proxys   &  r   test_original$ProxyForInterfaceTests.test_original  s-    
 8!"34X>ennh/r   c                    \        \        4      p\        4       pV! V4      pVP                  4        V P	                  VP                  4       ^4       V P	                  VP
                  ^4       R# )z~
The class created from L{proxyForInterface} passes methods on an
interface to the object which is passed to its constructor.
Nr   r\  ri  r_  r   rk  )r   klassyayabler  s   &   r   test_proxyMethod'ProxyForInterfaceTests.test_proxyMethod  sR    
 ""34)g		a(q)r   c                   a \        \        4      o ! V3R lRS4      p\        4       pV! V4      pVP                  4        V P	                  ^VP
                  4       R# )zr
Methods of the class created from L{proxyForInterface} can be used with
the decorator-helper L{functools.wraps}.
c                   Z   <a  ] tR tRt o ]!  ZP
                  4      V3R l4       tRtV tR# )?ProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klassi  c                l   < V P                   ;P                  ^,          un        SP                  V 4      # r   )r8   rk  r_  )r   bases   &r   r_  CProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klass.yay  s&    ""a'"xx~%r   r(   N)r   r   r   r   r   r_  r   r    )r"   r  s   @r   r  r    s     488_& &r   r  Nr  )r   r  r8   r  r  s   &   @r   test_decoratedProxyMethod0ProxyForInterfaceTests.test_decoratedProxyMethod  sK    
 !!23	&D 	& 9/HMM*r   c                   a \        4       p\        4       Vn        \        \        4      ! V4      oV P                  SP                  VP                  4       V P                  \        V3R l4       R# )zK
Proxy objects should proxy declared attributes, but not other
attributes.
c                     < S P                   # r&   )rk  )r  s   r   r   <ProxyForInterfaceTests.test_proxyAttribute.<locals>.<lambda>  s	    %**r   N)ri  r   ra  r   r\  r   r   AttributeErrorr   r  r  s   & @r   test_proxyAttribute*ProxyForInterfaceTests.test_proxyAttribute  sQ    
 )!'!"34W=e**G,B,BC.*<=r   c                    \        4       p\        \        4      ! V4      p\        4       pW2n        V P                  VP                  V4       R# )z^
The attributes that proxy objects proxy should be assignable and affect
the original object.
N)ri  r   r\  r   ra  r   r   r  r  thingys   &   r   test_proxySetAttribute-ProxyForInterfaceTests.test_proxySetAttribute  s<    
 )!"34W=%g,,f5r   c                    \        4       pRVn        \        \        4      ! V4      pV=V P	                  \        VR4      4       R# )z]
The attributes that proxy objects proxy should be deletable and affect
the original object.
Nra  )ri  ra  r   r\  assertFalsehasattrr  s   &  r   test_proxyDeleteAttribute0ProxyForInterfaceTests.test_proxyDeleteAttribute  s?    
 )!%!"34W= *:;<r   c                    \        4       p\        \        4      ! V4      pV P                  VP	                  4       ^4       V P                  VP                  4       ^4       R# )zh
[Regression test] The proxy should send its method calls to the correct
method, not the incorrect one.
N)r  r   r|  r   r~  r  )r   multir  s   &  r   test_multipleMethods+ProxyForInterfaceTests.test_multipleMethods  sJ    
 *+!"23E:*A.*A.r   c                     ! R R\        \        4      4      p\        4       pV! V4      pV P                  VP                  ^ 4       VP                  4        V P                  VP                  R4       R# )z@
It is possible to subclass the result of L{proxyForInterface}.
c                   *   a  ] tR tRt o RtR tRtV tR# )AProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxyi  z=
A specialized proxy which can decrement the number of yays.
c                L    V P                   ;P                  ^,          un        R# )z
Decrement the number of yays.
N)r8   rk  r   s   &r   re  EProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxy.boo  s     ""a'"r   r(   Nrg  r!   s   @r   SpecializedProxyr    s     ( (r   r  N)r   r\  ri  r   rk  re  )r   r  r  specials   &   r   test_subclassing'ProxyForInterfaceTests.test_subclassing  sY    
		(01BC 		( )"7+q)r*r   c                \    \        \        4      pV P                  VP                  R4       R# )zA
The name of a proxy class indicates which interface it proxies.
zA(Proxy for twisted.python.test.test_components.IProxiedInterface)N)r   r\  r   r   r   r  s   & r   test_proxyName%ProxyForInterfaceTests.test_proxyName  s'     ""34NNR	
r   c                l    \        \        4      pV P                  \        P                  V4      4       R# )z?
The resulting proxy implements the interface that it proxies.
N)r   r\  
assertTrueimplementedByr  s   & r   test_implements&ProxyForInterfaceTests.test_implements  s'     ""34)77>?r   c                .    ! R R4      pV! 4       pV! 4       pW2n         \        P                  ! RR4      pV P                  VP	                  V4      VP
                  4       VP	                  R4      pV! V4       V P                  VP                  4       R# )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                   *   a  ] tR tRt o RtR tRtV tR# )>ProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.Samplei#  Fc                    R V n         R# )TNcalledr   s   &r   r   DProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.Sample.hello&  s	    "r   r  N)r   r   r   r   r  r   r   r    r!   s   @r   Sampler  #  s     F# #r   r  r   r8   N)r8   r   _ProxyDescriptorr   __get__r   r  r  )r   r  	fakeProxy
testObjectpdfakeClassMethods   &     r   test_proxyDescriptorGet.ProxyForInterfaceTests.test_proxyDescriptorGet  s{    "	# 	# H	X
'((*=I.
0@0@A**T*	"
))*r   c           	       a  ! R R\        \        4      4      o ! V3R lRS4      p\        4       pV! V4      pV P                  VP	                  ^^^^R7      ^4       V P                  VP
                  R\        ^^R7      3.4       R# )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                       ] tR tRtRtRtR# )DProxyForInterfaceTests.test_proxyInheritance.<locals>.YayableWrapperi9  z1
This class does not override any functionality.
r(   N)r   r   r   r   rh   r   r(   r   r   YayableWrapperr  9  s    r   r  c                   6   <a  ] tR tRt o Rt^tV3R ltRtV tR# )EProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapperi>  z(
This class overrides the 'yay' method.
c                p   < V ;P                   ^,          un         SP                  ! V .VO5/ VB ^,           # r   )wrappedYaysr_  )r   r   kr  s   &*,r   r_  IProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapper.yayE  s4      A% %))$88a81<<r   r(   N)	r   r   r   r   rh   r  r_  r   r    )r"   r  s   @r   EnhancedWrapperr  >  s      K= =r   r  )r   yN)      )r   r\  ri  r   r_  rl  dict)r   r  r  wrapperr  s   &   @r   test_proxyInheritance,ProxyForInterfaceTests.test_proxyInheritance2  sx    	./@A 	
		=n 		= )!'*QQ!4a8FD1N+C*DEr   c                    \        \        4      p\        4       pV! V4      pVP                  4        VP	                  4        V P                  VP                  4       V P                  VP                  4       R# )z
Proxies of subinterfaces generated with proxyForInterface should allow
access to attributes of both the child and the base interfaces.
N)r   rc  rs  r_  re  r  ru  ry  )r   
proxyClassbooabler  s   &   r   test_interfaceInheritance0ProxyForInterfaceTests.test_interfaceInheritanceN  sR    
 '';<
)7#				&&r   c                   \        4       p\        4       Vn        \        \        RR7      ! V4      pV P                  VP                  V4       V P                  VP                  4       ^4       V P                  VP                  VP                  4       \        4       pW2n        V P                  VP                  V4       V=V P                  \        VR4      4       R# )z
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)originalAttributera  N)ri  r   ra  r   r\  r   r  r   r_  r  r  r  s   &   r   test_attributeCustomization2ProxyForInterfaceTests.test_attributeCustomization[  s     )!'!"3uMgVeii) 	a(e**G,B,BC%g,,f5 *:;<r   r(   N)r   r   r   r   rh   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r    r!   s   @r   r  r    sX     0
*+$	>	6	=/+,
@+@F8'= =r   r  N);rh   	functoolsr   zope.interfacer   r   r   zope.interface.adapterr   twisted.pythonr   twisted.python.compatr   r	   twisted.python.componentsr
   r   r   twisted.trialr   r   r   r$   r,   r   r3   r@   rD   rH   rJ   rL   rN   rP   rR   rT   rZ   r_   SynchronousTestCaserj   r   r   r   r   r   r   r   r   r   r   r   r   r   r\  rc  ri  rs  r|  r  r  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   