U
    ,W                     @   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.
Zrestructuredtext    N)removeSecurityProxyc                 C   s   | S N )xr   r   6/usr/lib/python3/dist-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_propertyzDescriptor 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   )smZ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 )zA 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   Z__docformat__
contextlibZ	threadingZzope.security.proxyr   ImportErrorZzope.component.globalregistryr   Zzope.component.interfacesr   r	   r!   r
   Zlocalr   r   r   r   contextmanagerr   r   r   r(   r*   Z	clearSiteZzope.testing.cleanupr+   r   r   r   r   <module>   s6   


	

