U
    [e(                     @   s   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	 d	eZG d
d deZdd Ze ZdS )    N)FunctionType)classImplements)	Interface)fromFunction)InterfaceClass)_decorator_non_returnc                   @   s   e Zd Zdd ZdS )optionalc                 C   s   |j | _ d S N__doc__)selfmethod r   `/var/www/html/services/stratfitenv/lib/python3.8/site-packages/zope/interface/common/__init__.py__init__#   s    zoptional.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   sf   e Zd ZdZdd Zedd Zdd Zedd	 Zed
d Z	dd Z
dddZdd Zd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                    s   | _ |dd}|dd}d|krNt ||| t || t _d S |d}| _t| _	t| _
|dd  |j kst||f fddt| D } ||d< || t |||    d S )	Nextra_classesr   ignored_classesabc   c                    s<   i | ]4\}}t |tr |s |s| ||qS r   )
isinstancer   #_ABCInterfaceClass__is_private_name,_ABCInterfaceClass__is_reverse_protocol_name(_ABCInterfaceClass__method_from_function.0kvr   r   r   
<dictcomp>   s   
 

 z.ABCInterfaceClass.__init__.<locals>.<dictcomp>r   )r   popr   r   r   $_ABCInterfaceClass__register_classes	__class___ABCInterfaceClass__abctuple!_ABCInterfaceClass__extra_classes#_ABCInterfaceClass__ignored_classesAssertionErrorvarsitems$_ABCInterfaceClass__create_class_docupdate)r   namebasesattrsr   r   based_onmethodsr   r!   r   r   x   s(    




	
zABCInterfaceClass.__init__c                 C   sL   dd |   D }|D ]}t| |< q|s,dS dddd |  D  }|S )Nc                 S   s    i | ]\}}t |tr||qS r   )r   r   r   r   r   r   r"      s     
  z@ABCInterfaceClass.__optional_methods_to_docs.<locals>.<dictcomp> z)

The following methods are optional:
 - z
-c                 s   s    | ]\}}d ||j f V  qdS )z%s
%sNr
   r   r   r   r   	<genexpr>   s    z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>)r,   r   join)r1   	optionalsr   docsr   r   r   Z__optional_methods_to_docs   s    

z,ABCInterfaceClass.__optional_methods_to_docsc                    s   | j }dd  d fddt|   dD }|r>d| }|jpFd}| }|r\|d	 nd}d
|j|j|d|| 	||f }|S )Nc                 S   s6   | j }| j}|tj krd| S |dkr*d}d||f S )Nz`%s`_ioioz`%s.%s`)r   r   str)cmodr/   r   r   r   ref   s    
z1ABCInterfaceClass.__create_class_doc.<locals>.refz
 - c                 3   s   | ]} |V  qd S r	   r   )r   r<   r>   r   r   r5      s   z7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>)keyz!

Known implementations are:

 - r4   r   z&Interface for the ABC `%s.%s`.

%s%s%sr   )
r&   r6   sortedgetRegisteredConformersr   
splitlinesr   r   get,_ABCInterfaceClass__optional_methods_to_docs)r   r1   r2   Zimplementations_docZbased_on_docdocr   r?   r   Z__create_class_doc   s$    
 
z$ABCInterfaceClass.__create_class_docc                 C   s"   |  dr| drdS |  dS )N__F_
startswithendswithr/   r   r   r   Z__is_private_name   s    z#ABCInterfaceClass.__is_private_namec                 C   s   |  do| dS )N__rrG   rI   rL   r   r   r   Z__is_reverse_protocol_name   s    z,ABCInterfaceClass.__is_reverse_protocol_namec                 C   s"   t || |d}|jdd  |_|S )NrL   r   )r   
positional)r   functionr/   r   r   r   r   Z__method_from_function   s    z(ABCInterfaceClass.__method_from_functionNc                 C   sH   |d k	r|n|   }|d k	r |n| j}|D ]}||kr8q*t||  q*d S r	   )rB   r)   r   )r   Z
conformersr   Zignoredclsr   r   r   Z__register_classes   s    z$ABCInterfaceClass.__register_classesc                 C   s   | j S )z;
        Return the ABC this interface represents.
        )r&   r!   r   r   r   getABC   s    zABCInterfaceClass.getABCc                 C   s   | j }zt|jt|j }W n\ tk
rz   ddlm} ||}|d }|d }dd t||D }dd |D }Y nX t	t|| j
S )zz
        Return an iterable of the classes that are known to conform to
        the ABC this interface parallels.
        r   )	_get_dumpr   c                 S   s   g | ]
}| qS r   r   r   xr   r   r   
<listcomp>   s     z=ABCInterfaceClass.getRegisteredConformers.<locals>.<listcomp>c                 S   s   g | ]}|d k	r|qS r	   r   rS   r   r   r   rU     s      )r&   list_abc_registry
_abc_cacheAttributeErrorr   rR   	itertoolschainsetr(   )r   r2   
registeredrR   dataregistrycacher   r   r   rB      s    z)ABCInterfaceClass.getRegisteredConformers)NN)r   r   r   r   r   staticmethodrE   r-   r   r   r   r$   rQ   rB   r   r   r   r   r   '   s   P#




r   c                  C   s0   dt fi f} tjtf|  }tj|f|   |S )NABCInterface)r   r   __new__r   r   )Zabc_name_bases_attrsinstancer   r   r   _create_ABCInterface  s    re   )rZ   typesr   Zzope.interfacer   r   Zzope.interface.interfacer   r   r   __all__objectr   r   re   rb   r   r   r   r   <module>   s   	 `
