o
    Óó·iâd  ã                   @   s  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
„ d
e
jƒZG dd„ deƒZG dd„ deƒZeeƒG dd„ de
jƒƒZeeƒG dd„ de
jƒƒZG dd„ de
jƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd „ d eƒZ!eee e!ƒG d!d"„ d"e
jƒƒZ"eeƒG d#d$„ d$ƒƒZ#G d%d&„ d&ƒZ$G d'd(„ d(ej%e$ƒZ&G d)d*„ d*ej%ƒZ'G d+d,„ d,eƒZ(ee(ƒG d-d.„ d.e
jƒƒZ)ee(ƒG d/d0„ d0e
jƒƒZ*G d1d2„ d2ƒZ+G d3d4„ d4e
jƒZ,ee(ƒG d5d6„ d6e
jƒƒZ-G d7d8„ d8eƒZ.G d9d:„ d:eƒZ/ee.ƒG d;d<„ d<ƒƒZ0eG d=d>„ d>ƒƒZ1G d?d@„ d@e$ej%ƒZ2G dAdB„ dBe$ej%ƒZ3G dCdD„ dDeƒZ4G dEdF„ dFe4ƒZ5ee4ƒG dGdH„ dHƒƒZ6ee5ƒG dIdJ„ dJƒƒZ7G dKdL„ dLeƒZ8G dMdN„ dNƒZ9G dOdP„ dPej%ƒZ:dQS )Rz0
Test cases for Twisted component architecture.
é    )Úwraps)Ú	AttributeÚ	InterfaceÚimplementer)ÚAdapterRegistry)Ú
components)ÚcmpÚ
comparable)Ú_addHookÚ_removeHookÚproxyForInterface)Úunittestc                   @   ó   e Zd ZdZdd„ ZdS )ÚCompor   c                 C   s   | j d | _ | j S ©Né   ©Únum©Úself© r   úiC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/python/test/test_components.pyÚinc   s   z	Compo.incN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      ó    r   c                   @   ó   e Zd Zdd„ ZdS )ÚIAdeptc                   C   s   t ƒ ‚©N)ÚNotImplementedErrorr   r   r   r   ÚadaptorFunc   s   zIAdept.adaptorFuncN)r   r   r   r!   r   r   r   r   r      ó    r   c                   @   r   )ÚIElapsedc                   C   ó   dS )z
        1!
        Nr   r   r   r   r   ÚelapsedFunc#   ó    zIElapsed.elapsedFuncN©r   r   r   r%   r   r   r   r   r#   "   r"   r#   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚAdeptc                 C   s   || _ d| _d S ©Nr   ©Úoriginalr   ©r   Úorigr   r   r   Ú__init__+   ó   
zAdept.__init__c                 C   s   | j d | _ | j | j ¡ fS r   )r   r+   r   r   r   r   r   r!   /   s   zAdept.adaptorFuncN)r   r   r   r.   r!   r   r   r   r   r(   )   s    r(   c                   @   r   )ÚElapsedc                 C   r$   r   r   r   r   r   r   r%   6   ó   zElapsed.elapsedFuncNr'   r   r   r   r   r0   4   ó    r0   c                   @   ó   e Zd ZdS )ÚACompN©r   r   r   r   r   r   r   r4   :   ó    r4   c                   @   r3   )ÚBCompNr5   r   r   r   r   r7   >   r6   r7   c                   @   r3   )ÚCCompNr5   r   r   r   r   r8   B   r6   r8   c                   @   r3   )ÚITestNr5   r   r   r   r   r9   F   r6   r9   c                   @   r3   )ÚITest2Nr5   r   r   r   r   r:   J   r6   r:   c                   @   r3   )ÚITest3Nr5   r   r   r   r   r;   N   r6   r;   c                   @   r3   )ÚITest4Nr5   r   r   r   r   r<   R   r6   r<   c                   @   r   )ÚTestc                 C   ó   d S r   r   r,   r   r   r   r.   X   r1   zTest.__init__N©r   r   r   r.   r   r   r   r   r=   V   r2   r=   c                   @   r   )ÚTest2r   c                 C   r>   r   r   r,   r   r   r   r.   `   r1   zTest2.__init__N)r   r   r   ZtemporaryAdapterr.   r   r   r   r   r@   \   s    r@   c                   @   r   )ÚRegistryUsingMixinzH
    Mixin for test cases which modify the global registry somehow.
    c                 C   s,   t ƒ }|  td|¡ t|ƒ}|  t|¡ dS )z‹
        Configure L{twisted.python.components.registerAdapter} to mutate an
        alternate registry to improve test isolation.
        ZglobalRegistryN)r   Úpatchr   r
   Z
