a
    ,W                     @   s
  d Z dZddlZddlZzddlmZ W n eyB   dd ZY n0 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 y   Y n
0 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 u 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   sL   | d u rt  }nt| } |  }| t_|t_zt`W n tyF   Y n0 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   s0   t  }t|  zd V  W t| n
t| 0 d S r   )r   r   )r   Zold_siter   r   r   r   V   s
    r   c                 C   s&   | du 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   s.   zt | |||W S  ty(   | Y S 0 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   s@   ddl m}  | j  | j  zt`W n ty:   Y n0 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   


	

