HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_components.cpython-38.pyc
U


W[ve�@s:dZddlmZmZddlmZddlmZmZm	Z	ddl
mZddlm
Z
mZddlmZddlmZdd	lmZmZmZGd
d�dej�ZGdd
�d
e�ZGdd�de�Zee�Gdd�dej��Zee�Gdd�dej��ZGdd�dej�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#Gd d!�d!e�Z$ee!e#e$�Gd"d#�d#ej��Z%ee"�Gd$d%�d%e&��Z'Gd&d'�d'e&�Z(Gd(d)�d)ej)e(�Z*Gd*d+�d+ej)�Z+Gd,d-�d-e�Z,ee,�Gd.d/�d/ej��Z-ee,�Gd0d1�d1ej��Z.Gd2d3�d3e&�Z/Gd4d5�d5ej�Z0ee,�Gd6d7�d7ej��Z1Gd8d9�d9e�Z2Gd:d;�d;e�Z3ee2�Gd<d=�d=e&��Z4e
Gd>d?�d?e&��Z5Gd@dA�dAe(ej)�Z6GdBdC�dCe(ej)�Z7GdDdE�dEe�Z8GdFdG�dGe8�Z9ee8�GdHdI�dIe&��Z:ee9�GdJdK�dKe&��Z;GdLdM�dMe�Z<GdNdO�dOe&�Z=GdPdQ�dQej)�Z>dRS)Sz0
Test cases for Twisted component architecture.
�)�division�absolute_import)�wraps)�	Interface�implementer�	Attribute)�AdapterRegistry)�
comparable�cmp)�unittest)�
components)�_addHook�_removeHook�proxyForInterfacec@seZdZdZdd�ZdS)�ComporcCs|jd|_|jS�N���num��self�r�E/usr/lib/python3/dist-packages/twisted/python/test/test_components.py�incsz	Compo.incN)�__name__�
__module__�__qualname__rrrrrrrsrc@seZdZdd�ZdS)�IAdeptcCs
t��dS�N)�NotImplementedErrorrrrr�adaptorFuncszIAdept.adaptorFuncN)rrrr rrrrrsrc@seZdZdd�ZdS)�IElapsedcCsdS)z
        1!
        Nrrrrr�elapsedFunc!szIElapsed.elapsedFuncN�rrrr"rrrrr! sr!c@seZdZdd�Zdd�ZdS)�AdeptcCs||_d|_dS�Nr��originalr�rZorigrrr�__init__(szAdept.__init__cCs|jd|_|j|j��fSr)rr'rrrrrr +szAdept.adaptorFuncN)rrrr)r rrrrr$&sr$c@seZdZdd�ZdS)�ElapsedcCsdSrrrrrrr"1szElapsed.elapsedFuncNr#rrrrr*/sr*c@seZdZdS)�ACompN�rrrrrrrr+4sr+c@seZdZdS)�BCompNr,rrrrr-6sr-c@seZdZdS)�CCompNr,rrrrr.8sr.c@seZdZdS)�ITestNr,rrrrr/;sr/c@seZdZdS)�ITest2Nr,rrrrr0?sr0c@seZdZdS)�ITest3Nr,rrrrr1Csr1c@seZdZdS)�ITest4Nr,rrrrr2Gsr2c@seZdZdd�ZdS)�TestcCsdSrrr(rrrr)Msz
Test.__init__N�rrrr)rrrrr3Ksr3c@seZdZdZdd�ZdS)�Test2rcCsdSrrr(rrrr)TszTest2.__init__N)rrrZtemporaryAdapterr)rrrrr5Qsr5c@seZdZdZdd�ZdS)�RegistryUsingMixinzH
    Mixin for test cases which modify the global registry somehow.
    cCs,t�}|�td|�t|�}|�t|�dS)z�
        Configure L{twisted.python.components.registerAdapter} to mutate an
        alternate registry to improve test isolation.
        ZglobalRegistryN)rZpatchrr
Z
addCleanupr)rZscratchRegistry�hookrrr�setUp]szRegistryUsingMixin.setUpN)rrr�__doc__r8rrrrr6Ysr6c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�ComponentizedTestsz8
    Simple test case for caching in Componentized.
    cCs8t�|�t�ttt�t�ttt�t�ttt	�dSr)