addCleanupr   )r   ZscratchRegistryÚhookr   r   r   ÚsetUpi   s   zRegistryUsingMixin.setUpN)r   r   r   Ú__doc__rD   r   r   r   r   rA   d   ó    rA   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚComponentizedTestsz8
    Simple test case for caching in Componentized.
    c                 C   s8   t  | ¡ t ttt¡ t ttt¡ t ttt	¡ d S r   )
rA   rD   r   ÚregisterAdapterr=   r4   r9   r;   r@   r:   r   r   r   r   rD   ~   s   
zComponentizedTests.setUpc                 C   sj   t  ttt¡ t  ttt¡ tƒ }| t¡ ¡ dksJ ‚| t¡ ¡ dks'J ‚tt|ƒƒ 	¡ dks3J ‚d S )N)r   r   )é   rI   r   )
r   rH   r(   r   r   r0   r#   ÚgetComponentr!   r%   ©r   Úcr   r   r   ÚtestComponentized…   s   z$ComponentizedTests.testComponentizedc                 C   s€   t ƒ }| t¡}| t¡}| t¡}| t¡}||u sJ ‚||us#J ‚| |¡ | t¡}| t¡}||u s8J ‚||us>J ‚d S r   )r8   rJ   r9   r:   ZremoveComponent)r   rL   Úco1Zco2Úco3Úco4Zco5Zco6r   r   r   ÚtestInheritanceAdaptationŽ   s   






z,ComponentizedTests.testInheritanceAdaptationc                 C   s>   t ƒ }| t¡}| t¡}| t¡}|  |¡ |  ||¡ d S r   )r8   rJ   r9   r;   r<   ÚassertIsNoneÚassertIs)r   rL   rN   rO   rP   r   r   r   ÚtestMultiAdapterœ   s   



z#ComponentizedTests.testMultiAdapterc                 C   sN   t  ¡ }tƒ }|  | t|¡|¡ |  |jt|d�|¡ |  | t¡d¡ dS )z‘
        Test that a default value specified to Componentized.getComponent if
        there is no component for the requested interface.
        )ÚdefaultN)r   ÚComponentizedÚobjectrS   rJ   r9   )r   ÚcomponentizedrU   r   r   r   Útest_getComponentDefaults¤   s
   z,ComponentizedTests.test_getComponentDefaultsc                 C   s<   t  ¡ }| tt¡ | t¡}|  |j|¡ |  |t¡ dS )zŽ
        C{Componentized.setAdapter} sets a component for an interface by
        wrapping the instance with the given adapter class.
        N)	r   rV   Z
setAdapterr   r(   rJ   ÚassertEqualr+   ÚassertIsInstance©r   rX   Ú	componentr   r   r   Útest_setAdapter¯   s
   
z"ComponentizedTests.test_setAdapterc                 C   s>   t  ¡ }|jtdd� | t¡}|  |j|¡ |  |t¡ dS )z˜
        C{Componentized.setAdapter} adapts the instance by wrapping it with
        given adapter class, then stores it using C{addComponent}.
        T)ZignoreClassN)	r   rV   Z
addAdapterr(   rJ   r   rZ   r+   r[   r\   r   r   r   Útest_addAdapterº   s
   
z"ComponentizedTests.test_addAdapterc                 C   s0   t  ¡ }tƒ }| t|¡ |  | t¡|¡ dS )zx
        C{Componentized.setComponent} stores the given component using the
        given interface as the key.
        N)r   rV   rW   ÚsetComponentr9   rS   rJ   ©r   rX   Úobjr   r   r   Útest_setComponentÅ   s   z$ComponentizedTests.test_setComponentc                 C   s8   t  ¡ }tƒ }| t|¡ | t¡ |  | t¡¡ dS )zm
        C{Componentized.setComponent} removes the cached component for the
        given interface.
        N)r   rV   rW   r`   r9   ZunsetComponentrR   rJ   ra   r   r   r   Útest_unsetComponentÏ   s
   
z&ComponentizedTests.test_unsetComponentc                 C   s8   t  ¡ }| td¡ t|ƒ}|  d|¡ |  d|¡ dS )zR
        C{ReprableComponentized} has a C{__repr__} that lists its cache.
        Úhellor9   N)r   ZReprableComponentizedr`   r9   ÚreprZassertIn)r   ÚrcÚresultr   r   r   Útest_reprableComponentizedÚ   s
   z-ComponentizedTests.test_reprableComponentizedN)r   r   r   rE   rD   rM   rQ   rT   rY   r^   r_   rc   rd   ri   r   r   r   r   rG   y   s    	
