§
    JDvcÙ(  ã                   ó¬   — d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 g Z
 G d„ d	e¦  «        Z G d
„ de¦  «        Zd„ Z e¦   «         ZdS )é    N)ÚFunctionType)ÚclassImplements)Ú	Interface)ÚfromFunction)ÚInterfaceClass)Ú_decorator_non_returnc                   ó   — e Zd Zd„ ZdS )Úoptionalc                 ó   — |j         | _         d S ©N©Ú__doc__)ÚselfÚmethods     ú@/usr/lib/python3/dist-packages/zope/interface/common/__init__.pyÚ__init__zoptional.__init__#   s   € Ø”~ˆŒˆˆó    N)Ú__name__Ú
__module__Ú__qualname__r   © r   r   r
   r
      s#   € € € € € ð&ð &ð &ð &ð &r   r
   c                   óz   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zed„ ¦   «         Zed„ ¦   «         Z	d„ Z
dd	„Zd
„ Zd„ ZdS )Ú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                 óÈ  ‡ — |‰ _         |                     dd¦  «        }|                     dd¦  «        }d|vrAt          j        ‰ |||¦  «         t                               ‰ ||¦  «         t          ‰ _        d S |                     d¦  «        }|‰ _        t          |¦  «        ‰ _	        t          |¦  «        ‰ _
        |dd …         |j         k    sJ ||f¦   «         ‚ˆ fd„t          |¦  «                             ¦   «         D ¦   «         }‰                      |¦  «        |d<   |                     |¦  «         t          j        ‰ |||¦  «         ‰                      ¦   «          d S )NÚextra_classesr   Úignored_classesÚabcé   c                 óÂ   •— i | ][\  }}t          |t          ¦  «        ¯‰                     |¦  «        °/‰                     |¦  «        °D|‰                     ||¦  «        “Œ\S r   )Ú
isinstancer   Ú#_ABCInterfaceClass__is_private_nameÚ,_ABCInterfaceClass__is_reverse_protocol_nameÚ(_ABCInterfaceClass__method_from_function)Ú.0ÚkÚvr   s      €r   ú
<dictcomp>z.ABCInterfaceClass.__init__.<locals>.<dictcomp>Œ   sƒ   ø€ ð 
ð 
ð 
ñ ��1Ý˜!�\Ñ*Ô*ð
ð
 48×3IÒ3IÈ!Ñ3LÔ3Lð
ð ×3Ò3°AÑ6Ô6ð
ð ˆt×*Ò*¨1¨aÑ0Ô0ð
ð 
ð 
r   r   )r   Úpopr   r   r   Ú$_ABCInterfaceClass__register_classesÚ	__class__Ú_ABCInterfaceClass__abcÚtupleÚ!_ABCInterfaceClass__extra_classesÚ#_ABCInterfaceClass__ignored_classesÚvarsÚitemsÚ$_ABCInterfaceClass__create_class_docÚupdate)r   ÚnameÚbasesÚattrsr   r   Úbased_onÚmethodss   `       r   r   zABCInterfaceClass.__init__x   sq  ø€ àˆŒØŸ	š	 /°2Ñ6Ô6ˆØŸ)š)Ð$5°rÑ:Ô:ˆà˜ÐÐõ Ô# D¨$°°uÑ=Ô=Ð=Ý×0Ò0°°}ÀoÑVÔVÐVÝ+ˆDŒNØˆFà—9’9˜UÑ#Ô#ˆØˆŒ
Ý$ ]Ñ3Ô3ˆÔÝ!& Ñ!7Ô!7ˆÔà�A�B�BŒx˜8Ô,Ò,Ð,Ð,¨t°XÐ.>Ñ,Ô,Ð,ð
ð 
ð 
ð 
õ ˜X™œ×,Ò,Ñ.Ô.ð	
ñ 
ô 
ˆð "×4Ò4°UÑ;Ô;ˆ�	Ñà�Š�uÑÔÐÝÔ  d¨E°7Ñ;Ô;Ð;Ø×ÒÑ!Ô!Ð!Ð!Ð!r   c                 óÐ   — d„ |                       ¦   «         D ¦   «         }|D ]}t          | |<   Œ|sdS dd                     d„ |                      ¦   «         D ¦   «         ¦  «        z   }|S )Nc                 óD   — i | ]\  }}t          |t          ¦  «        ¯||“ŒS r   )r    r
   ©r$   r%   r&   s      r   r'   z@ABCInterfaceClass.__optional_methods_to_docs.<locals>.<dictcomp>�   s-   € ÐOÐOÐO™d˜a µzÀ!ÅXÑ7NÔ7NÐO�Q˜ÐOÐOÐOr   Ú z)

