HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/zope/interface/__pycache__/interface.cpython-38.pyc
U

$
x`{��@sdZddlZddlmZddlmZddlZddlmZddlmZ	ddl
mZddlm
Zddlm
Z
d	d
dgZdZd
ZdZdZe�Ze�Zdd�Zdd�ZGdd�de�ZeZeGdd�de��ZGdd�de�ZeGdd�dee��Zegd�ZGdd
�d
e�Z Gdd�de!�Z"e"d	ee efdd i�Z#d!d"�Z$Gd#d	�d	e#�Z%e%d$d%d&�Z&d'd(�e&_'e&�(e&�e&j)e&fk�svt*�e&e _+e&e
_+Gd)d*�d*e%�Z,Gd+d,�d,e�Z-Gd-d.�d.e-�Z.d:d/d0�Z/d;d1d2�Z0d3d4�Z1dd5l2m3Z3dd6l2m4Z4dd7l
m5Z5dd8l
m6Z6dd9l2m7Z7e �(e7e7�dS)<z Interface object implementation
�N)�
MethodType)�FunctionType)�_use_c_impl)�PYTHON2)�Invalid)�ro�InterfaceClass�
Specification�
adapter_hooks��Z__interface_tagged_values__Z__interface_methods__cCs2t�d�j}|�ti�}|�dg�}|�|�tS)N��
invariants)�sys�	_getframe�f_locals�
setdefault�TAGGED_DATA�append�_decorator_non_return)�callrZtagsr�r�:/usr/lib/python3/dist-packages/zope/interface/interface.py�	invariant2s

rcCs$t�d�j}|�ti�}|||<tS)z;Attaches a tagged value to an interface at definition time.r
)rrrrrr)�key�valuerZ
tagged_valuesrrr�taggedValue:src@sXeZdZdZddd�Zdd�Zdd�Zd	d
�Zddd
�Zdd�Z	dd�Z
eZeZe	Z
dS)�ElementzI
    Default implementation of `zope.interface.interfaces.IElement`.
    �cCs0|s|�d�dkr|}d}||_||_d|_dS)N� r)�find�__name__�__doc__�_Element__tagged_values)�selfr!r"rrr�__init__LszElement.__init__cCs|jS)z! Returns the name of the object. �r!�r$rrr�getNameWszElement.getNamecCs|jS)z+ Returns the documentation for the object. )r"r'rrr�getDoc[szElement.getDoccCs|jst|��|j|S��* Returns the value associated with 'tag'. )r#�KeyError)r$�tagrrr�getTaggedValuefszElement.getTaggedValueNcCs|jr|j�||�S|Sr*)r#�get)r$r-�defaultrrr�queryTaggedValuelszElement.queryTaggedValuecCs|jr|j��SdS)z# Returns a collection of all tags. r)r#�keysr'rrr�getTaggedValueTagspszElement.getTaggedValueTagscCs|jdkri|_||j|<dS)z  Associates 'value' with 'key'. N)r#�r$r-rrrr�setTaggedValuets
zElement.setTaggedValue)r)N)r!�
__module__�__qualname__r"r%r(r)r.r1r3r5�queryDirectTaggedValueZgetDirectTaggedValue�getDirectTaggedValueTagsrrrrrBs	

rc@s,eZdZdZdd�Zdd�Zdd�ZeZdS)	�SpecificationBase)�_implied�_dependents�_bases�_v_attrs�__iro__�__sro__�__weakref__cCst|�}||jkS)z2Is the interface implemented by an object
        )�
providedByr;)r$Zob�specrrrrB�szSpecificationBase.providedBycCst|�}||jkS)z�Test whether the specification is implemented by a class or factory.

        Raise TypeError if argument is neither a class nor a callable.
        )�
implementedByr;)r$�clsrCrrrrD�szSpecificationBase.implementedBycCs
||jkS)zCIs the interface the same as or extend the given interface
        �r;)r$�	interfacerrr�isOrExtends�szSpecificationBase.isOrExtendsN)r!r6r7�	__slots__rBrDrH�__call__rrrrr:�s

r:c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�NameAndModuleComparisonMixinrcCs^||krdS|dkrdS|j|jf}z|j|jf}Wntk
rLtYSX||k||kS)a�
        Compare *self* to *other* based on ``__name__`` and ``__module__``.

        Return 0 if they are equal, return 1 if *self* is
        greater than *other*, and return -1 if *self* is less than
        *other*.

        If *other* does not have ``__name__`` or ``__module__``, then
        return ``NotImplemented``.

        .. caution::
           This allows comparison to things well outside the type hierarchy,
           perhaps not symmetrically.

           For example, ``class Foo(object)`` and ``class Foo(Interface)``
           in the same file would compare equal, depending on the order of
           operands. Writing code like this by hand would be unusual, but it could
           happen with dynamic creation of types and interfaces.

        None is treated as a pseudo interface that implies the loosest
        contact possible, no contract. For that reason, all interfaces
        sort before None.
        rN���)r!r6�AttributeError�NotImplemented)r$�otherZn1Zn2rrr�_compare�s
z%NameAndModuleComparisonMixin._comparecCs|�|�}|tkr|S|dkS�Nr�rPrN�r$rO�crrr�__lt__�s
z#NameAndModuleComparisonMixin.__lt__cCs|�|�}|tkr|S|dkSrQrRrSrrr�__le__�s
z#NameAndModuleComparisonMixin.__le__cCs|�|�}|tkr|S|dkSrQrRrSrrr�__gt__�s
z#NameAndModuleComparisonMixin.__gt__cCs|�|�}|tkr|S|dkSrQrRrSrrr�__ge__�s
z#NameAndModuleComparisonMixin.__ge__N)	r!r6r7rIrPrUrVrWrXrrrrrK�s'rKc@s^eZdZdZdZddd�Zdd�Zedd	��Ze	fd
d�Z
dd
�Zdd�Zdd�Z
dd�ZdS)�
InterfaceBasez:Base class that wants to be replaced with a C base :)
    )r!�__ibmodule__�_v_cached_hashNcCs||_||_dS�N�r!rZ)r$�name�modulerrrr%
szInterfaceBase.__init__cCst�dSr\)�NotImplementedError�r$�conformrrr�
_call_conformszInterfaceBase._call_conformcCs|jSr\)rZr'rrr�__module_property__sz!InterfaceBase.__module_property__cCstz
|j}Wntk
r"d}YnX|dk	rB|�|�}|dk	rB|S|�|�}|dk	rX|S|tk	rd|Std||��dS)z)Adapt an object to the interface
        NzCould not adapt)Z__conform__rMrc�	__adapt__�_marker�	TypeError)r$�objZ	alternaterb�adapterrrrrJs



zInterfaceBase.__call__cCs6|�|�r|StD]}|||�}|dk	r|SqdS)z(Adapt an object to the receiver
        N)rBr
)r$rh�hookrirrrre+s


zInterfaceBase.__adapt__cCs6z|jWStk
r.t|j|jf�|_YnX|jSr\)r[rM�hashr!r6r'rrr�__hash__8s
zInterfaceBase.__hash__cCs|�|�}|tkr|S|dkSrQrRrSrrr�__eq__@s
zInterfaceBase.__eq__cCs*||krdS|�|�}|tkr"|S|dkS)NFrrRrSrrr�__ne__Fs
zInterfaceBase.__ne__)NN)r!r6r7r"rIr%rc�propertyrdrfrJrerlrmrnrrrrrY�s


rYc@s�eZdZdZdZdZejZejZddd�Z	e
dd��Zdd	�Zd
d�Z
dd
�Ze
dd�e�ZeZdd�Zdd�Zdd�Zddd�Zddd�Zd dd�ZdS)!r	awSpecifications

    An interface specification is used to track interface declarations
    and component registrations.

    This class is a base class for both interfaces themselves and for
    interface specifications (declarations).

    Specifications are mutable.  If you reassign their bases, their
    relations with other specifications are adjusted accordingly.
    rNcCs2d|_d|_i|_d|_d|_d|_t|�|_dS)Nr)r<r=r;r>r?r@�tuple�	__bases__)r$�basesrrrr%hs	zSpecification.__init__cCs|jdkrt��|_|jSr\)r<�weakref�WeakKeyDictionaryr'rrr�
dependentszs

zSpecification.dependentscCs|j�|d�d|j|<dS)Nrr
)rur/r<)r$�	dependentrrr�	subscribe�szSpecification.subscribecCs\z|j|}Wntk
r*t|��YnX|d8}|sB|j|=n|dksNt�||j|<dS)Nr
r)r<rgr,ru�AssertionError)r$rv�nrrr�unsubscribe�s
zSpecification.unsubscribecCs>|jD]}|�|�q||_|D]}|�|�q |�|�dSr\)rqrzr=rw�changed)r$rr�brrrZ
__setBases�s
zSpecification.__setBasescCs|jSr\)r=r'rrr�<lambda>��zSpecification.<lambda>csV|jdd�|jD�d�}|j��dk	rR|rR|d�k	rR�fdd�|D�}|���|S)z�
        Calculate and return the resolution order for this object, using its ``__bases__``.

        Ensures that ``Interface`` is always the last (lowest priority) element.
        cSsi|]}||j�qSr)r@��.0r|rrr�
<dictcomp>�s�z0Specification._calculate_sro.<locals>.<dictcomp>)Z	base_mrosNrLcsg|]}|�k	r|�qSrr)r��x��rootrr�
<listcomp>�s�z0Specification._calculate_sro.<locals>.<listcomp>)�_do_calculate_rorq�_ROOTr)r$Zsrorr�r�_calculate_sro�s#
�

�
zSpecification._calculate_srocCs~d|_|j}|��|��}t|�|_tdd�|D��|_|D]}d||<q>t|jr^|j��nd�D]}|�	|�qdd|_dS)z�
        We, or something we depend on, have changed.

        By the time this is called, the things we depend on,
        such as our bases, should themselves be stable.
        NcSsg|]}t|t�r|�qSr��
isinstancer)r��ancestorrrrr��s
�z)Specification.changed.<locals>.<listcomp>r)
r>r;�clearr�rpr@r?r<r2r{)r$Zoriginally_changedZimpliedZ	ancestorsr�rvrrrr{�s

zSpecification.changedccs8i}|jD](}|��D]}||krd||<|Vqq
dS)�DReturn an iterator for the interfaces in the specification.
        r
N)rq�
interfaces)r$�seen�baserGrrrr�s
zSpecification.interfacesTcCs||jko|p||kS)z�Does the specification extend the given interface?

        Test whether an interface in the specification extends the
        given interface
        rF)r$rG�strictrrr�extends
s
�zSpecification.extendscCst�||�Sr\)rs�ref)r$�callbackrrrrsszSpecification.weakrefcCsd|j}|dkri}|_|�|�}|dkrT|jD]"}|�|�}|dk	r0|||<qTq0|dkr`|S|S)z+Query for an attribute description
        N)r>r/r?�direct)r$r^r0�attrs�attr�ifacerrrr/s