r6r8r�registerAdapterr3r+r/r1r5r0rrrrr8rs
zComponentizedTests.setUpcCsjt�ttt�t�ttt�t�}|�t���dks8t	�|�t���dksNt	�tt|���
�dksft	�dS)N)rr)�r<r)rr;r$rrr*r!�getComponentr �AssertionErrorr"�r�crrr�testComponentizedzsz$ComponentizedTests.testComponentizedcCs�t�}|�t�}|�t�}|�t�}|�t�}||ks:t�||k	sFt�|�|�|�t�}|�t�}||kspt�||k	s|t�dSr)r.r=r/r0r>ZremoveComponent)rr@�co1Zco2�co3�co4Zco5Zco6rrr�testInheritanceAdaptation�s






z,ComponentizedTests.testInheritanceAdaptationcCs>t�}|�t�}|�t�}|�t�}|�|�|�||�dSr)r.r=r/r1r2�assertIsNone�assertIs)rr@rBrCrDrrr�testMultiAdapter�s



z#ComponentizedTests.testMultiAdaptercCsNt��}t�}|�|�t|�|�|�|jt|d�|�|�|�t�d�dS)z�
        Test that a default value specified to Componentized.getComponent if
        there is no component for the requested interface.
        )�defaultN)r�
Componentized�objectrGr=r/)r�
componentizedrIrrr�test_getComponentDefaults�s
���z,ComponentizedTests.test_getComponentDefaultscCs<t��}|�tt�|�t�}|�|j|�|�|t�dS)z�
        C{Componentized.setAdapter} sets a component for an interface by
        wrapping the instance with the given adapter class.
        N)	rrJZ
setAdapterrr$r=�assertEqualr'�assertIsInstance�rrLZ	componentrrr�test_setAdapter�s

z"ComponentizedTests.test_setAdaptercCs>t��}|jtdd�|�t�}|�|j|�|�|t�dS)z�
        C{Componentized.setAdapter} adapts the instance by wrapping it with
        given adapter class, then stores it using C{addComponent}.
        T)ZignoreClassN)	rrJZ
addAdapterr$r=rrNr'rOrPrrr�test_addAdapter�s

z"ComponentizedTests.test_addAdaptercCs0t��}t�}|�t|�|�|�t�|�dS)zx
        C{Componentized.setComponent} stores the given component using the
        given interface as the key.
        N)rrJrK�setComponentr/rGr=�rrL�objrrr�test_setComponent�sz$ComponentizedTests.test_setComponentcCs8t��}t�}|�t|�|�t�|�|�t��dS)zm
        C{Componentized.setComponent} removes the cached component for the
        given interface.
        N)rrJrKrSr/ZunsetComponentrFr=rTrrr�test_unsetComponent�s

z&ComponentizedTests.test_unsetComponentcCs8t��}|�td�t|�}|�d|�|�d|�dS)zR
        C{ReprableComponentized} has a C{__repr__} that lists its cache.
        �hellor/N)rZReprableComponentizedrSr/�reprZassertIn)rZrc�resultrrr�test_reprableComponentized�s