rG   c                   @   r   )ÚAdapterTestszTest adapters.c                 C   s2   t ƒ }t|ƒ}|  tjt|¡ |  t|d ƒ¡ d S r   )rW   r(   ÚassertRaisesr   ZCannotAdaptr9   rR   )r   ÚoÚar   r   r   ÚtestAdapterGetComponentè   s   z$AdapterTests.testAdapterGetComponentN)r   r   r   rE   rn   r   r   r   r   rj   å   r   rj   c                   @   r3   )ÚIMetaNr5   r   r   r   r   ro   ï   r6   ro   c                   @   r   )Ú	MetaAdderc                 C   s   | j j| S r   r*   ©r   r   r   r   r   Úaddõ   ó   zMetaAdder.addN©r   r   r   rr   r   r   r   r   rp   ó   r2   rp   c                   @   r   )ÚBackwardsAdderc                 C   s   | j j| S r   r*   rq   r   r   r   rr   û   rs   zBackwardsAdder.addNrt   r   r   r   r   ru   ù   r2   ru   c                   @   r   )Ú
MetaNumberz9
    Integer wrapper for Interface adaptation tests.
    c                 C   ó
   || _ d S r   r   rq   r   r   r   r.     ó   
zMetaNumber.__init__N)r   r   r   rE   r.   r   r   r   r   rv   ÿ   rF   rv   c                   @   r   )ÚComponentNumberc                 C   s   d| _ tj | ¡ d S r)   )r   r   rV   r.   r   r   r   r   r.   	  s   zComponentNumber.__init__Nr?   r   r   r   r   ry     r"   ry   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )ÚComponentAdderz0
    Adder for componentized adapter tests.
    c                 C   s   t j | |¡ | jj| _d S r   )r   ÚAdapterr.   r+   r   ©r   r+   r   r   r   r.     s   zComponentAdder.__init__c                 C   s   |  j |7  _ | j S r   r   rq   r   r   r   rr     s   zComponentAdder.addN)r   r   r   rE   r.   rr   r   r   r   r   r{     s    r{   c                   @   r   )ÚIAttrXz=
    Base interface for test of adapter with C{__cmp__}.
    c                   C   r$   )z!
        Return a value.
        Nr   r   r   r   r   Úx"  r&   zIAttrX.xN©r   r   r   rE   r   r   r   r   r   r~     rF   r~   c                   @   r   )ÚIAttrXXz@
    Adapted interface for test of adapter with C{__cmp__}.
    c                   C   r$   )z+
        Return a tuple of values.
        Nr   r   r   r   r   Úxx-  r&   z
IAttrXX.xxN)r   r   r   rE   r‚   r   r   r   r   r�   (  rF   r�   c                   @   r   )ÚXcellentzG
    L{IAttrX} implementation for test of adapter with C{__cmp__}.
    c                 C   r$   )z;
        Return a value.

        @return: a value
        úx!Nr   r   r   r   r   r   9  s   z
Xcellent.xNr€   r   r   r   r   rƒ   3  s    rƒ   c                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚDoubleXAdapterz
    Adapter with __cmp__.
    é*   c                 C   rw   r   )r+   r}   r   r   r   r.   J  rx   zDoubleXAdapter.__init__c                 C   s   | j  ¡ | j  ¡ fS r   )r+   r   r   r   r   r   r‚   M  s   zDoubleXAdapter.xxc                 C   s   t | j|jƒS r   )r   r   )r   Úotherr   r   r   Ú__cmp__P  s   zDoubleXAdapter.__cmp__N)r   r   r   rE   r   r.   r‚   rˆ   r   r   r   r   r…   B  s    r…   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚMetaInterfaceTestsc                 C   s0   t  ttt¡ tdƒ}|  t|ƒ d¡d¡ dS )zS
        Registered adapters can be used to adapt classes to an interface.
        r   rI   N)r   rH   rp   rv   ro   rZ   rr   )r   Únr   r   r   Ú
