%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/components.cpython-312.pyc

�

Ϫ�fw7���dZddlmZddlmZddlmZmZddlm	Z	ddl
mZe	�Zda
d�Zd�Zd	�Zd
�Zee�d�ZeZGd�d
�ZGd�d�ZGd�de�Zdd�ZGd�d�ZGd�d�Zgd�Zy)a�
Component architecture for Twisted, based on Zope3 components.

Using the Zope3 API directly is strongly recommended. Everything
you need is in the top-level of the zope.interface package, e.g.::

   from zope.interface import Interface, implementer

   class IFoo(Interface):
       pass

   @implementer(IFoo)
   class Foo:
       pass

   print(IFoo.implementedBy(Foo)) # True
   print(IFoo.providedBy(Foo())) # True

L{twisted.python.components.registerAdapter} from this module may be used to
add to Twisted's global adapter registry.

L{twisted.python.components.proxyForInterface} is a factory for classes
which allow access to only the parts of another class defined by a specified
interface.
�)�StringIO)�Dict)�declarations�	interface)�AdapterRegistry)�reflectc��t}|sJd��t|tj�st	j
|�}|D]-}|j
|g|�}|��tr� td|�d���|D]}|j|g|d|��y)a
Register an adapter class.

    An adapter class is expected to implement the given interface, by
    adapting instances implementing 'origInterface'. An adapter class's
    __init__ method should accept one parameter, an instance implementing
    'origInterface'.
    zYou need to pass an InterfaceNzan adapter (z) was already registered.�)
�globalRegistry�
isinstancer�InterfaceClassr�
implementedBy�
registered�ALLOW_DUPLICATES�
ValueError�register)�adapterFactory�
origInterface�interfaceClasses�self�interfaceClass�factorys      �;/usr/lib/python3/dist-packages/twisted/python/components.py�registerAdapterr2s����D��<�<�<���m�Y�%=�%=�>�$�2�2�=�A�
�*�P���/�/�=�/�>�B����'7��|�G�9�4M�N�O�O�P�+�K���
�
�}�o�~�r�>�J�K�c��t}t|tj�st	j
|�}|j
||�}|�|}|S)z�Return registered adapter for a given class and interface.

    Note that is tied to the *Twisted* global registry, and will
    thus not find adapters registered elsewhere.
    )rrrr
rr�lookup1)�
fromInterface�toInterface�defaultrrs     r�getAdapterFactoryr!JsH���D��m�Y�%=�%=�>�$�2�2�=�A�
��l�l�=�+�6�G������Nrc�h��|j��fd�}tjj|�|S)z�
    Add an adapter hook which will attempt to look up adapters in the given
    registry.

    @type registry: L{zope.interface.adapter.AdapterRegistry}

    @return: The hook which was added, for later use with L{_removeHook}.
    c�R���tj|�|�}|�y||�S�N)r�
providedBy)�iface�obr�lookups   �r�_hookz_addHook.<locals>._hookds,�����0�0��4�e�<���?���2�;�r)rr�
adapter_hooks�append)�registryr)r(s  @r�_addHookr-Ys0����
�
�F�����"�"�5�)��Lrc�B�tjj|�y)z�
    Remove a previously added adapter hook.

    @param hook: An object previously returned by a call to L{_addHook}.  This
        will be removed from the list of adapter hooks.
    N)rr*�remove)�hooks r�_removeHookr1os�����"�"�4�(rc��tS)zWReturns the Twisted global
    C{zope.interface.adapter.AdapterRegistry} instance.
    )r�rr�getRegistryr4}s
���rc�*�eZdZdZdZdZd�Zd�Zd�Zy)�Adaptera/I am the default implementation of an Adapter for some interface.

    This docstring contains a limerick, by popular demand::

        Subclassing made Zope and TR
        much harder to work with by far.
            So before you inherit,
            be sure to declare it
        Adapter, not PyObject*

    @cvar temporaryAdapter: If this is True, the adapter will not be
          persisted on the Componentized.
    @cvar multiComponent: If this adapter is persistent, should it be
          automatically registered for all appropriate interfaces.
    r�c��||_y)z;Set my 'original' attribute to be the object I am adapting.N��original)rr:s  r�__init__zAdapter.__init__�s	�� ��
rc�f�t|jd�r|jj|�Sy)zn
        I forward __conform__ to self.original if it has it, otherwise I
        simply return None.
        �__conform__N)�hasattrr:r=�rrs  rr=zAdapter.__conform__�s*��
�4�=�=�-�0��=�=�,�,�Y�7�7�rc�:�|jj||�S)z1
        Forward isuper to self.original
        )r:�isuper)rr&�adapters   rrAzAdapter.isuper�s���}�}�#�#�E�7�3�3rN)	�__name__�
