U
    ÌZj¶  ã                   @   s  d Z dZddlZddlZzddlmZ W n ek
rD   dd„ ZY nX ddlmZ ddl	m
Z
 dd	l	mZ G d
d„ deƒZG dd„ dejƒZeƒ Zddd„Zdd„ Zejdd„ ƒZddd„Zd dd„Zdd„ Zdd„ ZeZzddlmZ W n ek
�r    Y n
X eeƒ dS )!zEHooks for getting and setting a site in the thread global namespace.
Úrestructuredtexté    N)ÚremoveSecurityProxyc                 C   s   | S ©N© )Úxr   r   úW/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/zope/component/hooks.pyr      s    r   )ÚgetGlobalSiteManager)ÚComponentLookupError)ÚIComponentLookupc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Úread_propertyzÁDescriptor for property-like computed attributes.

    Unlike the standard 'property', this descriptor allows assigning a
    value to the instance, shadowing the property getter function.
    c                 C   s
   || _ d S r   ©Úfunc)Úselfr   r   r   r   Ú__init__&   s    zread_property.__init__c                 C   s   |d kr| S |   |¡S r   r   )r   ÚinstÚclsr   r   r   Ú__get__)   s    zread_property.__get__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r       s   r   c                   @   s"   e Zd ZdZeƒ Zedd„ ƒZdS )ÚSiteInfoNc                 C   s   | j jj}|| _|S r   )ÚsmÚadaptersÚadapter_hook)r   r   r   r   r   r   3   s    
zSiteInfo.adapter_hook)r   r   r   Úsiter   r   r   r   r   r   r   r   r   /   s   r   c                 C   sN   | d krt ƒ }nt| ƒ} |  ¡ }| t_|t_zt`W n tk
rH   Y nX d S r   )r   r   ÚgetSiteManagerÚsiteinfor   r   r   ÚAttributeError)r   r   r   r   r   ÚsetSite;   s    
r   c                   C   s   t jS r   )r   r   r   r   r   r   ÚgetSiteR   s    r    c                 c   s(   t ƒ }t| ƒ z
d V  W 5 t|ƒ X d S r   )r    r   )r   Zold_siter   r   r   r   V   s
    
r   c                 C   s&   | dkrt jS t| tƒ ƒ}t|ƒ}|S )z‘A special hook for getting the site manager.

    Here we take the currently set site into account to find the appropriate
    site manager.
    N)r   r   r
   r   r   )Úcontextr   r   r   r   r   `   s     ÿr   Ú c                 C   s0   zt  | |||¡W S  tk
r*   | Y S X d S r   )r   r   r	   )Z	interfaceÚobjectÚnameÚdefaultr   r   r   r   u   s    r   c                  C   s(   ddl m}  | j t¡ | j t¡ d S ©Nr   ©Ú_api)Úzope.componentr(   r   Zsethookr   r'   r   r   r   ÚsetHooks|   s    r*   c                  C   sB   ddl m}  | j ¡  | j ¡  zt`W n tk
r<   Y nX d S r&   )r)   r(   r   Úresetr   r   r   r'   r   r   r   Ú
resetHooks�   s    

r,   )Ú
addCleanUp)N)N)r"   N)r   Ú__docformat__Ú
contextlibÚ	threadingZzope.security.proxyr   ÚImportErrorZzope.component.globalregistryr   Zzope.component.interfacesr	   r
   r#   r   Úlocalr   r   r   r    Úcontextmanagerr   r   r   r*   r,   Z	clearSiteZzope.testing.cleanupr-   r   r   r   r   Ú<module>   s6   


	