z-ComponentizedTests.test_reprableComponentizedN)rrrr9r8rArErHrMrQrRrVrWr[rrrrr:ns		r:c@seZdZdZdd�ZdS)�AdapterTestszTest adapters.cCs2t�}t|�}|�tjt|�|�t|d��dSr)rKr$�assertRaisesrZCannotAdaptr/rF)r�o�arrr�testAdapterGetComponent�sz$AdapterTests.testAdapterGetComponentN)rrrr9r`rrrrr\�sr\c@seZdZdS)�IMetaNr,rrrrra�srac@seZdZdd�ZdS)�	MetaAddercCs|jj|Srr&�rrrrr�add�sz
MetaAdder.addN�rrrrdrrrrrb�srbc@seZdZdd�ZdS)�BackwardsAddercCs|jj|Srr&rcrrrrdszBackwardsAdder.addNrerrrrrf�srfc@seZdZdZdd�ZdS)�
MetaNumberz9
    Integer wrapper for Interface adaptation tests.
    cCs
||_dSrrrcrrrr)	szMetaNumber.__init__N)rrrr9r)rrrrrgsrgc@seZdZdd�ZdS)�ComponentNumbercCsd|_tj�|�dSr%)rrrJr)rrrrr)szComponentNumber.__init__Nr4rrrrrhsrhc@s eZdZdZdd�Zdd�ZdS)�ComponentAdderz0
    Adder for componentized adapter tests.
    cCstj�||�|jj|_dSr)r�Adapterr)r'r�rr'rrrr)szComponentAdder.__init__cCs|j|7_|jSrrrcrrrrdszComponentAdder.addN)rrrr9r)rdrrrrrisric@seZdZdZdd�ZdS)�IAttrXz=
    Base interface for test of adapter with C{__cmp__}.
    cCsdS)z!
        Return a value.
        Nrrrrr�x)szIAttrX.xN�rrrr9rmrrrrrl%srlc@seZdZdZdd�ZdS)�IAttrXXz@
    Adapted interface for test of adapter with C{__cmp__}.
    cCsdS)z+
        Return a tuple of values.
        Nrrrrr�xx4sz
IAttrXX.xxN)rrrr9rprrrrro0sroc@seZdZdZdd�ZdS)�XcellentzG
    L{IAttrX} implementation for test of adapter with C{__cmp__}.
    cCsdS)z;
        Return a value.

        @return: a value
        �x!rrrrrrm@sz
Xcellent.xNrnrrrrrq;srqc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�DoubleXAdapterz
    Adapter with __cmp__.
    �*cCs
||_dSr)r'rkrrrr)PszDoubleXAdapter.__init__cCs|j��|j��fSr)r'rmrrrrrpTszDoubleXAdapter.xxcCst|j|j�Sr)r
r)r�otherrrr�__cmp__XszDoubleXAdapter.__cmp__N)rrrr9rr)rprvrrrrrsJs
rsc@s$eZdZdd�Zdd�Zdd�ZdS)�MetaInterfaceTestscCs0t�ttt�td�}|�t|��d�d�dS)zS
        Registered adapters can be used to adapt classes to an interface.
        rr<N)rr;rbrgrarNrd)r�nrrr�
test_basic^szMetaInterfaceTests.test_basiccCsJt�ttt�t�}t|��d�t|��d�|�t|��d�d�dS)Nr�)rr;rirhrardrNr?rrr�testComponentizedInteractionfs
z/MetaInterfaceTests.testComponentizedInteractioncCs,t�ttt�tt��}|�d|���dS)N)rrrr)rr;rsrlrorqrNrp)rrprrr�testAdapterWithCmpms
z%MetaInterfaceTests.testAdapterWithCmpN)rrrryr{r|rrrrrw]srwc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�RegistrationTestsz)
    Tests for adapter registration.
    cCs0dd�}t�||t�|�t�|td�|�dS)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}.
        cSsdSrr�r^rrr�<lambda>~�zGRegistrationTests._registerAdapterForClassOrInterface.<locals>.<lambda>N�rr;r/rG�getAdapterFactory�rr'Zadapterrrr�#_registerAdapterForClassOrInterfacexs�z5RegistrationTests._registerAdapterForClassOrInterfacecCsGdd�dt�}|�|�S)za
        Test that an adapter from a class can be registered and then looked
        up.
        c@seZdZdS)zCRegistrationTests.test_registerAdapterForClass.<locals>.TheOriginalNr,rrrr�TheOriginal�sr�)rKr��rr�rrr�test_registerAdapterForClass�sz.RegistrationTests.test_registerAdapterForClasscCs
|�t�S)zf
        Test that an adapter from an interface can be registered and then
        looked up.
        )r�r0rrrr� test_registerAdapterForInterface�sz2RegistrationTests.test_registerAdapterForInterfacecCsLdd�}dd�}t�||t�|�ttj||t�|�t�|td�|�dS)z�
        Verify that L{components.registerAdapter} raises L{ValueError} if the
        from-type/interface and to-interface pair is not unique.
        cSsdS�NFrr~rrrr�r�zHRegistrationTests._duplicateAdapterForClassOrInterface.<locals>.<lambda>cSsdS�NTrr~rrrr�r�N)rr;r/r]�
ValueErrorrGr�)rr'�firstAdapter�
secondAdapterrrr�$_duplicateAdapterForClassOrInterface�s��z6RegistrationTests._duplicateAdapterForClassOrInterfacecCsGdd�dt�}|�|�S)zz
        Test that attempting to register a second adapter from a class
        raises the appropriate exception.
        c@seZdZdS)zDRegistrationTests.test_duplicateAdapterForClass.<locals>.TheOriginalNr,rrrrr��sr�)rKr�r�rrr�test_duplicateAdapterForClass�sz/RegistrationTests.test_duplicateAdapterForClasscCs
|�t�S)z
        Test that attempting to register a second adapter from an interface
        raises the appropriate exception.
        )r�r0rrrr�!test_duplicateAdapterForInterface�sz3RegistrationTests.test_duplicateAdapterForInterfacecCs�dd�}dd�}Gdd�dt�}t�|||�dt_z(t�|||�|�t�||d�|�W5dt_X|�ttj|||�|�t�||d�|�dS)	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.
        cSsdSr�rr~rrrr�r�zORegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.<lambda>cSsdSr�rr~rrrr�r�c@seZdZdS)zSRegistrationTests._duplicateAdapterForClassOrInterfaceAllowed.<locals>.TheInterfaceNr,rrrr�TheInterface�sr�TFN)rrr;ZALLOW_DUPLICATESrGr�r]r�)rr'r�r�r�rrr�+_duplicateAdapterForClassOrInterfaceAllowed�s.���z=RegistrationTests._duplicateAdapterForClassOrInterfaceAllowedcCsGdd�dt�}|�|�S)z�
        Test that when L{components.ALLOW_DUPLICATES} is set to a true
        value, duplicate registrations from classes are allowed to override
        the original registration.
        c@seZdZdS)zKRegistrationTests.test_duplicateAdapterForClassAllowed.<locals>.TheOriginalNr,rrrrr��sr�)rKr�r�rrr�$test_duplicateAdapterForClassAllowed�sz6RegistrationTests.test_duplicateAdapterForClassAllowedcCsGdd�dt�}|�|�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@seZdZdS)zORegistrationTests.test_duplicateAdapterForInterfaceAllowed.<locals>.TheOriginalNr,rrrrr��sr�)rr�r�rrr�(test_duplicateAdapterForInterfaceAllowed�sz:RegistrationTests.test_duplicateAdapterForInterfaceAllowedcCsHdd�}t�||tt�|�t�|td�|�|�t�|td�|�dS)zh
        Verify that an adapter can be registered for multiple to-interfaces at a
        time.
        cSsdSrrr~rrrr�r�zJRegistrationTests._multipleInterfacesForClassOrInterface.<locals>.<lambda>N)rr;r/r0rGr�r�rrr�&_multipleInterfacesForClassOrInterface�s��z8RegistrationTests._multipleInterfacesForClassOrInterfacecCsGdd�dt�}|�|�S)zi
        Test the registration of an adapter from a class to several
        interfaces at once.
        c@seZdZdS)zFRegistrationTests.test_multipleInterfacesForClass.<locals>.TheOriginalNr,rrrrr�sr�)rKr�r�rrr�test_multipleInterfacesForClass�sz1RegistrationTests.test_multipleInterfacesForClasscCs
|�t�S)zn
        Test the registration of an adapter from an interface to several
        interfaces at once.
        )r�r1rrrr�#test_multipleInterfacesForInterfacesz5RegistrationTests.test_multipleInterfacesForInterfacecCsldd�}dd�}Gdd�d|�}t�||t�t�||t�|�t�|td�|�|�t�|td�|�dS)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.
        cSsdSr�rr~rrrrr�zSRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.<lambda>cSsdSr�rr~rrrrr�c@seZdZdS)zVRegistrationTests._subclassAdapterRegistrationForClassOrInterface.<locals>.TheSubclassNr,rrrr�TheSubclasssr�Nr�)rr'r�r�r�rrr�/_subclassAdapterRegistrationForClassOrInterfaces��zARegistrationTests._subclassAdapterRegistrationForClassOrInterfacecCsGdd�dt�}|�|�S)z~
        Test that an adapter to a particular interface can be registered
        from both a class and its subclass.
        c@seZdZdS)zORegistrationTests.test_subclassAdapterRegistrationForClass.<locals>.TheOriginalNr,rrrrr�)sr�)rKr�r�rrr�(test_subclassAdapterRegistrationForClass$sz:RegistrationTests.test_subclassAdapterRegistrationForClasscCs
|�t�S)z�
        Test that an adapter to a particular interface can be registered
        from both an interface and its subclass.
        )r�r0rrrr�,test_subclassAdapterRegistrationForInterface.sz>RegistrationTests.test_subclassAdapterRegistrationForInterfaceN)rrrr9r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr}ts 





r}c@s eZdZdZed�Zdd�ZdS)�IProxiedInterfacez=
    An interface class for use by L{proxyForInterface}.
    z@
        An example declared attribute, which should be proxied.cOsdS)z:
        A sample method which should be proxied.
        Nr)r_�kwrrr�yay?szIProxiedInterface.yayN)rrrr9r�ifaceAttributer�rrrrr�7sr�c@seZdZdZdd�ZdS)�IProxiedSubInterfacezS
    An interface that derives from another for use with L{proxyForInterface}.
    cCsdS)zD
        A different sample method which should be proxied.
        Nrrrrr�booIszIProxiedSubInterface.booN�rrrr9r�rrrrr�Dsr�c@s eZdZdZdd�Zdd�ZdS)�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.
    cCsd|_g|_dSr%)�yays�yayArgsrrrrr)XszYayable.__init__cOs$|jd7_|j�||f�|jS)z)
        Increment C{self.yays}.
        r)r�r��append)rr_r�rrrr�\szYayable.yayN)rrrr9r)r�rrrrr�Osr�c@s(eZdZdZdZdZdd�Zdd�ZdS)�Booablez3
    An implementation of IProxiedSubInterface
    FcCs
d|_dS)z;
        Mark the fact that 'yay' has been called.
        TN)�yayedrrrrr�mszBooable.yaycCs
d|_dS)z<
        Mark the fact that 'boo' has been called.1
        TN)�booedrrrrr�tszBooable.booN)rrrr9r�r�r�r�rrrrr�fs
r�c@s eZdZdZdd�Zdd�ZdS)�IMultipleMethodsz-
    An interface with multiple methods.
    cCsdS)z4
        The first method. Should return 1.
        Nrrrrr�	methodOne�szIMultipleMethods.methodOnecCsdS)z5
        The second method. Should return 2.
        Nrrrrr�	methodTwo�szIMultipleMethods.methodTwoN�rrrr9r�r�rrrrr�|sr�c@s eZdZdZdd�Zdd�ZdS)�MultipleMethodImplementorz:
    A precise implementation of L{IMultipleMethods}.
    cCsdS)z
        @return: 1
        rrrrrrr��sz#MultipleMethodImplementor.methodOnecCsdS)z
        @return: 2
        r<rrrrrr��sz#MultipleMethodImplementor.methodTwoNr�rrrrr��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�ProxyForInterfaceTestsz)
    Tests for L{proxyForInterface}.
    cCs$t�}tt�|�}|�|j|�dS)z�
        Proxy objects should have an C{original} attribute which refers to the
        original object passed to the constructor.
        N)rKrr�rGr')rr'�proxyrrr�
test_original�sz$ProxyForInterfaceTests.test_originalcCs@tt�}t�}||�}|��|�|��d�|�|jd�dS)z�
        The class created from L{proxyForInterface} passes methods on an
        interface to the object which is passed to its constructor.
        r<N�rr�r�r�rNr�)r�klass�yayabler�rrr�test_proxyMethod�sz'ProxyForInterfaceTests.test_proxyMethodcsDtt��G�fdd�d��}t�}||�}|��|�d|j�dS)z�
        Methods of the class created from L{proxyForInterface} can be used with
        the decorator-helper L{functools.wraps}.
        cs"eZdZe�j��fdd��ZdS)z?ProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klasscs|jjd7_��|�Sr)r'r�r�r��baserrr��szCProxyForInterfaceTests.test_decoratedProxyMethod.<locals>.klass.yayN)rrrrr�rr�rrr��sr�r<Nr�)rr�r'r�rr�r�test_decoratedProxyMethod�sz0ProxyForInterfaceTests.test_decoratedProxyMethodcsBt�}t�|_tt�|��|��j|j�|�t�fdd��dS)zc
        Proxy objects should proxy declared attributes, but not other
        attributes.
        cs�jSr)r�r�r�rrr�r�z<ProxyForInterfaceTests.test_proxyAttribute.<locals>.<lambda>N)r�rKr�rr�rGr]�AttributeError)rr�rr�r�test_proxyAttribute�s
z*ProxyForInterfaceTests.test_proxyAttributecCs0t�}tt�|�}t�}||_|�|j|�dS)zv
        The attributes that proxy objects proxy should be assignable and affect
        the original object.
        N)r�rr�rKr�rG�rr�r�Zthingyrrr�test_proxySetAttribute�s
z-ProxyForInterfaceTests.test_proxySetAttributecCs0t�}d|_tt�|�}|`|�t|d��dS)zu
        The attributes that proxy objects proxy should be deletable and affect
        the original object.
        Nr�)r�r�rr��assertFalse�hasattr)rr�r�rrr�test_proxyDeleteAttribute�s
