o
    ,W                     @   s
  d Z dZddlZddlZzddlmZ W n ey!   dd ZY nw 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 dS w 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   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   )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   sL   | d u rt  }nt| } |  }| t_|t_zt`W d S  ty%   Y d S w 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| d S t| w r   )r    r   )r   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 w r   )r   r   r	   )	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   sethookr   r)   r   r   r   setHooks|   s   r-   c                  C   s@   ddl m}  | j  | j  zt`W d S  ty   Y d S w r(   )r+   r*   r   resetr   r   r   r)   r   r   r   
resetHooks   s   


r/   )
addCleanUpr   )r#   N)r   __docformat__
contextlib	threadingzope.security.proxyr   ImportErrorzope.component.globalregistryr   zope.component.interfacesr	   r
   r%   r   localr   r   r   r    contextmanagerr   r   r   r-   r/   	clearSitezope.testing.cleanupr0   r   r   r   r   <module>   s<   



	