zSpecification.get)r)T)N)N)r!r6r7r"rIr�r:rHrBr%rorurwrzZ_Specification__setBasesrq�calculate_ror�r�r{r�r�rsr/rrrrr	Rs,

�
9 


c@s,eZdZdZdd�Zedd��Zdd�ZdS)	�_InterfaceMetaClassrcCsPt�d�jd}tjd}t|t�r.tjd}||d<t�||||�}||_	|S)Nr
r!r6rd)
rr�	f_globalsrY�__dict__r��str�type�__new__�_InterfaceMetaClass__module)rEr^rrr�r6Zmoduledescr�kindrrrr�ts


z_InterfaceMetaClass.__new__cCs|jSr\)r��rErrrr6�sz_InterfaceMetaClass.__module__cCsd|j|jfS)Nz<class '%s.%s'>)r�r!r�rrr�__repr__�s�z_InterfaceMetaClass.__repr__N)r!r6r7rIr�ror�rrrrr�)s
I
r�rIrcCs&t�d�j}|�ti�}|||j<tS)a�
    Convert a method specification to an actual method of the interface.

    This is a decorator that functions like `staticmethod` et al.

    The primary use of this decorator is to allow interface definitions to
    define the ``__adapt__`` method, but other interface methods can be
    overridden this way too.

    .. seealso:: `zope.interface.interfaces.IInterfaceDeclaration.interfacemethod`
    r
)rrrr�INTERFACE_METHODSr!r)�funcr�methodsrrr�interfacemethod�s
r�c@s�eZdZdZd/dd�Zd0dd�Zdd	�Zd
d�Zdd
�Zdd�Z	d1dd�Z
dd�Zd2dd�Zdd�Z
e
Zdd�Zdd�Zd3dd�Zd4dd �Zd5d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�ZdS)6rz�
    Prototype (scarecrow) Interfaces Implementation.

    Note that it is not possible to change the ``__name__`` or ``__module__``
    after an instance of this object has been constructed.
    Nrc	Cs�t|t�st�|pi}|�td�}|r�|�d|kr@d|�d�ini�d|krVd|d<t|t�rh|f}n|tkrxtf}n|tf}t	|�|d||�}n@t
