U
    ÈZjãS  ã                   @   sÒ  d Z ddlmZ ddlZddlmZ ddlmZ ddlZddlZddl	m
Z
 ddlmZ dZd	Zd
Zeƒ Zdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZeZzddlmZ W n ek
rÂ   Y nX eƒ ZG dd„ deƒZeZzddlmZ W n ek
�r   Y nX g ZzddlmZ W n ek
�r0   Y nX G dd„ deƒZG dd„ deeeƒZeddd�ZG dd „ d eƒZ G d!d"„ d"e ƒZ!d-d#d$„Z"d.d%d&„Z#d'd(„ Z$dd)l%m&Z& dd*l%m'Z' dd+l	m(Z( dd,l	m)Z) dS )/z Interface object implementation
é    )Ú
generatorsN)Ú
MethodType)ÚFunctionType)ÚInvalid)Úroé   é   Z__interface_tagged_values__c                 C   s2   t  d¡j}| ti ¡}| dg ¡}| | ¡ tS )Né   Ú
invariants)ÚsysÚ	_getframeÚf_localsÚ
setdefaultÚTAGGED_DATAÚappendÚ_decorator_non_return)Úcallr   Útagsr
   © r   ú[/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/zope/interface/interface.pyÚ	invariant"   s
    
r   c                 C   s$   t  d¡j}| ti ¡}||| < tS )z;Attaches a tagged value to an interface at definition time.r	   )r   r   r   r   r   r   )ÚkeyÚvaluer   Ztagged_valuesr   r   r   ÚtaggedValue*   s    r   c                   @   sL   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zddd„Zdd„ Z	dd„ Z
dS )ÚElementzI
    Default implementation of `zope.interface.interfaces.IElement`.
    Ú c                 C   s0   |s|  d¡dkr|}d }|| _|| _i | _d S )Nú r   )ÚfindÚ__name__Ú__doc__Ú_Element__tagged_values)Úselfr   r   r   r   r   Ú__init__<   s    zElement.__init__c                 C   s   | j S )z! Returns the name of the object. ©r   ©r!   r   r   r   ÚgetNameE   s    zElement.getNamec                 C   s   | j S )z+ Returns the documentation for the object. )r   r$   r   r   r   ÚgetDocI   s    zElement.getDocc                 C   s
   | j | S ©ú* Returns the value associated with 'tag'. ©r    )r!   Útagr   r   r   ÚgetTaggedValueM   s    zElement.getTaggedValueNc                 C   s   | j  ||¡S r'   )r    Úget)r!   r*   Údefaultr   r   r   ÚqueryTaggedValueQ   s    zElement.queryTaggedValuec                 C   s
   | j  ¡ S ©z Returns a list of all tags. )r    Úkeysr$   r   r   r   ÚgetTaggedValueTagsU   s    zElement.getTaggedValueTagsc                 C   s   || j |< dS )z  Associates 'value' with 'key'. Nr)   ©r!   r*   r   r   r   r   ÚsetTaggedValueY   s    zElement.setTaggedValue)r   )N)r   Ú
__module__Ú__qualname__r   r"   r%   r&   r+   r.   r1   r3   r   r   r   r   r   2   s   	
	
r   c                   @   s(   e Zd Zdd„ Zdd„ Zdd„ ZeZdS )ÚSpecificationBasePyc                 C   s   t |ƒ}| |jkS )z2Is the interface implemented by an object
        )Ú
providedByÚ_implied)r!   ÚobÚspecr   r   r   r7   _   s    zSpecificationBasePy.providedByc                 C   s   t |ƒ}| |jkS )z•Test whether the specification is implemented by a class or factory.

        Raise TypeError if argument is neither a class nor a callable.
        )ÚimplementedByr8   )r!   Úclsr:   r   r   r   r;   e   s    z!SpecificationBasePy.implementedByc                 C   s
   || j kS )zCIs the interface the same as or extend the given interface
        ©r8   )r!   Ú	interfacer   r   r   ÚisOrExtendsm   s    zSpecificationBasePy.isOrExtendsN)r   r4   r5   r7   r;   r?   Ú__call__r   r   r   r   r6   ]   s   r6   )ÚSpecificationBasec                   @   s$   e Zd ZdZefdd„Zdd„ ZdS )ÚInterfaceBasePyz:Base class that wants to be replaced with a C base :)
    c                 C   s\   t |ddƒ}|dk	r*|  |¡}|dk	r*|S |  |¡}|dk	r@|S |tk	rL|S td|| ƒ‚dS )z)Adapt an object to the interface
        Z__conform__NzCould not adapt)ÚgetattrÚ_call_conformÚ	__adapt__Ú_markerÚ	TypeError)r!   ÚobjZ	alternateÚconformÚadapterr   r   r   r@      s    