The following methods are optional:
 - z
-c              3   ó4   K  — | ]\  }}|›d |j         ›�V — ŒdS )ú
Nr   r:   s      r   ú	<genexpr>z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>¤   sL   è è € ð K
ð K
Ù*.¨!¨Q˜˜˜˜1œ9˜9Ð%ðK
ð K
ð K
ð K
ð K
ð K
r   )r0   r   Újoin)r5   Ú	optionalsr%   Údocss       r   Ú__optional_methods_to_docsz,ABCInterfaceClass.__optional_methods_to_docs›   s’   € àOÐO e§k¢k¡m¤mÐOÑOÔOˆ	Øð 	-ð 	-ˆAÝ,ˆE�!‰HˆHàð 	Ø�2à=ÀÇ
Â
ð K
ð K
Ø2;·/²/Ñ2CÔ2CðK
ñ K
ô K
ñ A
ô A
ñ 
ˆð ˆr   c           	      ó€  ‡— | j         }d„ Šd                     ˆfd„t          |                      ¦   «         ‰¬¦  «        D ¦   «         ¦  «        }|rd|z   }|j        pd}|                     ¦   «         }|r|d         nd}d|j        ›d	|j        ›d
|                     d|¦  «        ›|  	                    |¦  «        ›|›�}|S )Nc                 ój   — | j         }| j        }|t          j         k    rd|z  S |dk    rd}d|›d|›d�S )Nz`%s`Ú_ioÚioú`ú.)r   r   Ústr)ÚcÚmodr3   s      r   Úrefz1ABCInterfaceClass.__create_class_doc.<locals>.ref«   sI   € Ø”,ˆCØ”:ˆDØ•c”nÒ$Ð$Ø ‘}Ð$Ø�eŠ|ˆ|Ø�øØ #   T T TÐ*Ð*r   z
 - c              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S r   r   )r$   rJ   rL   s     €r   r>   z7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>³   s?   øè è € ð +
ð +
àð ˆC�‰FŒFð+
ð +
ð +
ð +
ð +
ð +
r   )Úkeyz!

Known implementations are:

 - r;   r   zInterface for the ABC `rH   z`.

r   )
r+   r?   ÚsortedÚgetRegisteredConformersr   Ú
splitlinesr   r   ÚgetÚ,_ABCInterfaceClass__optional_methods_to_docs)r   r5   r6   Úimplementations_docÚbased_on_docÚdocrL   s         @r   Ú__create_class_docz$ABCInterfaceClass.__create_class_doc©   s  ø€ Ø”:ˆð	+ð 	+ð 	+ð &Ÿlšlð +
ð +
ð +
ð +
å˜D×8Ò8Ñ:Ô:ÀÐDÑDÔDð+
ñ +
ô +
ñ 
ô 
Ðð ð 	`Ø"IÐL_Ñ"_Ðà Ô(Ð.¨BˆØ#×.Ò.Ñ0Ô0ˆØ*6Ð>�| A”�¸Bˆˆð ÔÐÐ Ô!2Ð!2Ð!2Ø�IŠI�i Ñ.Ô.Ð.Ø×+Ò+¨EÑ2Ô2Ð2ØÐð	
ˆð ˆ
r   c                 ó„   — |                       d¦  «        r|                      d¦  «        rdS |                       d¦  «        S )NÚ__FÚ_©Ú
startswithÚendswith©r3   s    r   Ú__is_private_namez#ABCInterfaceClass.__is_private_nameÇ   s@   € à�?Š?˜4Ñ Ô ð 	 T§]¢]°4Ñ%8Ô%8ð 	Ø�5Ø�Š˜sÑ#Ô#Ð#r   c                 óV   — |                       d¦  «        o|                      d¦  «        S )NÚ__rrY   r[   r^   s    r   Ú__is_reverse_protocol_namez,ABCInterfaceClass.__is_reverse_protocol_nameÍ   s'   € ð �Š˜uÑ%Ô%Ð=¨$¯-ª-¸Ñ*=Ô*=Ð=r   c                 óR   — t          || |¬¦  «        }|j        dd …         |_        |S )Nr^   r   )r   Ú
positional)r   Úfunctionr3   r   s       r   Ú__method_from_functionz(ABCInterfaceClass.__method_from_functionÕ   s1   € Ý˜h¨°4Ð8Ñ8Ô8ˆð #Ô-¨a¨b¨bÔ1ˆÔØˆr   Nc                 ó€   — |�|n|                       ¦   «         }|�|n| j        }|D ]}||v rŒt          || ¦  «         Œd S r   )rP   r.   r   )r   Ú
conformersr   ÚignoredÚclss        r   Ú__register_classesz$ABCInterfaceClass.__register_classesÜ   sg   € ð $.Ð#9�Z�Z¸t×?[Ò?[Ñ?]Ô?]ˆ
Ø%4Ð%@�/�/ÀdÔF\ˆØð 	'ð 	'ˆCØ�gˆ~ˆ~ØÝ˜C Ñ&Ô&Ð&Ð&ð	'ð 	'r   c                 ó   — | j         S )z;
        Return the ABC this interface represents.
        )r+   )r   s    r   ÚgetABCzABCInterfaceClass.getABCæ   s   € ð ŒzÐr   c                 ól  — | j         }	 t          |j        ¦  «        t          |j        ¦  «        z   }n\# t          $ rO ddlm}  ||¦  «        }|d         }|d         }d„ t          j        ||¦  «        D ¦   «         }d„ |D ¦   «         }Y nw xY wt          t          j        || j
        ¦  «        ¦  «        S )zz
        Return an iterable of the classes that are known to conform to
        the ABC this interface parallels.
        r   )Ú	_get_dumpr   c                 ó"   — g | ]} |¦   «         ‘ŒS r   r   ©r$   Úxs     r   ú