r�|r�t|�dkr�tdd�|D��}|r�t	|d|i�jd}t
�|�S)N�
__classcell__rer
Z_CALL_CUSTOM_ADAPTz<WithCustomMethods>css$|]}tt|�t�rt|�VqdSr\)�
issubclassr�� _InterfaceClassWithCustomMethodsrrrr�	<genexpr>�s�z)InterfaceClass.__new__.<locals>.<genexpr>)r�rprx�popr��updater�r�rr��PY2�len�__mro__�_InterfaceClassBaser�)	rEr^rrr�r"r6Zneeds_custom_classZ	cls_basesZbases_with_custom_methodsrrrr��sD��
����zInterfaceClass.__new__c
	Cs,tdd�|D��std��|dkr&i}|dkrx|�d�}t|t�rJ|d=n.zt�d�jd}Wntt	fk
rvYnXt
�|||�|�d�}|dk	r�t|t�s�|dkr�|}|d=|dkr�d}t
�|||�|�td�}|dk	�r|��D]\}}	|�||	�q�t�||�|�|�|_d	||f|_dS)
Ncss|]}t|t�VqdSr\r�)r�r�rrrr��sz*InterfaceClass.__init__.<locals>.<genexpr>zExpected base interfacesr6r
r!r"r�%s.%s)�allrgr/r�r�rrr�rMr,rYr%�	Attributerr�r�itemsr5r	�_InterfaceClass__compute_attrs�_InterfaceClass__attrsZ__identifier__)
r$r^rrr�r"r6�dZtagged_datar�valrrrr%�s:




zInterfaceClass.__init__cs"�fdd���fdd�|��D�S)NcsHt|t�r�|_|jsD||_n&t|t�r8t|�|d�}ntd|��|S)N)r^zConcrete attribute, )r�r�rGr!r�fromFunction�InvalidInterface)�aname�avalr'rr�update_value!s

z4InterfaceClass.__compute_attrs.<locals>.update_valuecs,i|]$\}}|dkr|tk	r|�||��qS))Z
__locals__r7�__annotations__)r)r�r�r�)r�rrr�,s
�z2InterfaceClass.__compute_attrs.<locals>.<dictcomp>)r�)r$r�r)r$r�rZ__compute_attrss
�zInterfaceClass.__compute_attrsccs
|VdS)r�Nrr'rrrr�:szInterfaceClass.interfacescCs|jSr\)rqr'rrr�getBases?szInterfaceClass.getBasescCs||kp|�|�S)zSame interface or extends?)r�)r$rOrrr�isEqualOrExtendedByBsz"InterfaceClass.isEqualOrExtendedByFcCsB|s|j��S|j��}|jD]}|�t�|�|���q|��S)z4Return the attribute names defined by the interface.)r�r2�copyrqr��dict�fromkeys�names�r$r��rr�rrrr�Fs


zInterfaceClass.namescCst|jdd��S)NT)r�)�iterr�r'rrr�__iter__RszInterfaceClass.__iter__cCsP|s|j��Si}|jddd�D]}|�t|�|���q"|�|j�|��S)z=Return attribute names and descriptions defined by interface.NrL)r�r�rqr�r��namesAndDescriptionsr�rrrr�Us
z#InterfaceClass.namesAndDescriptionscCs"|�|�}|dk	r|St|��dS)z4Return the attribute description for the given name.N)r/r,�r$r^r�rrr�getDescriptionForbs
z InterfaceClass.getDescriptionForcCs|�|�dk	Sr\�r/�r$r^rrr�__contains__lszInterfaceClass.__contains__cCs|j�|�Sr\)r�r/r�rrrr�oszInterfaceClass.directcCs|�||�Sr\r�)r$r^r0rrr�queryDescriptionForrsz"InterfaceClass.queryDescriptionForcCst|jD]\}|�dd�D]J}z||�Wqtk
r^}z|dk	rL|�|�n�W5d}~XYqXqq|rpt|��dS)z&validate object to defined invariants.rrN)r?r8rr)r$rh�errorsr�r�errorrrr�validateInvariantsus
z!InterfaceClass.validateInvariantscCs,|jD] }|�|t�}|tk	r|Sq|S)z�
        Queries for the value associated with *tag*, returning it from the nearest
        interface in the ``__iro__``.

        If not found, returns *default*.
        )r?r8rf)r$r-r0r�rrrrr1�s