zInterfaceBasePy.__call__c                 C   s6   |   |¡r|S tD ]}|| |ƒ}|dk	r|  S qdS )z(Adapt an object to the reciever
        N)r7   Úadapter_hooks)r!   rH   ÚhookrJ   r   r   r   rE   ‘   s    

zInterfaceBasePy.__adapt__N)r   r4   r5   r   rF   r@   rE   r   r   r   r   rB   {   s   rB   )ÚInterfaceBase)rK   c                   @   sz   e Zd ZdZejZejZddd„Zdd„ Zdd„ Z	d	d
„ Z
edd„ e
ƒZdd„ Zdd„ Zddd„Zddd„Zddd„ZdS )ÚSpecificationaw  Specifications

    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.
    r   c                 C   s   i | _ t ¡ | _t|ƒ| _d S ©N)r8   ÚweakrefÚWeakKeyDictionaryÚ
dependentsÚtupleÚ	__bases__)r!   Úbasesr   r   r   r"   ¼   s    
zSpecification.__init__c                 C   s   | j  |d¡d | j |< d S ©Nr   r	   )rR   r,   )r!   Ú	dependentr   r   r   Ú	subscribeÁ   s    zSpecification.subscribec                 C   s@   | j  |d¡d }|s | j |= n|dkr4|| j |< nt|ƒ‚d S rV   )rR   r,   ÚKeyError)r!   rW   Únr   r   r   ÚunsubscribeÄ   s    
zSpecification.unsubscribec                 C   sB   | j D ]}| | ¡ q|| jd< |D ]}| | ¡ q$|  | ¡ d S )NrT   )rT   r[   Ú__dict__rX   Úchanged)r!   rU   Úbr   r   r   Z
__setBasesÍ   s    

