%PDF- %PDF-
 Mini Shell
 Mini Shell  
 | Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/ | 
| Current File : //lib/python3/dist-packages/twisted/python/__pycache__/components.cpython-312.pyc | 
�
    Ϫ�fw7  �                   �  � d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ  e	�       Zda
d� Zd� Zd	� Zd
� Z ee�       d� ZeZ G d� d
�      Z G d� d�      Z G d� de�      Zdd�Z G d� d�      Z G d� d�      Zg d�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         }|sJ d�       �t        |t        j                  �      st	        j
                  |�      }|D ]-  }|j
                  |g|�      }|��t        r� t        d|� 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 InterfaceNzan 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�registerAdapterr   2   s�   � � �D��<�<�<�� �m�Y�%=�%=�>�$�2�2�=�A�
�*� P���/�/�=�/�>�B����'7��|�G�9�4M�N�O�O�P� +� K���
�
�}�o�~�r�>�J�K�    c                 �   � t         }t        | t        j                  �      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.
    )r   r   r   r
   r   r   �lookup1)�
fromInterface�toInterface�defaultr   r   s        r   �getAdapterFactoryr!   J   sH   � � �D��m�Y�%=�%=�>�$�2�2�=�A�
��l�l�=�+�6�G������Nr   c                 �h   �� | j                   ��fd�}t        j                  j                  |�       |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   ��  �t        j                  |�      | �      }|�y  ||�      S �N)r   �
providedBy)�iface�obr   �lookups      �r   �_hookz_addHook.<locals>._hookd   s,   �� ���0�0��4�e�<���?���2�;�r   )r   r   �
adapter_hooks�append)�registryr)   r(   s     @r   �_addHookr-   Y   s0   �� � �
�
�F�� ���"�"�5�)��Lr   c                 �B   � t         j                  j                  | �       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)r   r*   �remove)�hooks    r   �_removeHookr1   o   s   � � ���"�"�4�(r   c                  �   � t         S )zWReturns the Twisted global
    C{zope.interface.adapter.AdapterRegistry} instance.
    )r   � r   r   �getRegistryr4   }   s
   � � �r   c                   �*   � e Zd ZdZdZdZd� 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)r   r:   s     r   �__init__zAdapter.__init__�   s	   � � ��
r   c                 �f   � t        | j                  d�      r| j                  j                  |�      S y)zn
        I forward __conform__ to self.original if it has it, otherwise I
        simply return None.
        �__conform__N)�hasattrr:   r=   �r   r   s     r   r=   zAdapter.__conform__�   s*   � �
 �4�=�=�-�0��=�=�,�,�Y�7�7�r   c                 �:   � | j                   j                  ||�      S )z1
        Forward isuper to self.original
        )r:   �isuper)r   r&