test_basicU  s   zMetaInterfaceTests.test_basicc                 C   sJ   t  ttt¡ tƒ }t|ƒ d¡ t|ƒ d¡ |  t|ƒ d¡d¡ d S )Nr   é   )r   rH   r{   ry   ro   rr   rZ   rK   r   r   r   ÚtestComponentizedInteraction]  s
   z/MetaInterfaceTests.testComponentizedInteractionc                 C   s,   t  ttt¡ ttƒ ƒ}|  d| ¡ ¡ d S )N)r„   r„   )r   rH   r…   r~   r�   rƒ   rZ   r‚   )r   r‚   r   r   r   ÚtestAdapterWithCmpd  s   
z%MetaInterfaceTests.testAdapterWithCmpN)r   r   r   r‹   r�   rŽ   r   r   r   r   r‰   T  s    r‰   c                   @   sˆ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd S )!ÚRegistrationTestsz)
    Tests for adapter registration.
    c                 C   s0   dd„ }t  ||t¡ |  t  |td¡|¡ dS )zÌ
        Register an adapter with L{components.registerAdapter} for the given
        class or interface and verify that the adapter can be looked up with
        L{components.getAdapterFactory}.
        c                 S   r>   r   r   ©rl   r   r   r   Ú<lambda>v  r&   zGRegistrationTests._registerAdapterForClassOrInterface.<locals>.<lambda>N©r   rH   r9   rS   ÚgetAdapterFactory©r   r+   Úadapterr   r   r   Ú#_registerAdapterForClassOrInterfacep  s   z5RegistrationTests._registerAdapterForClassOrInterfacec                 C   ó   G dd„ dƒ}|   |¡S )za
        Test that an adapter from a class can be registered and then looked
        up.
        c                   @   r3   )zCRegistrationTests.test_registerAdapterForClass.<locals>.TheOriginalNr5   r   r   r   r   ÚTheOriginal€  r6   r˜   N)r–   ©r   r˜   r   r   r   Útest_registerAdapterForClassz  ó   
z.RegistrationTests.test_registerAdapterForClassc                 C   ó
   |   t¡S )zf
        Test that an adapter from an interface can be registered and then
        looked up.
        N)r–   r:   r   r   r   r   Ú test_registerAdapterForInterface…  ó   
z2RegistrationTests.test_registerAdapterForInterfacec                 C   sL   dd„ }dd„ }t  ||t¡ |  tt j||t¡ |  t  |td¡|¡ dS )z˜
        Verify that L{components.registerAdapter} raises L{ValueError} if the
        from-type/interface and to-interface pair is not unique.
        c                 S   r$   ©NFr   r�   r   r   r   r‘   ‘  r&   zHRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>c                 S   r$   ©NTr   r�   r   r   r   r‘   ’  r&   N)r   rH   r9   rk   Ú
ValueErrorrS   r“   )r   r+   ÚfirstAdapterÚsecondAdapterr   r   r   Ú$_duplicateAdapterForClassOrInterfaceŒ  s   ÿz6RegistrationTests._duplicateAdapterForClassOrInterfacec                 C   r—   )zz
        Test that attempting to register a second adapter from a class
        raises the appropriate exception.
        c                   @   r3   )zDRegistrationTests.test_duplicateAdapterForClass.<locals>.TheOriginalNr5   r   r   r   r   r˜      r6   r˜   N)r¤   r™   r   r   r   Útest_duplicateAdapterForClassš  r›   z/RegistrationTests.test_duplicateAdapterForClassc                 C   rœ   )z
        Test that attempting to register a second adapter from an interface
        raises the appropriate exception.
        N)r¤   r:   r   r   r   r   Ú!test_duplicateAdapterForInterface¥  rž   z3RegistrationTests.test_duplicateAdapterForInterfacec                 C   sš   dd„ }dd„ }G dd„ dt ƒ}t |||¡ dt_zt |||¡ |  t ||d¡|¡ W dt_ndt_w |  ttj|||¡ |  t ||d¡|¡ dS )	zÖ
        Verify that when C{components.ALLOW_DUPLICATES} is set to C{True}, new
        adapter registrations for a particular from-type/interface and
        to-interface pair replace older registrations.
        c                 S   r$   rŸ   r   r�   r   r   r   r‘   ²  r&   zORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>c                 S   r$   r    r   r�   r   r   r   r‘   ³  r&   c                   @   r3   )zSRegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.TheInterfaceNr5   r   r   r   r   ÚTheInterfaceµ  r6   r§   TNF)r   r   rH   ZALLOW_DUPLICATESrS   r“   rk   r¡   )r   r+   r¢   r£   r§   r   r   r   Ú+_duplicateAdapterForClassOrInterfaceAllowed¬  s$   þÿÿz=RegistrationTests._duplicateAdapterForClassOrInterfaceAllowedc                 C   r—   )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                   @   r3   )zKRegistrationTests.test_duplicateAdapterForClassAllowed.<locals>.TheOriginalNr5   r   r   r   r   r˜   Ó  r6   r˜   N)r¨   r™   r   r   r   Ú$test_duplicateAdapterForClassAllowedÌ  s   