<listcomp>z=ABCInterfaceClass.getRegisteredConformers.<locals>.<listcomp>   s   € ÐHÐHÐH !˜!˜!™#œ#ÐHÐHÐHr   c                 ó   — g | ]}|®|‘ŒS r   r   rq   s     r   rs   z=ABCInterfaceClass.getRegisteredConformers.<locals>.<listcomp>  s   € ÐAÐAÐA °1°=˜!°=°=°=r   )r+   ÚlistÚ_abc_registryÚ
_abc_cacheÚAttributeErrorr   ro   Ú	itertoolsÚchainÚsetr-   )r   r6   Ú
registeredro   ÚdataÚregistryÚcaches          r   rP   z)ABCInterfaceClass.getRegisteredConformersì   sÜ   € ð
 ”:ˆð
	BÝ˜hÔ4Ñ5Ô5½¸XÔ=PÑ8QÔ8QÑQˆJˆJøÝð 	Bð 	Bð 	Bð &Ð%Ð%Ð%Ð%Ð%Ø�9˜XÑ&Ô&ˆDØ˜A”wˆHØ˜”GˆEØHÐH¥y¤°xÀÑ'GÔ'GÐHÑHÔHˆJØAÐA ZÐAÑAÔAˆJˆJˆJð	Bøøøõ •9”? :¨tÔ/CÑDÔDÑEÔEÐEs   ‰)3 ³ABÂB)NN)r   r   r   r   r   ÚstaticmethodrS   r1   r!   r"   r#   r)   rm   rP   r   r   r   r   r   '   s×   € € € € € ðJð Jð`!"ð !"ð !"ðF ðð ñ „\ððð ð ð< ð$ð $ñ „\ð$ð
 ð>ð >ñ „\ð>ðð ð ð'ð 'ð 'ð 'ðð ð ðFð Fð Fð Fð Fr   r   c                  ón   — dt           fi f} t          j        t          g| ¢R Ž }t          j        |g| ¢R Ž  |S )NÚABCInterface)r   r   Ú__new__r   r   )Úabc_name_bases_attrsÚinstances     r   Ú_create_ABCInterfacer†     sL   € ð
 +­Y¨L¸"Ð=ÐÝ Ô(Õ):ÐRÐ=QÐRÐRÐR€HÝÔ˜HÐ<Ð';Ð<Ð<Ð<Ð<Ø€Or   )ry   Útypesr   Úzope.interfacer   r   Úzope.interface.interfacer   r   r   Ú__all__Úobjectr
   r   r†   r‚   r   r   r   ú<module>rŒ      s  ðð Ð Ð Ð Ø Ð Ð Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *Ø $Ð $Ð $Ð $Ð $Ð $Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø :Ð :Ð :Ð :Ð :Ð :ð€ð&ð &ð &ð &ð &ˆvñ &ô &ð &ð\Fð \Fð \Fð \Fð \F˜ñ \Fô \Fð \Fð~ð ð ð $Ð#Ñ%Ô%€€€r   