__module__�__qualname__�__doc__�temporaryAdapter�multiComponentr;r=rAr3rrr6r6�s#���$���N�!��4rr6c�V�eZdZdZdZd�Zd�Zd�Zdd�Zd�Z	dd�Z
d	�Zd
�Zdd�Z
d
�Zy)�
Componentizeda�I am a mixin to allow you to be adapted in various ways persistently.

    I define a list of persistent adapters.  This is to allow adapter classes
    to store system-specific state, and initialized on demand.  The
    getComponent method implements this.  You must also register adapters for
    this class for the interfaces that you wish to pass to getComponent.

    Many other classes and utilities listed here are present in Zope3; this one
    is specific to Twisted.
    r7c��i|_yr$)�
_adapterCache�rs rr;zComponentized.__init__�s
����rc��t|||�Sr$)r!)r�klassrr s    r�locateAdapterClassz Componentized.locateAdapterClass�s�� ����@�@rc�4�|j|||��y)zv
        Cache a provider for the given interface, by adapting C{self} using
        the given adapter class.
        N)�setComponent)rr�adapterClasss   r�
setAdapterzComponentized.setAdapter�s��
	
���.�,�t�*<�=rc�:�||�}|j||�|S)z�Utility method that calls addComponent.  I take an adapter class and
        instantiate it with myself as the first argument.

        @return: The adapter instantiated.
        )�addComponent)rrS�ignoreClass�adapts    r�
addAdapterzComponentized.addAdapter�s#���T�"�����%��-��rc�H�||jtj|�<y)z:
        Cache a provider of the given interface.
        N�rLr�qual)rr�	components   rrRzComponentized.setComponent�s��<E����7�<�<��7�8rc���tj|�D]Q}|s+|j|j|d�|jk(s�0||jtj|�<�Sy)a�
        Add a component to me, for all appropriate interfaces.

        In order to determine which interfaces are appropriate, the component's
        provided interfaces will be scanned.

        If the argument 'ignoreClass' is True, then all interfaces are
        considered appropriate.

        Otherwise, an 'appropriate' interface is one for which its class has
        been registered as an adapter for my class according to the rules of
        getComponent.
        N)rr%rP�	__class__rLrr\)rr]rWr&s    rrVzComponentized.addComponent�sc��"�,�,�Y�7�	D�E���'�'�����t�D��&�&�'�;D��"�"�7�<�<��#6�7�	Drc�D�|jtj|�=y)z;Remove my component specified by the given interface class.Nr[)rrs  r�unsetComponentzComponentized.unsetComponent�s�����w�|�|�N�;�<rc���g}t|jj��D];\}}||us�|j|=|jt	j
|���=|S)z�
        Remove the given component from me entirely, for all interfaces for which
        it has been registered.

        @return: a list of the interfaces that were removed.
        )�listrL�itemsr+r�namedObject)rr]�l�k�vs     r�removeComponentzComponentized.removeComponent�sc��
����+�+�1�1�3�4�	1�D�A�q��I�~��&�&�q�)�����,�,�Q�/�0�	1��rNc�:�tj|�}||jvr|j|S|j|�}|�Pt	|d�r|j
s8||j|<t	|d�r|jr|j|�|�|S|S)aCreate or retrieve an adapter for the given interface.

        If such an adapter has already been created, retrieve it from the cache
        that this instance keeps of all its adapters.  Adapters created through
        this mechanism may safely store system-specific state.

        If you want to register an adapter that will be created through
        getComponent, but you don't require (or don't want) your adapter to be
        cached and kept alive for the lifetime of this Componentized object,
        set the attribute 'temporaryAdapter' to True on your adapter class.

        If you want to automatically register an adapter for all appropriate
        interfaces (with addComponent), set the attribute 'multiComponent' to
        True on your adapter class.
        rGrH)rr\rL�	__adapt__r>rGrHrV)rrr rgrBs     r�getComponentzComponentized.getComponents��� 