z6RegistrationTests.test_duplicateAdapterForClassAllowedc                 C   s   G dd„ dt ƒ}|  |¡S )zÂ
        Test that when L{components.ALLOW_DUPLICATES} is set to a true
        value, duplicate registrations from interfaces are allowed to
        override the original registration.
        c                   @   r3   )zORegistrationTests.test_duplicateAdapterForInterfaceAllowed.<locals>.TheOriginalNr5   r   r   r   r   r˜   ß  r6   r˜   N)r   r¨   r™   r   r   r   Ú(test_duplicateAdapterForInterfaceAllowedØ  s   
z:RegistrationTests.test_duplicateAdapterForInterfaceAllowedc                 C   sH   dd„ }t  ||tt¡ |  t  |td¡|¡ |  t  |td¡|¡ dS )zh
        Verify that an adapter can be registered for multiple to-interfaces at a
        time.
        c                 S   r>   r   r   r�   r   r   r   r‘   é  r&   zJRegistrationTests._multipleInterfacesForClassOrInterface.<locals>.<lambda>N)r   rH   r9   r:   rS   r“   r”   r   r   r   Ú&_multipleInterfacesForClassOrInterfaceä  s   z8RegistrationTests._multipleInterfacesForClassOrInterfacec                 C   r—   )zi
        Test the registration of an adapter from a class to several
        interfaces at once.
        c                   @   r3   )zFRegistrationTests.test_multipleInterfacesForClass.<locals>.TheOriginalNr5   r   r   r   r   r˜   ô  r6   r˜   N)r«   r™   r   r   r   Útest_multipleInterfacesForClassî  r›   z1RegistrationTests.test_multipleInterfacesForClassc                 C   rœ   )zn
        Test the registration of an adapter from an interface to several
        interfaces at once.
        N)r«   r;   r   r   r   r   Ú#test_multipleInterfacesForInterfaceù  rž   z5RegistrationTests.test_multipleInterfacesForInterfacec                 C   sl   dd„ }dd„ }G dd„ d|ƒ}t  ||t¡ t  ||t¡ |  t  |td¡|¡ |  t  |td¡|¡ dS )a   
        Verify that a new adapter can be registered for a particular
        to-interface from a subclass of a type or interface which already has an
        adapter registered to that interface and that the subclass adapter takes
        precedence over the base class adapter.
        c                 S   r$   r    r   r�   r   r   r   r‘     r&   zSRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>c                 S   r$   rŸ   r   r�   r   r   r   r‘     r&   c                   @   r3   )zVRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.TheSubclassNr5   r   r   r   r   ÚTheSubclass
  r6   r®   Nr’   )r   r+   r¢   r£   r®   r   r   r   Ú/_subclassAdapterRegistrationForClassOrInterface   s   ÿzARegistrationTests._subclassAdapterRegistrationForClassOrInterfacec                 C   r—   )z~
        Test that an adapter to a particular interface can be registered
        from both a class and its subclass.
        c                   @   r3   )zORegistrationTests.test_subclassAdapterRegistrationForClass.<locals>.TheOriginalNr5   r   r   r   r   r˜     r6   r˜   N)r¯   r™   r   r   r   Ú(test_subclassAdapterRegistrationForClass  r›   z:RegistrationTests.test_subclassAdapterRegistrationForClassc                 C   rœ   )zƒ
        Test that an adapter to a particular interface can be registered
        from both an interface and its subclass.
        N)r¯   r:   r   r   r   r   Ú,test_subclassAdapterRegistrationForInterface  rž   z>RegistrationTests.test_subclassAdapterRegistrationForInterfaceN)r   r   r   rE   r–   rš   r�   r¤   r¥   r¦   r¨   r©   rª   r«   r¬   r­   r¯   r°   r±   r   r   r   r   r�   k  s"    
 