z0ProxyForInterfaceTests.test_proxyDeleteAttributecCs6t�}tt�|�}|�|��d�|�|��d�dS)z�
        [Regression test] The proxy should send its method calls to the correct
        method, not the incorrect one.
        rr<N)r�rr�rNr�r�)rZmultir�rrr�test_multipleMethods�sz+ProxyForInterfaceTests.test_multipleMethodscCsJGdd�dtt��}t�}||�}|�|jd�|��|�|jd�dS)zP
        It is possible to subclass the result of L{proxyForInterface}.
        c@seZdZdZdd�ZdS)zAProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxyzU
            A specialized proxy which can decrement the number of yays.
            cSs|jjd8_dS)z?
                Decrement the number of yays.
                rN)r'r�rrrrr�szEProxyForInterfaceTests.test_subclassing.<locals>.SpecializedProxy.booNr�rrrr�SpecializedProxysr�r���N)rr�r�rNr�r�)rr�r�Zspecialrrr�test_subclassing�s
z'ProxyForInterfaceTests.test_subclassingcCstt�}|�|jd�dS)zQ
        The name of a proxy class indicates which interface it proxies.
        zA(Proxy for twisted.python.test.test_components.IProxiedInterface)N)rr�rNr�rr�rrr�test_proxyNames
