
    (ph)                         S SK r S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	  / r
 " S S	5      r " S
 S\5      rS r\" 5       rg)    N)FunctionType)	Interface)classImplements)InterfaceClass)_decorator_non_return)fromFunctionc                       \ rS rSrS rSrg)optional    c                 &    UR                   U l         g N__doc__)selfmethods     Q/var/www/html/venv/lib/python3.13/site-packages/zope/interface/common/__init__.py__init__optional.__init__$   s    ~~    r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__ r   r   r
   r
       s    &r   r
   c                   p    \ rS rSrSrS r\S 5       rS r\S 5       r	\S 5       r
S rSS
 jrS rS rSrg	)ABCInterfaceClass(   a 
  
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           	      $   Xl         UR                  SS5      nUR                  SS5      nSU;  a9  [        R                  " XX#5        [        R                  XU5        [        U l        g UR                  S5      nX`l        [        U5      U l	        [        U5      U l
        USS  UR                   :X  d   X45       e[        U5      R                  5        VVs0 s H]  u  px[        U[        5      (       d  M  U R                  U5      (       a  M4  U R!                  U5      (       a  ML  XpR#                  X5      _M_     n	nnU R%                  U5      U	S'   U	R'                  U5        [        R                  " XX)5        U R                  5         g s  snnf )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   ABCInterfaceClass.__init__z   sk   		/26))$5r: ##D=00_ ,DN99U#
$]3!&!7ABx8,,,>t.>>,
 X,,.	
 /!\* 1 &&q) 1 //2	 1A**100.	 	 
 "44U;	uE;!
s   F7FF'Fc                    U R                  5        VVs0 s H  u  p[        U[        5      (       d  M  X_M      nnnU H  n[        X'   M     U(       d  gSSR	                  S UR                  5        5       5      -   nU$ s  snnf )N z)

The following methods are optional:
 - z
-c              3   H   #    U  H  u  pU S UR                    3v   M     g7f)
Nr   ).0r7   r8   s      r   	<genexpr>?ABCInterfaceClass.__optional_methods_to_docs.<locals>.<genexpr>   s&      K
,=DAqcAII;,=s    ")r,   r-   r
   r   join)r5   r7   r8   	optionalsdocss        r   __optional_methods_to_docs,ABCInterfaceClass.__optional_methods_to_docs   s}    &+kkmOmdaz!X7NTQTm	OA,EH  =

 K
,5OO,=K
 A
 
  Ps
   B B c                   ^ U R                   nS mSR                  U4S j[        U R                  5       TS9 5       5      nU(       a  SU-   nUR                  =(       d    SnUR                  5       nU(       a  US   OSnSR                  UR                  UR                  UR                  S	U5      U R                  U5      U5      nU$ )
Nc                     U R                   nU R                  nU[        R                   :X  a  SU-  $ US:X  a  SnSU SU S3$ )Nz`%s`_ioio`.)r   r   str)cmodr3   s      r   ref1ABCInterfaceClass.__create_class_doc.<locals>.ref   sK    ,,C::Dcnn$}$e|se1TF!$$r   z
 - c              3   4   >#    U  H  nT" U5      v   M     g 7fr   r   )r?   rN   rP   s     r   r@   7ABCInterfaceClass.__create_class_doc.<locals>.<genexpr>   s      +
D FFDs   )keyz!

Known implementations are:

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

{}{}{}r   )r'   rB   sortedgetRegisteredConformersr   
splitlinesformatr   r   get,_ABCInterfaceClass__optional_methods_to_docs)r   r5   r6   implementations_docbased_on_docdocrP   s         @r   __create_class_doc$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                 ~    U R                  S5      (       a  U R                  S5      (       a  gU R                  S5      $ )N__F_
startswithendswithr3   s    r   __is_private_name#ABCInterfaceClass.__is_private_name   s1    ??4  T]]4%8%8s##r   c                 T    U R                  S5      =(       a    U R                  S5      $ )N__rra   rc   rf   s    r   __is_reverse_protocol_name,ABCInterfaceClass.__is_reverse_protocol_name   s!     u%=$--*==r   c                 B    [        XUS9nUR                  SS  Ul        U$ )Nrf   r#   )r   
positional)r   functionr3   r   s       r   __method_from_function(ABCInterfaceClass.__method_from_function   s*    h48 #--ab1r   Nc                     Ub  UOU R                  5       nUb  UOU R                  nU H  nXC;   a  M
  [        X@5        M     g r   )rV   r*   r   )r   
conformersr!   ignoredclss        r   __register_classes$ABCInterfaceClass.__register_classes   sQ     %0J--/ 	
  /:O'' 	 C~C& r   c                     U R                   $ )z+
Return the ABC this interface represents.
)r'   )r   s    r   getABCABCInterfaceClass.getABC   s     zzr   c                    U R                   n [        UR                  5      [        UR                  5      -   n[        [        R                  " X R                  5      5      $ ! [         ag    SSKJn  U" U5      nUS   nUS   n[        R                  " XV5       Vs/ s H	  ow" 5       PM     Os  snf nnU Vs/ s H	  owc  M  UPM     Os  snf nn Nf = f)zb
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"   r|   	itertoolschainsetr)   )r   r6   
registeredr|   dataregistrycachexs           r   rV   )ABCInterfaceClass.getRegisteredConformers   s    
 ::	BX++,tH4G4G/HH  9??:/C/CDEE  	B &X&DAwHGE'0x'GH'G!!#'GHJH%/AZ!ZAJAJ	Bs/   +A" ":CB-,C8C	C	CC)__abcr&   __extra_classes__ignored_classesr   )NN)r   r   r   r   r   r   staticmethodrZ   r1   r.   r/   r0   r%   ry   rV   r   r   r   r   r   r   (   sf    Jb$"L  B $ $
 > >' Fr   r   c                  ~    S[         40 4n [        R                  " [        /U Q76 n[        R                  " U/U Q76   U$ )NABCInterface)r   r   __new__r   r   )abc_name_bases_attrsinstances     r   _create_ABCInterfacer     sI    
 +YL"= ((0H H<';<Or   )r   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   