�L�L��#����"�"�"��%�%�a�(�(�)�i�)�)�$�/�G��"���!3�4��9Q�9Q�(/��"�"�1�%��7�$4�5�'�:P�:P��%�%�g�.������Nrc�$�|j|�Sr$)rlr?s  rr=zComponentized.__conform__#s��� � ��+�+r)rr$)rCrDrErF�persistenceVersionr;rPrTrYrRrVrarirlr=r3rrrJrJ�sD��	��� �A�>��E�D�*=���>,rrJc��eZdZd�Zdefd�Zy)�ReprableComponentizedc�.�tj|�yr$)rJr;rMs rr;zReprableComponentized.__init__(s�����t�$r�returnc�h�ddlm}t�}||j|�|j�S)Nr)�pprint)rtrrL�getvalue)rrt�sios   r�__repr__zReprableComponentized.__repr__+s(��!��j���t�!�!�3�'��|�|�~�rN)rCrDrEr;�strrwr3rrrprp's��%��#�rrpc�����fd�}d|i}|D]}t|��||<�tdtj|��d�tf|�}tj||�|S)a�
    Create a class which proxies all method calls which adhere to an interface
    to another provider of that interface.

    This function is intended for creating specialized proxies. The typical way
    to use it is by subclassing the result::

      class MySpecializedProxy(proxyForInterface(IFoo)):
          def someInterfaceMethod(self, arg):
              if arg == 3:
                  return 3
              return self.original.someInterfaceMethod(arg)

    @param iface: The Interface to which the resulting object will conform, and
        which the wrapped object must provide.

    @param originalAttribute: name of the attribute used to save the original
        object in the resulting class. Default to C{original}.
    @type originalAttribute: C{str}

    @return: A class whose constructor takes the original object as its only
        argument. Constructing the class creates the proxy.
    c� ��t|�|�yr$)�setattr)rr:�originalAttributes  �rr;z#proxyForInterface.<locals>.__init__Ls�����'��2rr;z(Proxy for �))�_ProxyDescriptor�typerr\�objectr�classImplements)r&r|r;�contents�name�proxys `    r�proxyForInterfacer�3sp���23�$.�x�"8�H��C��)�$�0A�B����C��;�w�|�|�E�2�3�1�5��y�(�K�E�� � ���.��Lrc��eZdZdZd�Zd�Zy)�_ProxiedClassMethoda�
    A proxied class method.

    @ivar methodName: the name of the method which this should invoke when
        called.
    @type methodName: L{str}

    @ivar __name__: The name of the method being proxied (the same as
        C{methodName}).
    @type __name__: L{str}

    @ivar originalAttribute: name of the attribute of the proxy where the
        original object is stored.
    @type originalAttribute: L{str}
    c�.�|x|_|_||_yr$)�
methodNamerCr|)rr�r|s   rr;z_ProxiedClassMethod.__init__js��*4�4���$�-�!2��rc�j�t||j�}t||j�}||i|��S)z�
        Invoke the specified L{methodName} method of the C{original} attribute
        for proxyForInterface.

        @param oself: an instance of a L{proxyForInterface} object.

        @return: the result of the underlying method.
        )�getattrr|r�)r�oself�args�kwr:�actualMethods      r�__call__z_ProxiedClassMethod.__call__ns6���5�$�"8�"8�9���x����9���T�(�R�(�(rN)rCrDrErFr;r�r3rrr�r�Ys��� 3�)rr�c�*�eZdZdZd�Zdd�Zd�Zd�Zy)r~a�
    A descriptor which will proxy attribute access, mutation, and
    deletion to the L{_ProxyDescriptor.originalAttribute} of the
    object it is being accessed from.

    @ivar attributeName: the name of the attribute which this descriptor will
        retrieve from instances' C{original} attribute.
    @type attributeName: C{str}

    @ivar originalAttribute: name of the attribute of the proxy where the
        original object is stored.
    @type originalAttribute: C{str}
    c� �||_||_yr$)�
attributeNamer|)rr�r|s   rr;z_ProxyDescriptor.__init__�s��*���!2��rNc��|� t|j|j�St||j�}t||j�S)zL
        Retrieve the C{self.attributeName} property from I{oself}.
        )r�r�r|r�)rr�rr:s    r�__get__z_ProxyDescriptor.__get__�sG���=�&�t�'9�'9�4�;Q�;Q�R�R��5�$�"8�"8�9���x��!3�!3�4�4rc�^�t||j�}t||j|�y)zE
        Set the C{self.attributeName} property of I{oself}.
        N)r�r|r{r�)rr��valuer:s    r�__set__z_ProxyDescriptor.__set__�s(���5�$�"8�"8�9����$�,�,�e�4rc�\�t||j�}t||j�y)zH
        Delete the C{self.attributeName} property of I{oself}.
        N)r�r|�delattrr�)rr�r:s   r�
__delete__z_ProxyDescriptor.__delete__�s&���5�$�"8�"8�9����$�,�,�-rr$)rCrDrErFr;r�r�r�r3rrr~r~|s���3�5�5�.rr~)rr!r6rJrpr4r�Nr9)rF�ior�typingr�zope.interfacerr�zope.interface.adapterr�twisted.pythonrrrrr!r-r1r4�	TypeError�CannotAdaptr6rJrpr�r�r~�__all__r3rr�<module>r�s����6��3�2�#�!�"����K�0��,)�	������'4�'4�Tr,�r,�j	�M�	�#�L )� )�F(.�(.�V�r

Zerion Mini Shell 1.0