
    tf)                         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     ]/var/www/surfInsights/venv3-11/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!\**
 &&q))
 //22
 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__z   sz   		/266))$5r:: #D$u===00m_   ,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   4   K   | ]\  }}| d |j          V  dS )
Nr   r:   s      r   	<genexpr>z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>   sO       K
 K
$(AqqAI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OekkmmOOO	 	- 	-A,E!HH 	2=

 K
 K
,5OO,=,=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         }| 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   sN    ,C:Dcn$$}$e||$s$$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FF+
 +
 +
 +
 +
 +
r   )keyz!

Known implementations are:

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

{}{}{}r   )r+   r?   sortedgetRegisteredConformersr   
splitlinesformatr   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   :	% 	% 	% &ll +
 +
 +
 +
D88::DDD+
 +
 +
 
 
  	7:MM   !(.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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__rrZ   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 #-abb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   ss     %0JJ--// 	
  /:OO' 	  	' 	'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   rr   s     r   rt   z=ABCInterfaceClass.getRegisteredConformers.<locals>.<listcomp>  s    AAA1=!===r   )r+   list_abc_registry
_abc_cacheAttributeErrorr   rp   	itertoolschainsetr-   )r   r6   
registeredrp   dataregistrycaches          r   rP   z)ABCInterfaceClass.getRegisteredConformers   s    
 :	BX+,,tH4G/H/HH J  	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   staticmethodrT   r1   r!   r"   r#   r)   rn   rP   r   r   r   r   r   (   s        J Jb$" $" $"L   \  B $ $ \$
 > > \>  ' ' ' '   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     sV    
 +YL"= (0  H H<';<<<<Or   )rz   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& & & & & & & &kF kF kF kF kF kF kF kF\
 
 
 $#%%r   