
    /Jf(                         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dS )    N)FunctionType)	Interface)classImplements)InterfaceClass)_decorator_non_return)fromFunctionc                       e Zd Zd ZdS )optionalc                     |j         | _         d S N)__doc__)selfmethods     a/home/alex/cs2snipeproduction/venv/lib/python3.11/site-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!\**

 483I3I!3L3L
 33A66
 t**1a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__y   sq   		/266))$5r:: #D$u===00}oVVV+DNF99U##
$]33!&!7!7ABBx8,,,,tX.>,,,
 
 
 
 X,,..	
 
 
 "44U;;	udE7;;;!!!!!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Odaz!X7N7NOQOOOr    z)

The following methods are optional:
 - z
-c              3   R   K   | ]"\  }}d                      ||j                  V  #dS )z{}
{}N)formatr   r9   s      r   	<genexpr>z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>   sO       K
 K
.2aHOOAqy))K
 K
 K
 K
 K
 K
r   )r/   r   join)r4   	optionalsr$   docss       r   __optional_methods_to_docsz,ABCInterfaceClass.__optional_methods_to_docs   s    OOekkmmOOO	 	- 	-A,E!HH 	2=

 K
 K
6?oo6G6G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        |j        |	                    d	|          | 
                    |          |          }|S )
Nc                     | j         }| j        }|t          j         k    rd|z  S |dk    rd}d                    ||          S )Nz`%s`_ioioz`{}.{}`)r   r   strr<   )cmodr2   s      r   refz1ABCInterfaceClass.__create_class_doc.<locals>.ref   sK    ,C:Dcn$$}$e||##C...r   z
 - c              3   .   K   | ]} |          V  d S r   r   )r#   rG   rI   s     r   r=   z7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>   s?       +
 +
 CFF+
 +
 +
 +
 +
 +
r   )keyz!

Known implementations are:

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

{}{}{}r   )r*   r>   sortedgetRegisteredConformersr   
splitlinesr<   r   r   get,_ABCInterfaceClass__optional_methods_to_docs)r   r4   r5   implementations_docbased_on_docdocrI   s         @r   __create_class_docz$ABCInterfaceClass.__create_class_doc   s   :	/ 	/ 	/ &ll +
 +
 +
 +
D88::DDD+
 +
 +
 
 
  	`"IL_"_ (.B#..00*6>|AB<CC!2IIi..++E22	
 
 
r   c                     |                      d          r|                     d          rdS |                      d          S )N__F_
startswithendswithr2   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__rrV   rX   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   functionr2   r   s       r   __method_from_functionz(ABCInterfaceClass.__method_from_function   s1    h4888 #-abb1r   Nc                     ||n|                                  }||n| j        }|D ]}||v rt          ||            d S r   )rM   r-   r   )r   
conformersr   ignoredclss        r   __register_classesz$ABCInterfaceClass.__register_classes   sg     $.#9ZZt?[?[?]?]
%4%@//dF\ 	' 	'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   rn   s     r   rp   z=ABCInterfaceClass.getRegisteredConformers.<locals>.<listcomp>  s    AAA1=!===r   )r*   list_abc_registry
_abc_cacheAttributeErrorr   rl   	itertoolschainsetr,   )r   r5   
registeredrl   dataregistrycaches          r   rM   z)ABCInterfaceClass.getRegisteredConformers   s    
 :
	Bh455X=P8Q8QQJJ 	B 	B 	B &%%%%%9X&&DAwHGEHHyx'G'GHHHJAAZAAAJJJ	B 9?:t/CDDEEEs   )3 ABB)NN)r   r   r   r   r   staticmethodrP   r0   r    r!   r"   r(   rj   rM   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    
 +YL"= ():R=QRRRHH<';<<<<Or   )rv   typesr   zope.interfacer   r   zope.interface.interfacer   r   r   __all__r
   r   r   r   r   r   r   <module>r      s             $ $ $ $ $ $ * * * * * * 3 3 3 3 3 3 : : : : : : 1 1 1 1 1 1& & & & & & & &\F \F \F \F \F \F \F \F~   $#%%r   