zSpecification.__setBasesc                 C   s   | j  dd¡S )NrT   r   )r\   r,   r$   r   r   r   Ú<lambda>Û   ó    zSpecification.<lambda>c                 C   s²   z| ` W n tk
r   Y nX | j}| ¡  t| ƒ}zt|krH| t¡ W n tk
r^   Y nX t|ƒ| _	tdd„ |D ƒƒ| _
|D ]}d||< q‚t| j ¡ ƒD ]}| |¡ qždS )z4We, or something we depend on, have changed
        c                 S   s   g | ]}t |tƒr|‘qS r   )Ú
isinstanceÚInterfaceClass)Ú.0Úancestorr   r   r   Ú
<listcomp>ó   s    
ÿz)Specification.changed.<locals>.<listcomp>r   N)Ú_v_attrsÚAttributeErrorr8   Úclearr   Ú	Interfacer   Ú	NameErrorrS   Z__sro__Ú__iro__rR   r0   r]   )r!   Zoriginally_changedZimpliedZ	ancestorsrd   rW   r   r   r   r]   ß   s$    

zSpecification.changedc                 c   s8   i }| j D ](}| ¡ D ]}||krd||< |V  qq
dS )úDReturn an iterator for the interfaces in the specification.
        r	   N)rT   Ú
interfaces)r!   ÚseenÚbaser>   r   r   r   rm      s    
zSpecification.interfacesTc                 C   s   || j ko| p| |kS )z—Does the specification extend the given interface?

        Test whether an interface in the specification extends the
        given interface
        r=   )r!   r>   Ústrictr   r   r   Úextends  s    
þzSpecification.extendsNc                 C   s   t  | |¡S rO   )rP   Úref)r!   Úcallbackr   r   r   rP     s    zSpecification.weakrefc                 C   sz   z
| j }W n tk
r(   i  }| _ Y nX | |¡}|dkrf| jD ]"}| |¡}|dk	rB|||<  qfqB|dkrr|S |S dS )z+Query for an attribute description
        N)rf   rg   r,   rk   Údirect)r!   Únamer-   ÚattrsÚattrZifacer   r   r   r,     s    



zSpecification.get)r   )T)N)N)r   r4   r5   r   rA   r?   r7   r"   rX   r[   Z_Specification__setBasesÚpropertyrT   r]   rm   rq   rP   r,   r   r   r   r   rN   «   s    
	ý!

rN   c                   @   sð   e Zd ZdZd9dd„Zdd„ Zdd	„ Zd
d„ Zd:dd„Zdd„ Z	d;dd„Z
dd„ ZeZdd„ Zdd„ Zd<dd„Zd=dd„Zd>dd„Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ ZdS )?rb   z0Prototype (scarecrow) Interfaces Implementation.r   Nc              	   C   s®  |d kri }|d kr^|  d¡}t|tƒr0|d= n.zt d¡jd }W n ttfk
r\   Y nX || _|  d¡}|d k	r’t|t	ƒs’|d krŒ|}|d= |d kržd}t
 | ||¡ | td ¡}|d k	rÞ| ¡ D ]\}}	|  ||	¡ qÈ|D ]}
t|
tƒsâtdƒ‚qât | |¡ t| ¡ ƒD ]~\}}|dk�r.||= �qt|t	ƒ�rP| |_|j�sŽ||_n>t|tƒ�rpt|| |d�||< n|tk�r‚||= ntd	| ƒ‚�q|| _d
| j| jf | _d S )Nr4   r	   r   r   r   zExpected base interfaces)Z
__locals__r5   Ú__annotations__)ru   zConcrete attribute, ú%s.%s)r,   ra   Ústrr   r   Ú	f_globalsrg   rY   r4   Ú	Attributer   r"   Úpopr   Úitemsr3   rb   rG   rN   Úlistr>   r   r   ÚfromFunctionr   ÚInvalidInterfaceÚ_InterfaceClass__attrsZ__identifier__)r!   ru   rU   rv   r   r4   ÚdZtagged_datar   Úvalro   rw   r   r   r   r"   5  sV    







zInterfaceClass.__init__c                 c   s
   | V  dS )rl   Nr   r$   r   r   r   rm   y  s    zInterfaceClass.interfacesc                 C   s   | j S rO   )rT   r$   r   r   r   ÚgetBases~  s    zInterfaceClass.getBasesc                 C   s   | |kp|  | ¡S )zSame interface or extends?)rq   )r!   Úotherr   r   r   ÚisEqualOrExtendedBy�  s    z"InterfaceClass.isEqualOrExtendedByFc                 C   sB   |s| j  ¡ S | j  ¡ }| jD ]}| t | |¡¡¡ q| ¡ S )z4Return the attribute names defined by the interface.)rƒ   r0   ÚcopyrT   ÚupdateÚdictÚfromkeysÚnames©r!   ÚallÚrro   r   r   r   r�   …  s    


zInterfaceClass.namesc                 C   s   t | jdd�ƒS )NT)r�   )Úiterr�   r$   r   r   r   Ú__iter__‘  s    zInterfaceClass.__iter__c                 C   sP   |s| j  ¡ S i }| jddd… D ]}| t| |¡ƒ¡ q"| | j ¡ | ¡ S )z=Return attribute names and descriptions defined by interface.Néÿÿÿÿ)rƒ   r   rT   rŠ   r‹   ÚnamesAndDescriptionsrŽ   r   r   r   r”   ”  s    
z#InterfaceClass.namesAndDescriptionsc                 C   s"   |   |¡}|dk	r|S t|ƒ‚dS )z4Return the attribute description for the given name.N)r,   rY   )r!   ru   r�   r   r   r   ÚgetDescriptionFor¡  s    
z InterfaceClass.getDescriptionForc                 C   s   |   |¡d k	S rO   ©r,   ©r!   ru   r   r   r   Ú__contains__«  s    zInterfaceClass.__contains__c                 C   s   | j  |¡S rO   )rƒ   r,   r—   r   r   r   rt   ®  s    zInterfaceClass.directc                 C   s   |   ||¡S rO   r–   )r!   ru   r-   r   r   r   ÚqueryDescriptionFor±  s    z"InterfaceClass.queryDescriptionForc                 C   s¤   |   dg ¡D ]J}z||ƒ W q tk
rT } z|dkr:‚ n
| |¡ W 5 d}~X Y qX q| jD ]4}z| ||¡ W q^ tk
r�   |dkrŒ‚ Y q^X q^|r t|ƒ‚dS )z&validate object to defined invariants.r
   N)r.   r   r   rT   ÚvalidateInvariants)r!   rH   Úerrorsr   Úero   r   r   r   rš   ´  s    

z!InterfaceClass.validateInvariantsc                 C   sJ   t j| |td�}|tk	r|S | jD ]"}|j|td�}|tk	r"|  S q"|S ©r(   )r-   )r   r.   rF   rT   )r!   r*   r-   r   ro   r   r   r   r.   Ç  s    

zInterfaceClass.queryTaggedValuec                 C   s"   | j |td�}|tkrt|ƒ‚|S r�   )r.   rF   rY   r2   r   r   r   r+   Ò  s    zInterfaceClass.getTaggedValuec                 C   s>   t t | ¡ƒ}| jD ]$}| ¡ D ]}||kr | |¡ q q|S r/   )r€   r   r1   rT   r   )r!   r0   ro   r   r   r   r   r1   Ù  s    
z!InterfaceClass.getTaggedValueTagsc                 C   sX   z| j W S  tk
rR   | j}| j}|r4d||f }d| jj|f }|| _ | Y S X d S )Nrz   z<%s %s>)Z_v_reprrg   r   r4   Ú	__class__)r!   ru   Úmr�   r   r   r   Ú__repr__â  s    zInterfaceClass.__repr__c                 C   s8   z
|| ƒW S  t k
r2   t ¡ d jd k	r.‚ Y nX d S )Né   )rG   r   Úexc_infoÚtb_next)r!   rI   r   r   r   rD   î  s    
zInterfaceClass._call_conformc                 C   s   | j S rO   r#   r$   r   r   r   Ú
__reduce__  s    zInterfaceClass.__reduce__c                 C   sL   |dkrdS t | ddƒt | ddƒf}t |ddƒt |ddƒf}||k||k  S )aú  Make interfaces sortable

        TODO: It would ne nice if:

           More specific interfaces should sort before less specific ones.
           Otherwise, sort on name and module.

           But this is too complicated, and we're going to punt on it
           for now.

        For now, sort on interface and module name.

        None is treated as a pseudo interface that implies the loosest
        contact possible, no contract. For that reason, all interfaces
        sort before None.

        Nr“   r   r   r4   )rC   )r!   r‡   Zn1Zn2r   r   r   Z__cmp  s
    zInterfaceClass.__cmpc                 C   s4   | j }d|ksd|kr$t d¡ dS t| j| jfƒS )Nr4   r   z-Hashing uninitialized InterfaceClass instancer	   )r\   ÚwarningsÚwarnÚhashr   r4   )r!   r„   r   r   r   Ú__hash__#  s
    
zInterfaceClass.__hash__c                 C   s   |   |¡}|dkS ©Nr   ©Ú_InterfaceClass__cmp©r!   r‡   Úcr   r   r   Ú__eq__*  s    
zInterfaceClass.__eq__c                 C   s   |   |¡}|dkS r©   rª   r¬   r   r   r   Ú__ne__.  s    
zInterfaceClass.__ne__c                 C   s   |   |¡}|dk S r©   rª   r¬   r   r   r   Ú__lt__2  s    
zInterfaceClass.__lt__c                 C   s   |   |¡}|dkS r©   rª   r¬   r   r   r   Ú__le__6  s    
zInterfaceClass.__le__c                 C   s   |   |¡}|dkS r©   rª   r¬   r   r   r   Ú__gt__:  s    
zInterfaceClass.__gt__c                 C   s   |   |¡}|dkS r©   rª   r¬   r   r   r   Ú__ge__>  s    
zInterfaceClass.__ge__)r   NNN)F)F)N)N)N)r   r4   r5   r   r"   rm   r†   rˆ   r�   r’   r”   r•   Ú__getitem__r˜   rt   r™   rš   r.   r+   r1   r    rD   r¤   r«   r¨   r®   r¯   r°   r±   r²   r³   r   r   r   r   rb   -  s<     ÿ
D




	rb   ri   zzope.interface)r4   c                   @   s   e Zd ZdZdZdS )r}   zAttribute descriptions
    N)r   r4   r5   r   r>   r   r   r   r   r}   E  s   r}   c                   @   s`   e Zd ZdZd ZZd Z ZZdd„ Z	dd„ Z
