
    Vh)                         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)	Interface)classImplements)InterfaceClass)_decorator_non_return)fromFunctionc                       e Zd Zd Zy)optionalc                 &    |j                   | _         y N__doc__)selfmethods     N/home/dcms/DCMS/lib/python3.12/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                   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__z   sn   		/26))$5r: ##D$u=00m_ ,DN99U#
$]3!&!7ABx8,,,>tX.>>,
 X,,.	
 1!\*&&q)//2	 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   D   K   | ]  \  }}| d |j                      yw)
Nr   ).0r2   r3   s      r   	<genexpr>z?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>   s*      K
$(AqqcAII;K
s    )r'   r(   r
   r   join)r0   r2   r3   	optionalsdocss        r   __optional_methods_to_docsz,ABCInterfaceClass.__optional_methods_to_docs   s    &+kkmOdaz!X7NQTO	O 	-A,E!H	- =

 K
,5OO,=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| d| dS )Nz`%s`_ioio`.)r   r   str)cmodr.   s      r   refz1ABCInterfaceClass.__create_class_doc.<locals>.ref   sK    ,,C::Dcnn$}$e|se1TF!$$r   z
 - c              3   .   K   | ]  } |        y wr   r   )r9   rF   rH   s     r   r:   z7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>   s      +
 F+
s   )keyz!

Known implementations are:

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

{}{}{}r   )r"   r;   sortedgetRegisteredConformersr   
splitlinesformatr   r   get,_ABCInterfaceClass__optional_methods_to_docs)r   r0   r1   implementations_docbased_on_docdocrH   s         @r   __create_class_docz$ABCInterfaceClass.__create_class_doc   s    ::	% &ll +
D88:D+
 
 7:MM   !((.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__rrV   rX   r[   s    r   __is_reverse_protocol_namez,ABCInterfaceClass.__is_reverse_protocol_name   s!     u%=$--*==r   c                 J    t        || |      }|j                  dd  |_        |S )Nr[   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   )rL   r%   r   )r   
conformersr   ignoredclss        r   __register_classesz$ABCInterfaceClass.__register_classes   sZ     %0J--/ 	
  /:O'' 	  	'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   rl   	itertoolschainsetr$   )r   r1   
registeredrl   dataregistrycachexs           r   rL   z)ABCInterfaceClass.getRegisteredConformers   s    
 ::	BX++,tH4G4G/HH  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   staticmethodrP   r,   r)   r*   r+   r    rj   rL   r   r   r   r   r   (   sf    Jb$"L  B $ $
 > >' 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     sI    
 +YL"= ((0H H<';<Or   )rq   typesr   zope.interfacer   r   zope.interface.interfacer   r   r   __all__r
   r   r   r{   r   r   r   <module>r      sM      $ * 3 : 1& &kF kF\
 $%r   