zInterfaceClass.queryTaggedValuecCs"|j|td�}|tkrt|��|S)r+)r0)r1rfr,r4rrrr.�szInterfaceClass.getTaggedValuecCs$t�}|jD]}|�|���q|S)z Returns a list of all tags. )�setr?r�r9)r$r2r�rrrr3�s
z!InterfaceClass.getTaggedValueTagscCsDz|jWStk
r>t|�}d|jj|f}||_|YSXdS)Nz<%s %s>)Z_v_reprrMr��	__class__r!r�rrrr��szInterfaceClass.__repr__cCs |j}|j}|rd||f}|S)Nr�r])r$r^�mrrr�__str__�s
zInterfaceClass.__str__cCs8z
||�WStk
r2t��djdk	r.�YnXdS)N�)rgr�exc_info�tb_nextrarrrrc�s
zInterfaceClass._call_conformcCs|jSr\r&r'rrr�
__reduce__�szInterfaceClass.__reduce__)NrNNN)rNNN)F)F)N)N)N)r!r6r7r"r�r%r�r�r�r�r�r�r�r��__getitem__r�r�r�r�r1r.r3r�r�rcr�rrrrr�s6�
3�
3






	�	Interfacezzope.interface)r6cCstfSr\)r�rrrrr}�r~r}c@seZdZdZdS)r�z_
    Marker class for interfaces with custom methods that override InterfaceClass methods.
    N)r!r6r7r"rrrrr��sr�c@s,eZdZdZdZdd�Zdd�Zdd�ZdS)	r�zAttribute descriptions
    NcCsdS)z/Return extra data to put at the end of __str__.rrr'rrr�
_get_str_info�szAttribute._get_str_infocCs<d}|jdk	r&|jjd|jjd}||jp0d|��S)Nr�.z	<unknown>)rGr6r!r�)r$Zofrrrr��s
zAttribute.__str__cCs dt|�jt|�jt|�|fS)Nz<%s.%s object at 0x%x %s>)r�r6r!�idr'rrrr��s�zAttribute.__repr__)r!r6r7r"rGr�r�r�rrrrr��s
r�c@sdeZdZdZdZZdZZZdd�Z	dd�Z
dd	�Zee	e
e�Z
d
d�Zdd
�Zdd�ZeZdS)�Methodz�Method interfaces

    The idea here is that you have objects that describe methods.
    This provides an opportunity for rich meta-data.
    rNcCs|jdkriS|jSr\��	_optionalr'rrr�
_get_optionals
zMethod._get_optionalcCs
||_dSr\r�)r$�optrrr�
_set_optionalszMethod._set_optionalcCs
d|_dSr\r�r'rrr�
_del_optionalszMethod._del_optionalcOst|j|j��dSr\)�BrokenImplementationrGr!)r$�args�kwrrrrJszMethod.__call__cCs|j|j|j|j|jd�S)N��
positional�required�optional�varargs�kwargsr�r'rrr�getSignatureInfos�zMethod.getSignatureInfocCs�g}|jD]:}|�|�||j��kr
|ddt|j|�7<q
|jr\|�d|j�|jrr|�d|j�dd�|�S)NrL�=�*z**z(%s)z, )r�rr�r2�reprr�r��join)r$�sig�vrrr�getSignatureStrings

 zMethod.getSignatureString)r!r6r7r"r�r�r�r�r�r�r�r�ror�rJr�r�r�rrrrr��s
r�cCs0|p|j}t||j�}t|dd�p$d}|j}|j|}|j|d�}i}	t|�}
|
s`t|dd�}
||
}|dkr�||d�}d}|	�t	t
||d�|���|d|�|_|d|�|_|	|_
|}|jt@r�|||_|d}nd|_|jt@r�|||_nd|_||_|j��D]\}
}|�|
|��q|S)N�__defaults__rZ__defaults_count__rr
)r!r�r"�getattr�__code__�co_argcount�co_varnamesr�r�r��zipr�r�r��co_flags�
CO_VARARGSr��CO_VARKEYWORDSr�rGr�r�r5)r�rG�imlevelr^�method�defaults�codeZnar�r�Zdefaults_countZnrZargnorrrrrr�&s<





r�cCs&t|t�r|j}n|}t||d|d�S)Nr
)rr^)r�r�__func__r�)�methrGr^r�rrr�
fromMethodZs
rcCs~ddlm}ddlm}|t|�ddlm}|t|�ddlm}|t|�ddlm	}|t
|�ddlm}|t|�dS)Nr)�classImplements)�IElement)�
IAttribute)�IMethod)�ISpecification)�
IInterface)
�zope.interface.declarationsr	�zope.interface.interfacesr
rrr�rr�r
r	rr)r	r
rrr
rrrr�_wirecs



r)rD)rB)r�)r�)�_empty)NrN)NN)8r"r�typesrrrsZzope.interface._compatrrr��zope.interface.exceptionsrZzope.interface.rorr��zope.interface�__all__rrrr��objectrrfrrrZSpecificationBasePyr:rKrYr
r	r�r�r�r�rr�r�r{r@rxr�r�r�r�r�rrrrDrBr�r�rrrrr�<module>sv�
=.NO
Xh�

3
4