dd	„ Zee	e
eƒZd
d„ Zdd„ Zdd„ ZdS )ÚMethodzŽMethod interfaces

    The idea here is that you have objects that describe methods.
    This provides an opportunity for rich meta-data.
    r   Nc                 C   s   | j d kri S | j S rO   ©Ú	_optionalr$   r   r   r   Ú_get_optional_  s    
zMethod._get_optionalc                 C   s
   || _ d S rO   r¶   )r!   Úoptr   r   r   Ú_set_optionalc  s    zMethod._set_optionalc                 C   s
   d | _ d S rO   r¶   r$   r   r   r   Ú_del_optionale  s    zMethod._del_optionalc                 O   s   t | j| jƒ‚d S rO   )ÚBrokenImplementationr>   r   )r!   ÚargsÚkwr   r   r   r@   i  s    zMethod.__call__c                 C   s   | j | j| j| j| jdœS )N©Ú
positionalÚrequiredÚoptionalÚvarargsÚkwargsr¿   r$   r   r   r   ÚgetSignatureInfol  s    üzMethod.getSignatureInfoc                 C   s€   g }| j D ]:}| |¡ || j ¡ kr
|d  dt| j| ƒ 7  < q
| jr\| d| j ¡ | jrr| d| j ¡ dd |¡ S )Nr“   ú=Ú*z**z(%s)z, )rÀ   r   rÂ   r0   ÚreprrÃ   rÄ   Újoin)r!   ÚsigÚvr   r   r   ÚgetSignatureStringt  s    

 zMethod.getSignatureString)r   r4   r5   r   rÀ   rÁ   r·   rÃ   rÄ   r¸   rº   r»   rx   rÂ   r@   rÅ   rÌ   r   r   r   r   rµ   Q  s   rµ   c                 C   s  |p| j }t|| jƒ}t| dd ƒp$d}| j}|j| }|j|d … }i }	|t|ƒ }