�z%ProxyForInterfaceTests.test_proxyNamecCstt�}|�t�|��dS)zO
        The resulting proxy implements the interface that it proxies.
        N)rr��
assertTrueZ
implementedByr�rrr�test_implementssz&ProxyForInterfaceTests.test_implementscCsdGdd�dt�}|�}|�}||_t�dd�}|�|�|�|j�|�d�}||�|�|j�dS)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@seZdZdZdd�ZdS)z>ProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.SampleFcSs
d|_dSr�)�calledrrrrrX9szDProxyForInterfaceTests.test_proxyDescriptorGet.<locals>.Sample.helloN)rrrr�rXrrrr�Sample7sr�rXr'N)	rKr'rZ_ProxyDescriptorrN�__get__rXr�r�)rr�Z	fakeProxyZ
testObjectZpdZfakeClassMethodrrr�test_proxyDescriptorGet's
z.ProxyForInterfaceTests.test_proxyDescriptorGetcspGdd�dtt���G�fdd�d��}t�}||�}|�|jddddd	�d
�|�|jdtddd	�fg�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@seZdZdZdS)zDProxyForInterfaceTests.test_proxyInheritance.<locals>.YayableWrapperzI
            This class does not override any functionality.
            N)rrrr9rrrr�YayableWrapperKsr�cs eZdZdZdZ�fdd�ZdS)zEProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapperz@
            This class overrides the 'yay' method.
            rcs$|jd7_�j|f|�|�dS)Nr�)�wrappedYaysr�)rr_�k�r�rrr�UszIProxyForInterfaceTests.test_proxyInheritance.<locals>.EnhancedWrapper.yayN)rrrr9r�r�rr�rr�EnhancedWrapperPsr�rz���)rm�y�)rzr�N)rr�r�rNr�r��dict)rr�r��wrapperrr�r�test_proxyInheritanceEs	�z,ProxyForInterfaceTests.test_proxyInheritancecCsBtt�}t�}||�}|��|��|�|j�|�|j�dS)z�
        Proxies of subinterfaces generated with proxyForInterface should allow
        access to attributes of both the child and the base interfaces.
        N)rr�r�r�r�r�r�r�)rZ
proxyClassZbooabler�rrr�test_interfaceInheritance`sz0ProxyForInterfaceTests.test_interfaceInheritancecCs~t�}t�|_ttdd�|�}|�|j|�|�|��d�|�|j|j�t�}||_|�|j|�|`|�	t
|d��dS)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)ZoriginalAttributerr�N)r�rKr�rr�rGr�rNr�r�r�r�rrr�test_attributeCustomizationns ��z2ProxyForInterfaceTests.test_attributeCustomizationN)rrrr9r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s

r�N)?r9Z
__future__rr�	functoolsrZzope.interfacerrrZzope.interface.adapterrZtwisted.python.compatr	r
Z
twisted.trialrZtwisted.pythonrZtwisted.python.componentsr
rrrJrrr!rjr$r*r+r-r.r/r0r1r2r3rKr5r6ZSynchronousTestCaser:r\rarbrfrgrhrirlrorqrsrwr}r�r�r�r�r�r�r�rrrr�<module>sp
y	D