Current File : //usr/lib/python3/dist-packages/zope/interface/common/__pycache__/__init__.cpython-312.pyc
�

��e�(���ddlZddlmZddlmZddlmZddlmZddlmZddlm	Z	gZ
Gd�d	�ZGd
�de�Zd�Z
e
�Zy)
�N)�FunctionType)�classImplements)�	Interface)�fromFunction)�InterfaceClass)�_decorator_non_returnc��eZdZd�Zy)�optionalc�&�|j|_y�N)�__doc__)�self�methods  �@/usr/lib/python3/dist-packages/zope/interface/common/__init__.py�__init__zoptional.__init__#s
���~�~���N)�__name__�
__module__�__qualname__r�rrr
r
s��&rr
c�f�eZdZdZd�Zed��Zd�Zed��Zed��Z	d�Z
dd	�Zd
�Zd�Z
y)
�ABCInterfaceClassa�

    An interface that is automatically derived from a
    :class:`abc.ABCMeta` type.

    Internal use only.

    The body of the interface definition *must* define
    a property ``abc`` that is the ABC to base the interface on.

    If ``abc`` is *not* in the interface definition, a regular
    interface will be defined instead (but ``extra_classes`` is still
    respected).

    Use the ``@optional`` decorator on method definitions if
    the ABC defines methods that are not actually required in all cases
    because the Python language has multiple ways to implement a protocol.
    For example, the ``iter()`` protocol can be implemented with
    ``__iter__`` or the pair ``__len__`` and ``__getitem__``.

    When created, any existing classes that are registered to conform
    to the ABC are declared to implement this interface. This is *not*
    automatically updated as the ABC registry changes. If the body of the
    interface definition defines ``extra_classes``, it should be a
    tuple giving additional classes to declare implement the interface.

    Note that this is not fully symmetric. For example, it is usually
    the case that a subclass relationship carries the interface
    declarations over::

        >>> from zope.interface import Interface
        >>> class I1(Interface):
        ...     pass
        ...
        >>> from zope.interface import implementer
        >>> @implementer(I1)
        ... class Root(object):
        ...     pass
        ...
        >>> class Child(Root):
        ...     pass
        ...
        >>> child = Child()
        >>> isinstance(child, Root)
        True
        >>> from zope.interface import providedBy
        >>> list(providedBy(child))
        [<InterfaceClass __main__.I1>]

    However, that's not the case with ABCs and ABC interfaces. Just
    because ``isinstance(A(), AnABC)`` and ``isinstance(B(), AnABC)``
    are both true, that doesn't mean there's any class hierarchy
    relationship between ``A`` and ``B``, or between either of them
    and ``AnABC``. Thus, if ``AnABC`` implemented ``IAnABC``, it would
    not follow that either ``A`` or ``B`` implements ``IAnABC`` (nor
    their instances provide it)::

        >>> class SizedClass(object):
        ...     def __len__(self): return 1
        ...
        >>> from collections.abc import Sized
        >>> isinstance(SizedClass(), Sized)
        True
        >>> from zope.interface import classImplements
        >>> classImplements(Sized, I1)
        None
        >>> list(providedBy(SizedClass()))
        []

    Thus, to avoid conflicting assumptions, ABCs should not be
    declared to implement their parallel ABC interface. Only concrete
    classes specifically registered with the ABC should be declared to
    do so.

    .. versionadded:: 5.0.0
    c	��||_|jdd�}|jdd�}d|vr;tj||||�tj|||�t|_y|jd�}||_t|�|_	t|�|_
|dd|jk(s	J||f��t|�j�D��cic]J\}}t|t�r5|j|�s$|j!|�s||j#||���L}	}}|j%|�|	d<|	j'|�tj||||	�|j�ycc}}w)N�
extra_classesr�ignored_classes�abc�r
)r�poprrr�$_ABCInterfaceClass__register_classes�	__class__�_ABCInterfaceClass__abc�tuple�!_ABCInterfaceClass__extra_classes�#_ABCInterfaceClass__ignored_classes�vars�items�
isinstancer�#_ABCInterfaceClass__is_private_name�,_ABCInterfaceClass__is_reverse_protocol_name�(_ABCInterfaceClass__method_from_function�$_ABCInterfaceClass__create_class_doc�update)
r�name�bases�attrsrr�based_on�k�v�methodss
          rrzABCInterfaceClass.__init__xsh����
��	�	�/�2�6�
��)�)�$5�r�:�����
�#�#�D�$��u�=��0�0��}�o�V�+�D�N���9�9�U�#����
�$�]�3���!&��!7����A�B�x�8�,�,�,�>�t�X�.>�>�,�
�X��,�,�.�	
���1��!�\�*�4�3I�3I�!�3L��3�3�A�6�
�t�*�*�1�a�0�0�
��
�"�4�4�U�;��	�����u������d�E�7�;����!��
s�AE:c���|j�D��cic]\}}t|t�s�||��}}}|D]}t||<�
|syddj	d�|j�D��z}|Scc}}w)N�z)