|
dk rn||
 d … }d}
|	 t	t
||
d … |ƒƒ¡ |d |… |_|d |
… |_|	|_|}|jt@ rÎ|| |_|d }nd |_|jt@ rê|| |_nd |_||_| j ¡ D ]\}}| ||¡ �q |S )NÚ__defaults__r   r   r	   )r   rµ   r   rC   Ú__code__Úco_argcountÚco_varnamesÚlenrŠ   r‹   ÚziprÀ   rÁ   rÂ   Úco_flagsÚ
CO_VARARGSrÃ   ÚCO_VARKEYWORDSrÄ   r>   r\   r   r3   )Úfuncr>   Úimlevelru   ÚmethodÚdefaultsÚcodeÚnar�   r¹   ÚnrZargnor   r   r   r   r   r�   �  s6    





r�   c                 C   s&   t | tƒr| j}n| }t||d|d�S )Nr	   )r×   ru   )ra   r   Ú__func__r�   )Úmethr>   ru   rÖ   r   r   r   Ú
fromMethod®  s    
rß   c                  C   sh   ddl m}  ddlm} | t|ƒ ddlm} | t|ƒ ddlm} | t|ƒ ddlm	} | t
|ƒ d S )Nr   )ÚclassImplements)Ú
IAttribute)ÚIMethod)Ú
IInterface)ÚISpecification)Úzope.interface.declarationsrà   Zzope.interface.interfacesrá   r}   râ   rµ   rã   rb   rä   rN   )rà   rá   râ   rã   rä   r   r   r   Ú_wire·  s    


ræ   )r;   )r7   )r‚   )r¼   )Nr   N)NN)*r   Ú
__future__r   r   Útypesr   r   r¥   rP   Zzope.interface.exceptionsr   Zzope.interface.ror   rÔ   rÕ   r   Úobjectr   r   r   r   r6   rA   Z-zope.interface._zope_interface_coptimizationsÚImportErrorrF   rB   rM   rK   rN   rb   ri   r}   rµ   r�   rß   ræ   rå   r;   r7   r‚   r¼   r   r   r   r   Ú<module>   s`   +"   0
-
	