
[XMc           @   sy  d  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
 d e j f d     YZ d e j f d	     YZ d
 e f d     YZ d e f d     YZ d e j f d     YZ d e j f d     YZ e j e e e  e j e e e  d e j f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d  e j f d!     YZ d" dW d#     YZ e j e e e  e j e e e  e j e e e  d$ e j f d%     YZ d& e j f d'     YZ d( e f d)     YZ  d* e j f d+     YZ! d, e j f d-     YZ" d. dX d/     YZ# d0 dY d1     YZ$ d2 dZ d3     YZ% d4 e j f d5     YZ& d6 e j f d7     YZ' d8 e' f d9     YZ( d: e' f d;     YZ) e j e! e# e   e j e( e& e   d< e f d=     YZ* d> e f d?     YZ+ d@ d[ dA     YZ, dB d\ dC     YZ- e j e- e* e+  dD e j f dE     YZ. dF e j f dG     YZ/ dH e f dI     YZ0 dJ e0 f dK     YZ1 dL e2 f dM     YZ3 dN e2 f dO     YZ4 dP e f dQ     YZ5 dR e2 f dS     YZ6 dT e j f dU     YZ7 dV S(]   s0   
Test cases for Twisted component architecture.
i(   t	   Interfacet
   implementst	   Attribute(   t   unittest(   t
   components(   t   proxyForInterfacet   InterfacesTestCasec           B   s   e  Z d  Z RS(   s   Test interfaces.(   t   __name__t
   __module__t   __doc__(    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s   t   Compoc           B   s   e  Z d  Z d   Z RS(   i    c         C   s   |  j  d |  _  |  j  S(   Ni   (   t   num(   t   self(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   inc   s    (   R   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR
      s   t   IAdeptc           B   s   e  Z d    Z RS(   c           C   s   t     d  S(   N(   t   NotImplementedError(    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   adaptorFunc   s    (   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s   t   IElapsedc           B   s   e  Z d    Z RS(   c           C   s   d S(   s   
        1!
        N(    (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   elapsedFunc   s    (   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s   t   Adeptc           B   s$   e  Z e e  d    Z d   Z RS(   c         C   s   | |  _  d |  _ d  S(   Ni    (   t   originalR   (   R   t   orig(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   __init__%   s    	c         C   s&   |  j  d |  _  |  j  |  j j   f S(   Ni   (   R   R   R   (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   (   s    (   R   R   R   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   #   s   
	t   Elapsedc           B   s   e  Z e e  d    Z RS(   c         C   s   d S(   Ni   (    (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   .   s    (   R   R   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   ,   s   
t   ACompc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   4   s   t   BCompc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   6   s   t   CCompc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   8   s   t   ITestc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   ;   s   t   ITest2c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   =   s   t   ITest3c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   ?   s   t   ITest4c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   A   s   t   Testc           B   s!   e  Z e e e e  d    Z RS(   c         C   s   d  S(   N(    (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   E   s    (   R   R   R   R   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   C   s   t   Test2c           B   s!   e  Z e e  d  Z d   Z RS(   i   c         C   s   d  S(   N(    (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   J   s    (   R   R   R   R   t   temporaryAdapterR   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR    G   s   
t   ComponentizedTestCasec           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s3   Simple test case for caching in Componentized.
    c         C   ss   t    } | j t  j   d k s* t  | j t  j   d k sK t  t t |   j   d k so t  d  S(   Ni   i   (   i   i   (   i   i   (   R
   t   getComponentR   R   t   AssertionErrorR   R   (   R   t   c(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   testComponentizedW   s    	!!c         C   s   t    } | j t  } | j t  } | j t  } | j t  } | | k sW t  | | k	 si t  | j |  | j t  } | j t  } | | k s t  | | k	 s t  d  S(   N(   R   R#   R   R   R$   t   removeComponent(   R   R%   t   co1t   co2t   co3t   co4t   co5t   co6(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   testInheritanceAdaptation]   s    	c         C   sm   t    } | j t  } | j t  } | j t  } | j t  } | d  k sW t  | | k si t  d  S(   N(   R   R#   R   R   R   R   t   NoneR$   (   R   R%   R(   R)   R*   R+   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   testMultiAdapterk   s    	c         C   sm   t  j   } t   } |  j | j t |  |  |  j | j t d | |  |  j | j t  d  d S(   s   
        Test that a default value specified to Componentized.getComponent if
        there is no component for the requested interface.
        t   defaultN(   R   t   Componentizedt   objectt   assertIdenticalR#   R   R/   (   R   t   componentizedR1   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_getComponentDefaultsu   s    	(   R   R   R	   R&   R.   R0   R6   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR"   T   s
   			
t   AdapterTestCasec           B   s   e  Z d  Z d   Z RS(   s   Test adapters.c         C   sH   t    } t |  } |  j t j t |  |  j t | d   d   d  S(   N(   R3   R   t   assertRaisesR   t   CannotAdaptR   t   assertEqualsR/   (   R   t   ot   a(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   testAdapterGetComponent   s    	(   R   R   R	   R=   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR7      s   t   IMetac           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR>      s   t	   MetaAdderc           B   s   e  Z e e  d    Z RS(   c         C   s   |  j  j | S(   N(   R   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   add   s    (   R   R   R   R>   R@   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR?      s   
t   BackwardsAdderc           B   s   e  Z e e  d    Z RS(   c         C   s   |  j  j | S(   N(   R   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR@      s    (   R   R   R   R>   R@   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRA      s   
t
   MetaNumberc           B   s   e  Z d    Z RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s    (   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRB      s   t	   FakeAdderc           B   s   e  Z d    Z RS(   c         C   s   | d S(   Ni   (    (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR@      s    (   R   R   R@   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRC      s   t
   FakeNumberc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRD      s   t   ComponentNumberc           B   s   e  Z d    Z RS(   c         C   s   d |  _  t j j |   d  S(   Ni    (   R   R   R2   R   (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s    	(   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRE      s   t   ComponentMetac           B   s   e  Z e e  d    Z RS(   c         C   s&   t  j j |  |  |  j j |  _ d  S(   N(   R   t   AdapterR   R   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s    (   R   R   R   R>   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRF      s   
t   ComponentAdderc           B   s   e  Z d    Z RS(   c         C   s   |  j  | 7_  |  j  S(   N(   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR@      s    (   R   R   R@   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRH      s   t   ComponentDoublerc           B   s   e  Z d    Z RS(   c         C   s   |  j  | d 7_  |  j j  S(   Ni   (   R   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR@      s    (   R   R   R@   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRI      s   t   IAttrXc           B   s   e  Z d    Z RS(   c           C   s   d  S(   N(    (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   x   s    (   R   R   RK   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRJ      s   t   IAttrXXc           B   s   e  Z d    Z RS(   c           C   s   d  S(   N(    (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   xx   s    (   R   R   RM   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRL      s   t   Xcellentc           B   s   e  Z e e  d    Z RS(   c         C   s   d S(   Ns   x!(    (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRK      s    (   R   R   R   RJ   RK   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRN      s   
t   DoubleXAdapterc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   i*   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR      s    c         C   s   |  j  j   |  j  j   f S(   N(   R   RK   (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRM      s    c         C   s   t  |  j | j  S(   N(   t   cmpR   (   R   t   other(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   __cmp__   s    (   R   R   R   R   RM   RR   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRO      s   		t   TestMetaInterfacec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s/   t  d  } |  j t |  j d  d  d  S(   Ni   i   (   RB   R:   R>   R@   (   R   t   n(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt	   testBasic   s    c         C   sR   t    } t |  j d  t |  j d  |  j t |  j d  d  d  S(   Ni   i   (   RE   R>   R@   R:   (   R   R%   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   testComponentizedInteraction   s    	c         C   s)   t  t    } |  j d | j    d  S(   Ns   x!(   s   x!s   x!(   RL   RN   t   assertEqualRM   (   R   RM   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   testAdapterWithCmp   s    (   R   R   RU   RV   RX   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRS      s   		t   RegistrationTestCasec           B   s   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 RS(   s)   
    Tests for adapter registration.
    c         C   sU   d   } d t  f d     Y} t j | | |  |  j t j | | d   |  d  S(   Nc         S   s   d  S(   N(   R/   (   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   <lambda>   s    t   TheInterfacec           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR[      s   (   R    R   t   registerAdapterR4   t   getAdapterFactoryR/   (   R   R   t   adapterR[   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt#   _registerAdapterForClassOrInterface   s    	c         C   s#   d t  f d     Y} |  j |  S(   sa   
        Test that an adapter from a class can be registered and then looked
        up.
        t   TheOriginalc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`      s   (   R3   R_   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_registerAdapterForClass   s    c         C   s#   d t  f d     Y} |  j |  S(   sf   
        Test that an adapter from an interface can be registered and then
        looked up.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`   
  s   (   R    R_   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt    test_registerAdapterForInterface  s    c         C   sz   d   } d   } d t  f d     Y} t j | | |  |  j t t j | | |  |  j t j | | d   |  d  S(   Nc         S   s   t  S(   N(   t   False(   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ     s    c         S   s   t  S(   N(   t   True(   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ     s    R[   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR[     s   (   R    R   R\   R8   t
   ValueErrorR4   R]   R/   (   R   R   t   firstAdaptert   secondAdapterR[   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt$   _duplicateAdapterForClassOrInterface  s    		c         C   s#   d t  f d     Y} |  j |  S(   sz   
        Test that attempting to register a second adapter from a class
        raises the appropriate exception.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`   $  s   (   R3   Rh   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_duplicateAdapterForClass  s    c         C   s#   d t  f d     Y} |  j |  S(   s   
        Test that attempting to register a second adapter from an interface
        raises the appropriate exception.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`   .  s   (   R    Rh   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt!   test_duplicateAdapterForInterface)  s    c         C   s   d   } d   } d t  f d     Y} t j | | |  t t _ z6 t j | | |  |  j t j | | d   |  Wd  t t _ X|  j	 t
 t j | | |  |  j t j | | d   |  d  S(   Nc         S   s   t  S(   N(   Rc   (   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ   4  s    c         S   s   t  S(   N(   Rd   (   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ   5  s    R[   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR[   6  s   (   R    R   R\   Rd   t   ALLOW_DUPLICATESR4   R]   R/   Rc   R8   Re   (   R   R   Rf   Rg   R[   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt+   _duplicateAdapterForClassOrInterfaceAllowed3  s$    			
c         C   s#   d t  f d     Y} |  j |  S(   s   
        Test that when L{components.ALLOW_DUPLICATES} is set to a true
        value, duplicate registrations from classes are allowed to override
        the original registration.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`   R  s   (   R3   Rl   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt$   test_duplicateAdapterForClassAllowedL  s    c         C   s#   d t  f d     Y} |  j |  S(   s   
        Test that when L{components.ALLOW_DUPLICATES} is set to a true
        value, duplicate registrations from interfaces are allowed to
        override the original registration.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`   ]  s   (   R    Rl   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt(   test_duplicateAdapterForInterfaceAllowedW  s    c         C   s   d   } d t  f d     Y} d t  f d     Y} t j | | | |  |  j t j | | d   |  |  j t j | | d   |  d  S(   Nc         S   s   d  S(   N(   R/   (   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ   c  s    t   FirstInterfacec           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRo   d  s   t   SecondInterfacec           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRp   f  s   (   R    R   R\   R4   R]   R/   (   R   R   R^   Ro   Rp   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt&   _multipleInterfacesForClassOrInterfaceb  s    	c         C   s#   d t  f d     Y} |  j |  S(   si   
        Test the registration of an adapter from a class to several
        interfaces at once.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`   v  s   (   R3   Rq   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_multipleInterfacesForClassq  s    c         C   s#   d t  f d     Y} |  j |  S(   sn   
        Test the registration of an adapter from an interface to several
        interfaces at once.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`     s   (   R    Rq   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt#   test_multipleInterfacesForInterface{  s    c         C   s   d   } d   } d | f d     Y} d t  f d     Y} t j | | |  t j | | |  |  j t j | | d   |  |  j t j | | d   |  d  S(   Nc         S   s   t  S(   N(   Rd   (   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ     s    c         S   s   t  S(   N(   Rc   (   R;   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ     s    t   TheSubclassc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRt     s   R[   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR[     s   (   R    R   R\   R4   R]   R/   (   R   R   Rf   Rg   Rt   R[   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt/   _subclassAdapterRegistrationForClassOrInterface  s    		c         C   s#   d t  f d     Y} |  j |  S(   s~   
        Test that an adapter to a particular interface can be registered
        from both a class and its subclass.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`     s   (   R3   Ru   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt(   test_subclassAdapterRegistrationForClass  s    c         C   s#   d t  f d     Y} |  j |  S(   s   
        Test that an adapter to a particular interface can be registered
        from both an interface and its subclass.
        R`   c           B   s   e  Z RS(    (   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR`     s   (   R    Ru   (   R   R`   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt,   test_subclassAdapterRegistrationForInterface  s    (   R   R   R	   R_   Ra   Rb   Rh   Ri   Rj   Rl   Rm   Rn   Rq   Rr   Rs   Ru   Rv   Rw   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRY      s    	
	
	
		
	
					
	
		
t   IProxiedInterfacec           B   s#   e  Z d  Z e d  Z d   Z RS(   s=   
    An interface class for use by L{proxyForInterface}.
    s@   
        An example declared attribute, which should be proxied.c          O   s   d S(   s:   
        A sample method which should be proxied.
        N(    (   R<   t   kw(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   yay  s    (   R   R   R	   R   t   ifaceAttributeRz   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRx     s   	t   IProxiedSubInterfacec           B   s   e  Z d  Z d   Z RS(   sS   
    An interface that derives from another for use with L{proxyForInterface}.
    c         C   s   d S(   sD   
        A different sample method which should be proxied.
        N(    (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   boo  s    (   R   R   R	   R}   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR|     s   t   Yayablec           B   s*   e  Z d  Z e e  d   Z d   Z RS(   s   
    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         C   s   d |  _  g  |  _ d  S(   Ni    (   t   yayst   yayArgs(   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s    	c         O   s,   |  j  d 7_  |  j j | | f  |  j  S(   s)   
        Increment C{self.yays}.
        i   (   R   R   t   append(   R   R<   Ry   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRz     s    (   R   R   R	   R   Rx   R   Rz   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR~     s   
	t   Booablec           B   s6   e  Z d  Z e e  e Z e Z d   Z d   Z	 RS(   s3   
    An implementation of IProxiedSubInterface
    c         C   s   t  |  _ d S(   s;   
        Mark the fact that 'yay' has been called.
        N(   Rd   t   yayed(   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRz     s    c         C   s   t  |  _ d S(   s<   
        Mark the fact that 'boo' has been called.1
        N(   Rd   t   booed(   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR}     s    (
   R   R   R	   R   R|   Rc   R   R   Rz   R}   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   
	t   IMultipleMethodsc           B   s    e  Z d  Z d   Z d   Z RS(   s-   
    An interface with multiple methods.
    c           C   s   d S(   s4   
        The first method. Should return 1.
        N(    (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt	   methodOne  s    c           C   s   d S(   s5   
        The second method. Should return 2.
        N(    (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt	   methodTwo  s    (   R   R   R	   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   	t   MultipleMethodImplementorc           B   s    e  Z d  Z d   Z d   Z RS(   s:   
    A precise implementation of L{IMultipleMethods}.
    c         C   s   d S(   s   
        @return: 1
        i   (    (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s    c         C   s   d S(   s   
        @return: 2
        i   (    (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s    (   R   R   R	   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   	t   ProxyForInterfaceTestsc           B   s   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 RS(   s)   
    Tests for L{proxyForInterface}.
    c         C   s2   t    } t t  |  } |  j | j |  d S(   s   
        Proxy objects should have an C{original} attribute which refers to the
        original object passed to the constructor.
        N(   R3   R   Rx   R4   R   (   R   R   t   proxy(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_original  s    	c         C   sX   t  t  } t   } | |  } | j   |  j | j   d  |  j | j d  d S(   s   
        The class created from L{proxyForInterface} passes methods on an
        interface to the object which is passed to its constructor.
        i   N(   R   Rx   R~   Rz   R:   R   (   R   t   klasst   yayableR   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxyMethod$  s    	
c            sZ   t    } t   | _ t t  |    |  j   j | j  |  j t   f d    d S(   sc   
        Proxy objects should proxy declared attributes, but not other
        attributes.
        c              s     j  S(   N(   R   (    (   R   (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRZ   :  s    N(   R~   R3   R{   R   Rx   R4   R8   t   AttributeError(   R   R   (    (   R   sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxyAttribute1  s
    	c         C   sD   t    } t t  |  } t   } | | _ |  j | j |  d S(   sv   
        The attributes that proxy objects proxy should be assignable and affect
        the original object.
        N(   R~   R   Rx   R3   R{   R4   (   R   R   R   t   thingy(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxySetAttribute=  s
    			c         C   sD   t    } d | _ t t  |  } | ` |  j t | d   d S(   su   
        The attributes that proxy objects proxy should be deletable and affect
        the original object.
        R{   N(   R~   R/   R{   R   Rx   t   assertFalset   hasattr(   R   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxyDeleteAttributeI  s
    		c         C   sK   t    } t t  |  } |  j | j   d  |  j | j   d  d S(   s   
        [Regression test] The proxy should send its method calls to the correct
        method, not the incorrect one.
        i   i   N(   R   R   R   R:   R   R   (   R   t   multiR   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_multipleMethodsU  s    	c         C   se   d t  t  f d     Y} t   } | |  } |  j | j d  | j   |  j | j d  d S(   sP   
        It is possible to subclass the result of L{proxyForInterface}.
        t   SpecializedProxyc           B   s   e  Z d  Z d   Z RS(   sU   
            A specialized proxy which can decrement the number of yays.
            c         S   s   |  j  j d 8_ d S(   s?   
                Decrement the number of yays.
                i   N(   R   R   (   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR}   i  s    (   R   R   R	   R}   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR   e  s   i    iN(   R   Rx   R~   R:   R   R}   (   R   R   R   t   special(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_subclassing`  s    
	
c         C   s#   t  t  } |  j | j d  d S(   sQ   
        The name of a proxy class indicates which interface it proxies.
        sA   (Proxy for twisted.python.test.test_components.IProxiedInterface)N(   R   Rx   R:   R   (   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxyNamev  s    c         C   s&   t  t  } |  j t j |   d S(   sO   
        The resulting proxy implements the interface that it proxies.
        N(   R   Rx   t
   assertTruet   implementedBy(   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_implements  s    c         C   s   d d d     Y} |   } |   } | | _  t j d d  } |  j | j |  | j  | j d  } | |  |  j | j  d S(   s\  
        _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.
        t   Samplec           B   s   e  Z e Z d    Z RS(   c         S   s   t  |  _ d  S(   N(   Rd   t   called(   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   hello  s    (   R   R   Rc   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   R   R   N(    (	   R   R   t   _ProxyDescriptorR:   t   __get__R   R/   t
   failUnlessR   (   R   R   t	   fakeProxyt
   testObjectt   pdt   fakeClassMethod(    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxyDescriptorGet  s    			
c            s   d t  t  f d     Y  d   f   f d     Y} t   } | |  } |  j | j d d d d d	 d
 d  |  j | j d t d d d	 d
  f g  d S(   s   
        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.
        t   YayableWrapperc           B   s   e  Z d  Z RS(   sI   
            This class does not override any functionality.
            (   R   R   R	   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   t   EnhancedWrapperc              s#   e  Z d  Z d Z   f d   Z RS(   s@   
            This class overrides the 'yay' method.
            i   c            s&   |  j  d 7_    j |  | |  d S(   Ni   i   (   t   wrappedYaysRz   (   R   R<   t   k(   R   (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyRz     s    (   R   R   R	   R   Rz   (    (   R   (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   i   i   RK   i   t   yi   i   N(   i   i   (   R   Rx   R~   R:   Rz   R   t   dict(   R   R   R   t   wrapper(    (   R   sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_proxyInheritance  s    		(c         C   sY   t  t  } t   } | |  } | j   | j   |  j | j  |  j | j  d S(   s   
        Proxies of subinterfaces generated with proxyForInterface should allow
        access to attributes of both the child and the base interfaces.
        N(   R   R|   R   Rz   R}   R   R   R   (   R   t
   proxyClasst   booableR   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_interfaceInheritance  s    	

c         C   s   t    } t   | _ t t d d |  } |  j | j |  |  j | j   d  |  j | j | j  t   } | | _ |  j | j |  | ` |  j	 t
 | d   d S(   s  
        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.
        t   originalAttributet   fooi   R{   N(   R~   R3   R{   R   Rx   R4   R   R:   Rz   R   R   (   R   R   R   R   (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   test_attributeCustomization  s    			(   R   R   R	   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyR     s   	
											N(    (    (    (    (    (    (8   R	   t   zope.interfaceR    R   R   t   twisted.trialR   t   twisted.pythonR   t   twisted.python.componentsR   t   TestCaseR   R2   R
   R   R   RG   R   R   R\   R   R   R   R   R   R   R   R   R    R"   R7   R>   R?   RA   RB   RC   RD   RE   RF   RH   RI   RJ   RL   RN   RO   RS   RY   Rx   R|   R3   R~   R   R   R   R   (    (    (    sG   /usr/lib/python2.7/dist-packages/twisted/python/test/test_components.pyt   <module>   sh   	4	