
    e(                         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	      Z G d
 de      Zd Z e       Zy)    N)FunctionType)classImplements)	Interface)fromFunction)InterfaceClass)_decorator_non_returnc                       e Zd Zd Zy)optionalc                 &    |j                   | _         y 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                   f    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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           	          || _         |j                  dd      }|j                  dd      }d|vr;t        j                  | |||       t        j                  | ||       t        | _        y |j                  d      }|| _        t        |      | _	        t        |      | _
        |dd  |j                   k(  s	J ||f       t        |      j                         D ci c]J  \  }}t        |t              r5| j                  |      s$| j!                  |      s|| j#                  ||      L }	}}| j%                  |      |	d<   |	j'                  |       t        j                  | |||	       | j                          y c c}}w )Nextra_classesr   ignored_classesabc   r   )r   popr   r   r   $_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attrsr   r   based_onkvmethodss
             r   r   zABCInterfaceClass.__init__x   sh   		/26))$5r: ##D$u=00}oV+DN99U#
$]3!&!7ABx8,,,>tX.>>,
 X,,.	
 1!\*43I3I!3L33A6 t**1a00
 
 "44U;	udE7;!
s   AE:c                     | j                         D ci c]  \  }}t        |t              s|| }}}|D ]  }t        | |<    |syddj	                  d |j                         D              z   }|S c c}}w )N z)

The following methods are optional:
 - z
-c              3   Z   K   | ]#  \  }}d j                  ||j                         % yw)z{}
{}N)formatr   ).0r1   r2   s      r   	<genexpr>z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>   s*      K
.2aHOOAqyy)K
s   )+)r&   r'   r
   r   join)r/   r1   r2   	optionalsdocss        r   __optional_methods_to_docsz,ABCInterfaceClass.__optional_methods_to_docs   s    &+kkmOdaz!X7NQTO	O 	-A,E!H	- =

 K
6?oo6GK
 A
 
  Ps
   A3A3c                 |   | j                   }d dj                  fdt        | j                               D              }|rd|z   }|j                  xs d}|j                         }|r|d   nd}dj                  |j                  |j                  |j                  d	|      | j                  |      |      }|S )
Nc                     | j                   }| j                  }|t        j                   k(  rd|z  S |dk(  rd}dj                  ||      S )Nz`%s`_ioioz`{}.{}`)r   r   strr7   )cmodr-   s      r   refz1ABCInterfaceClass.__create_class_doc.<locals>.ref   sI    ,,C::Dcnn$}$e|##C..r   z
 - c              3   .   K   | ]  } |        y wr   r   )r8   rC   rE   s     r   r9   z7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>   s      +
 F+
s   )keyz!

Known implementations are:

 - r5   r   z&Interface for the ABC `{}.{}`.

{}{}{}r   )r!   r:   sortedgetRegisteredConformersr   
splitlinesr7   r   r   get,_ABCInterfaceClass__optional_methods_to_docs)r   r/   r0   implementations_docbased_on_docdocrE   s         @r   __create_class_docz$ABCInterfaceClass.__create_class_doc   s    ::	/ &ll +
D88:D+
 
 "IL_"_ ((.B#..0*6|AB<CC!2!2IIi.++E2	
 
r   c                 j    | j                  d      r| j                  d      ry| j                  d      S )N__F_
startswithendswithr-   s    r   __is_private_namez#ABCInterfaceClass.__is_private_name   s+    ??4 T]]4%8s##r   c                 J    | j                  d      xr | j                  d      S )N__rrR   rT   rW   s    r   __is_reverse_protocol_namez,ABCInterfaceClass.__is_reverse_protocol_name   s!     u%=$--*==r   c                 J    t        || |      }|j                  dd  |_        |S )NrW   r   )r   
positional)r   functionr-   r   s       r   __method_from_functionz(ABCInterfaceClass.__method_from_function   s,    h48 #--ab1r   Nc                 |    ||n| j                         }||n| j                  }|D ]  }||v rt        ||         y r   )rI   r$   r   )r   
conformersr   ignoredclss        r   __register_classesz$ABCInterfaceClass.__register_classes   sN     $.#9Zt?[?[?]
%4%@/dF\F\ 	'Cg~C&	'r   c                     | j                   S )z;
        Return the ABC this interface represents.
        )r!   )r   s    r   getABCzABCInterfaceClass.getABC   s     zzr   c                    | j                   }	 t        |j                        t        |j                        z   }t        t        j                  || j                              S # t        $ ra ddlm}  ||      }|d   }|d   }t        j                  ||      D cg c]	  } |        nc c}w }}|D cg c]  }||	 nc c}w }}Y w xY w)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AttributeErrorr   rh   	itertoolschainsetr#   )r   r0   
registeredrh   dataregistrycachexs           r   rI   z)ABCInterfaceClass.getRegisteredConformers   s    
 ::
	Bh445X=P=P8QQJ 9??:t/C/CDEE  	B &X&DAwHGE'0x'GH!!#HHJH%/A1=!AAJA	Bs/   +A" "9CB*)C5C=CCC)NN)r   r   r   r   r   staticmethodrL   r+   r(   r)   r*   r   rf   rI   r   r   r   r   r   '   se    J`!"F  < $ $
 > >'Fr   r   c                  z    dt         fi f} t        j                  t        g|  }t        j                  |g|   |S )NABCInterface)r   r   __new__r   r   )abc_name_bases_attrsinstances     r   _create_ABCInterfacer{     sC    
 +YL"= (():R=QRHH<';<Or   )rm   typesr   zope.interfacer   r   zope.interface.interfacer   r   r   __all__r
   r   r{   rw   r   r   r   <module>r      sM      * $ 1 3 :& &\F \F~ $%r   