The following methods are optional:
 - z
-c3�ZK�|]#\}}dj||j����%y�w)z{}
{}N)�formatr
)�.0r1r2s   r�	<genexpr>z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>�s*����K
�.2�a��H�O�O�A�q�y�y�)�K
�s�)+)r&r'r
r�join)r/r1r2�	optionals�docss     r�__optional_methods_to_docsz,ABCInterfaceClass.__optional_methods_to_docs�s���&+�k�k�m�O�d�a��z�!�X�7N�Q��T�O�	�O��	-�A�,�E�!�H�	-���=��
�
�K
�6?�o�o�6G�K
�A
�
�����Ps
�A3�A3c�|��|j}d��dj�fd�t|j����D��}|rd|z}|jxsd}|j�}|r|dnd}dj
|j|j|jd	|�|j|�|�}|S)
Nc��|j}|j}|tjk(rd|zS|dk(rd}dj||�S)Nz`%s`�_io�ioz`{}.{}`)rr�strr7)�c�modr-s   r�refz1ABCInterfaceClass.__create_class_doc.<locals>.ref�sI���,�,�C��:�:�D��c�n�n�$���}�$��e�|����#�#�C��.�.rz
 - c3�.�K�|]}�|����y�wrr)r8rCrEs  �rr9z7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>�s�����+
��
��F�+
�s�)�keyz!

Known implementations are:

 - r5rz&Interface for the ABC `{}.{}`.

{}{}{}r
)r!r:�sorted�getRegisteredConformersr
�
splitlinesr7rr�get�,_ABCInterfaceClass__optional_methods_to_docs)rr/r0�implementations_doc�based_on_doc�docrEs      @r�__create_class_docz$ABCInterfaceClass.__create_class_doc�s�����:�:��	/�&�l�l�+
��D�8�8�:��D�+
�
���"I�L_�"_�� �(�(�.�B��#�.�.�0��*6�|�A��B��<�C�C�����!2�!2��I�I�i��.��+�+�E�2��	
���
rc�j�|jd�r|jd�ry|jd�S)N�__F�_��
startswith�endswith�r-s r�__is_private_namez#ABCInterfaceClass.__is_private_name�s+���?�?�4� �T�]�]�4�%8�����s�#�#rc�J�|jd�xr|jd�S)N�__rrRrTrWs r�__is_reverse_protocol_namez,ABCInterfaceClass.__is_reverse_protocol_name�s!�����u�%�=�$�-�-��*=�=rc�J�t|||��}|jdd|_|S)NrWr)r�
positional)r�functionr-rs    r�__method_from_functionz(ABCInterfaceClass.__method_from_function�s,���h��4�8��#�-�-�a�b�1����
rNc�|�|�|n|j�}|�|n|j}|D]}||vr�t||��yr)rIr$r)r�
conformersr�ignored�clss     r�__register_classesz$ABCInterfaceClass.__register_classes�sN��$.�#9�Z�t�?[�?[�?]�
�%4�%@�/�d�F\�F\���	'�C��g�~���C��&�	'rc��|jS)z;
        Return the ABC this interface represents.
        )r!)rs r�getABCzABCInterfaceClass.getABC�s���z�z�rc��|j}	t|j�t|j�z}ttj||j��S#t$raddlm}||�}|d}|d}tj||�D�cgc]	}|���ncc}w}}|D�cgc]}|��|��	ncc}w}}Y��wxYw)zz
        Return an iterable of the classes that are known to conform to
        the ABC this interface parallels.
        r)�	_get_dumpr)r!�list�
_abc_registry�
_abc_cache�AttributeErrorrrh�	itertools�chain�setr#)rr0�
registeredrh�data�registry�cache�xs        rrIz)ABCInterfaceClass.getRegisteredConformers�s���
�:�:��
	B��h�4�4�5��X�=P�=P�8Q�Q�J��9�?�?�:�t�/C�/C�D�E�E���	B�
&��X�&�D��A�w�H���G�E�'0���x��'G�H�!�!�#�H��H�J�H�%/�A��1�=�!�A��A�J�A�	B�s/�+A"�"9C�B*�)C�5C�=C�C�C)NN)rrrr
r�staticmethodrLr+r(r)r*rrfrIrrrrr'se��J�`!"�F�����<�$��$�
�>��>��'��Frrc�z�dtfif}tjtg|���}tj|g|���|S)N�ABCInterface)rr�__new__rr)�abc_name_bases_attrs�instances  r�_create_ABCInterfacer{sC��
+�Y�L�"�=�� �(�(�):�R�=Q�R�H����H�<�';�<��Or)rm�typesr�zope.interfacerr�zope.interface.interfacerrr�__all__r
rr{rwrrr�<module>r�sM����*�$�1�3�:���&�&�\F��\F�~�$�%�r