r�   c                   @   s    e Zd ZdZedƒZdd„ ZdS )ÚIProxiedInterfacez=
    An interface class for use by L{proxyForInterface}.
    z@
        An example declared attribute, which should be proxied.c                  O   r$   )z:
        A sample method which should be proxied.
        Nr   )rm   Úkwr   r   r   Úyay1  r&   zIProxiedInterface.yayN)r   r   r   rE   r   ÚifaceAttributer´   r   r   r   r   r²   '  s    ÿr²   c                   @   r   )ÚIProxiedSubInterfacezS
    An interface that derives from another for use with L{proxyForInterface}.
    c                   C   r$   )zD
        A different sample method which should be proxied.
        Nr   r   r   r   r   Úboo<  r&   zIProxiedSubInterface.booN©r   r   r   rE   r·   r   r   r   r   r¶   7  rF   r¶   c                   @   rz   )Ú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                 C   s   d| _ g | _d S r)   )ÚyaysÚyayArgsr   r   r   r   r.   M  r/   zYayable.__init__c                 O   s$   |  j d7  _ | j ||f¡ | j S )z)
        Increment C{self.yays}.
        r   N)rº   r»   Úappend©r   rm   r³   r   r   r   r´   Q  s   zYayable.yayN)r   r   r   rE   r.   r´   r   r   r   r   r¹   B  s    r¹   c                   @   s(   e Zd ZdZdZdZdd„ Zdd„ ZdS )ÚBooablez3
    An implementation of IProxiedSubInterface
    Fc                 O   ó
   d| _ dS )z;
        Mark the fact that 'yay' has been called.
        TN)Úyayedr½   r   r   r   r´   e  ó   
zBooable.yayc                 C   r¿   )z<
        Mark the fact that 'boo' has been called.1
        TN)Úbooedr   r   r   r   r·   k  rÁ   zBooable.booN)r   r   r   rE   rÀ   rÂ   r´   r·   r   r   r   r   r¾   Z  s    r¾   c                   @   rz   )ÚIMultipleMethodsz-
    An interface with multiple methods.
    c                   C   r$   )z4
        The first method. Should return 1.
        Nr   r   r   r   r   Ú	methodOnew  r&   zIMultipleMethods.methodOnec                   C   r$   )z5
        The second method. Should return 2.
        Nr   r   r   r   r   Ú	methodTwo|  r&   zIMultipleMethods.methodTwoN©r   r   r   rE   rÄ   rÅ   r   r   r   r   rÃ   r  s    rÃ   c                   @   rz   )ÚMultipleMethodImplementorz:
    A precise implementation of L{IMultipleMethods}.
    c                 C   r$   )z
        @return: 1
        r   Nr   r   r   r   r   rÄ   ‡  ó   z#MultipleMethodImplementor.methodOnec                 C   r$   )z
        @return: 2
        rI   Nr   r   r   r   r   rÅ   �  rÈ   z#MultipleMethodImplementor.methodTwoNrÆ   r   r   r   r   rÇ   ‚  s    rÇ   c                   @   s€   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚProxyForInterfaceTestsz)
    Tests for L{proxyForInterface}.
    c                 C   s$   t ƒ }ttƒ|ƒ}|  |j|¡ dS )z‹
        Proxy objects should have an C{original} attribute which refers to the
        original object passed to the constructor.
        N)rW   r   r²   rS   r+   )r   r+   Úproxyr   r   r   Útest_original™  s   z$ProxyForInterfaceTests.test_originalc                 C   s@   t tƒ}tƒ }||ƒ}| ¡  |  | ¡ d¡ |  |jd¡ dS )z–
        The class created from L{proxyForInterface} passes methods on an
        interface to the object which is passed to its constructor.
        rI   N©r   r²   r¹   r´   rZ   rº   )r   ÚklassÚyayablerÊ   r   r   r   Útest_proxyMethod¢  s   z'ProxyForInterfaceTests.test_proxyMethodc                    sD   t tƒ‰ G ‡ fdd„dˆ ƒ}tƒ }||ƒ}| ¡  |  d|j¡ dS )zŠ
        Methods of the class created from L{proxyForInterface} can be used with
        the decorator-helper L{functools.wraps}.
        c                       s"   e Zd Ze” jƒ‡ fdd„ƒZdS )z?ProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klassc                    s   | j  jd7  _ˆ  | ¡S r   )r+   rº   r´   r   ©Úbaser   r   r´   ¶  s   
zCProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klass.yayN)r   r   r   r   r´   r   rÐ   r   r   rÍ   µ  s    rÍ   rI   NrÌ   )r   rÍ   r+   rÎ   r   rÐ   r   Útest_decoratedProxyMethod®  s   z0ProxyForInterfaceTests.test_decoratedProxyMethodc                    sB   t ƒ }tƒ |_ttƒ|ƒ‰ |  ˆ j|j¡ |  t‡ fdd„¡ dS )zc
        Proxy objects should proxy declared attributes, but not other
        attributes.
        c                      s   ˆ j S r   )rº   r   ©rÊ   r   r   r‘   É  s    z<ProxyForInterfaceTests.test_proxyAttribute.<locals>.<lambda>N)r¹   rW   rµ   r   r²   rS   rk   ÚAttributeError)r   rÎ   r   rÓ   r   Útest_proxyAttributeÀ  s
   z*ProxyForInterfaceTests.test_proxyAttributec                 C   s0   t ƒ }ttƒ|ƒ}tƒ }||_|  |j|¡ dS )zv
        The attributes that proxy objects proxy should be assignable and affect
        the original object.
        N)r¹   r   r²   rW   rµ   rS   ©r   rÎ   rÊ   Zthingyr   r   r   Útest_proxySetAttributeË  s
   z-ProxyForInterfaceTests.test_proxySetAttributec                 C   s0   t ƒ }d|_ttƒ|ƒ}|`|  t|dƒ¡ dS )zu
        The attributes that proxy objects proxy should be deletable and affect
        the original object.
        Nrµ   )r¹   rµ   r   r²   ÚassertFalseÚhasattr)r   rÎ   rÊ   r   r   r   Útest_proxyDeleteAttributeÖ  s
   z0ProxyForInterfaceTests.test_proxyDeleteAttributec                 C   s6   t ƒ }ttƒ|ƒ}|  | ¡ d¡ |  | ¡ d¡ dS )z€
        [Regression test] The proxy should send its method calls to the correct
        method, not the incorrect one.
        r   rI   N)rÇ   r   rÃ   rZ   rÄ   rÅ   )r   ZmultirÊ   r   r   r   Útest_multipleMethodsá  s   z+ProxyForInterfaceTests.test_multipleMethodsc                 C   sJ   G dd„ dt tƒƒ}tƒ }||ƒ}|  |jd¡ | ¡  |  |jd¡ dS )zP
        It is possible to subclass the result of L{proxyForInterface}.
        c                   @   r   )zAProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxyzU
            A specialized proxy which can decrement the number of yays.
            c                 S   s   | j  jd8  _dS )z?
                Decrement the number of yays.
                r   N)r+   rº   r   r   r   r   r·   õ  s   zEProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxy.booNr¸   r   r   r   r   ÚSpecializedProxyð  rF   rÜ   r   éÿÿÿÿN)r   r²   r¹   rZ   rº   r·   )r   rÜ   rÎ   Zspecialr   r   r   Útest_subclassingë  s   z'ProxyForInterfaceTests.test_subclassingc                 C   s   t tƒ}|  |jd¡ dS )zQ
        The name of a proxy class indicates which interface it proxies.
        zA(Proxy for twisted.python.test.test_components.IProxiedInterface)N)r   r²   rZ   r   ©r   rÊ   r   r   r   Útest_proxyName  s
   þz%ProxyForInterfaceTests.test_proxyNamec                 C   s   t tƒ}|  t |¡¡ dS )zO
        The resulting proxy implements the interface that it proxies.
        N)r   r²   Ú
assertTrueZimplementedByrß   r   r   r   Útest_implements  s   z&ProxyForInterfaceTests.test_implementsc                 C   sb   G dd„ dƒ}|ƒ }|ƒ }||_ t dd¡}|  | |¡|j¡ | d¡}||ƒ |  |j¡ dS )a\  
        _ProxyDescriptor's __get__ method should return the appropriate
        attribute of its argument's 'original' attribute if it is invoked with
        an object.  If it is invoked with None, it should return a false
        class-method emulator instead.

        For some reason, Python's documentation recommends to define
        descriptors' __get__ methods with the 'type' parameter as optional,
        despite the fact that Python itself never actually calls the descriptor
        that way.  This is probably do to support 'foo.__get__(bar)' as an
        idiom.  Let's make sure that the behavior is correct.  Since we don't
        actually use the 'type' argument at all, this test calls it the
        idiomatic way to ensure that signature works; test_proxyInheritance
        verifies the how-Python-actually-calls-it signature.
        c                   @   r   )z>ProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.SampleFc                 S   s
   d| _ d S r    )Úcalledr   r   r   r   re   &  rx   zDProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.Sample.helloN)r   r   r   rã   re   r   r   r   r   ÚSample#  r   rä   re   r+   N)r+   r   Z_ProxyDescriptorrZ   Ú__get__re   rá   rã   )r   rä   Z	fakeProxyZ
testObjectÚpdZfakeClassMethodr   r   r   Útest_proxyDescriptorGet  s   
z.ProxyForInterfaceTests.test_proxyDescriptorGetc                    sp   G dd„ dt tƒƒ‰ G ‡ fdd„dˆ ƒ}tƒ }||ƒ}|  |jddddd	�d
¡ |  |jdtddd	�fg¡ dS )z¿
        Subclasses of the class returned from L{proxyForInterface} should be
        able to upcall methods by reference to their superclass, as any normal
        Python class can.
        c                   @   s   e Zd ZdZdS )zDProxyForInterfaceTests.test_proxyInheritance.<locals>.YayableWrapperzI
            This class does not override any functionality.
            N)r   r   r   rE   r   r   r   r   ÚYayableWrapper9  s    rè   c                       s    e Zd ZdZdZ‡ fdd„ZdS )zEProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapperz@
            This class overrides the 'yay' method.
            r   c                    s*   |  j d7  _ ˆ j| g|¢R i |¤Žd S )Nr   é   )ÚwrappedYaysr´   )r   rm   Úk©rè   r   r   r´   E  s   zIProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapper.yayN)r   r   r   rE   rê   r´   r   rì   r   r   ÚEnhancedWrapper>  s    rí   rŒ   é   é   é   )r   Úyé   )rŒ   rî   N)r   r²   r¹   rZ   r´   r»   Údict)r   rí   rÎ   Úwrapperr   rì   r   Útest_proxyInheritance2  s    z,ProxyForInterfaceTests.test_proxyInheritancec                 C   sB   t tƒ}tƒ }||ƒ}| ¡  | ¡  |  |j¡ |  |j¡ dS )z 
        Proxies of subinterfaces generated with proxyForInterface should allow
        access to attributes of both the child and the base interfaces.
        N)r   r¶   r¾   r´   r·   rá   rÀ   rÂ   )r   Z
proxyClassZbooablerÊ   r   r   r   Útest_interfaceInheritanceN  s   z0ProxyForInterfaceTests.test_interfaceInheritancec                 C   s~   t ƒ }tƒ |_ttdd�|ƒ}|  |j|¡ |  | ¡ d¡ |  |j|j¡ tƒ }||_|  |j|¡ |`|  	t
|dƒ¡ dS )a  
        The original attribute name can be customized via the
        C{originalAttribute} argument of L{proxyForInterface}: the attribute
        should change, but the methods of the original object should still be
        callable, and the attributes still accessible.
        Úfoo)ZoriginalAttributer   rµ   N)r¹   rW   rµ   r   r²   rS   r÷   rZ   r´   rØ   rÙ   rÖ   r   r   r   Útest_attributeCustomization[  s   z2ProxyForInterfaceTests.test_attributeCustomizationN)r   r   r   rE   rË   rÏ   rÒ   rÕ   r×   rÚ   rÛ   rÞ   rà   râ   rç   rõ   rö   rø   r   r   r   r   rÉ   ”  s     	

 rÉ   N);rE   Ú	functoolsr   Zzope.interfacer   r   r   Zzope.interface.adapterr   Ztwisted.pythonr   Ztwisted.python.compatr   r	   Ztwisted.python.componentsr
   r   r   Ztwisted.trialr   rV   r   r   r#   r|   r(   r0   r4   r7   r8   r9   r:   r;   r<   r=   r@   rA   ZSynchronousTestCaserG   rj   ro   rp   ru   rv   ry   r{   r~   r�   rƒ   r…   r‰   r�   r²   r¶   r¹   r¾   rÃ   rÇ   rÉ   r   r   r   r   Ú<module>   sp   

l
	 =