U
    ,WN#                     @   s  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ zddlmZ W n  ek
r   ddlmZ Y nX daed9ddZdd Zd:ddZeedfddZeeddfddZeedfddZeeddfddZd;ddZd<d d!Z d"d# Z!ed=d%d&Z"ddl#Z$e$j%j%j&'e" d>d'd(Z(d?d)d*Z)d@d+d,Z*dAd-d.Z+e, Z-dBd/d0Z.dCd1d2Z/d3d4 Z0dDd5d6Z1dEd7d8Z2dS )FzZope 3 Component Architecture
    N)	Interface)implementedBy)
providedBy)IComponentArchitecture)!IComponentRegistrationConvenience)IFactory)ComponentLookupError)IComponentLookup)_BLANK)	adaptedBy)adapter)adapts)hookablec              
   C   s\   | dkr t dkrddlm a  t S z
t| W S  tk
rV } zt|j W 5 d}~X Y nX dS )z! See IComponentArchitecture.
    Nr   )base)r   Zzope.component.globalregistryr	   	TypeErrorr   args)contexterror r   5/usr/lib/python3/dist-packages/zope/component/_api.pygetSiteManager,   s    
r   c                 C   s"   t | ||}|d krt| ||S N)queryAdapterInContextr   )object	interfacer   r   r   r   r   getAdapterInContext?   s    
r   c                 C   sx   t | dd }|d k	rVz||}W n( tk
rH   t d jd k	rD Y nX |d k	rV|S || rd| S t|| |d|S )NZ__conform__    )getattrr   sysexc_infotb_nextr   r   queryAdapter)r   r   r   defaultZconformr   r   r   r   r   E   s    
r   c                 C   s(   t | ||d |}|d kr$t| |||S r   )r"   r   )r   r   namer   r   r   r   r   
getAdapter`   s    r%   c                 C   s*   |d krt || ||S t|| |||S r   )adapter_hookr   r"   )r   r   r$   r#   r   r   r   r   r"   f   s
    r"   c                 C   s(   t | |||d}|d kr$t| |||S N)r   )queryMultiAdapterr   )objectsr   r$   r   r   r   r   r   getMultiAdapterm   s    r*   c                 C   s6   zt |}W n tk
r$   | Y S X || |||S r   )r   r   r(   )r)   r   r$   r#   r   sitemanagerr   r   r   r(   s   s
    
r(   c                 C   s2   zt |}W n tk
r$   g  Y S X || |S r   )r   r   getAdapters)r)   Zprovidedr   r+   r   r   r   r,   }   s
    
r,   c                 C   s2   zt |}W n tk
r$   g  Y S X || |S r   )r   r   subscribers)r)   r   r   r+   r   r   r   r-      s
    
r-   c                  G   s   t d | d  d S r   )r   r-   )r)   r   r   r   handle   s    r.   r   c                 C   s2   z
t  }W n tk
r    Y d S X ||| ||S r   )r   r   r"   )r   r   r$   r#   r+   r   r   r   r&      s
    
r&   c                 C   s(   t | ||d}|d k	r|S t| |d S r'   )queryUtilityr   )r   r$   r   Zutilityr   r   r   
getUtility   s    r0   c                 C   s   t || ||S r   )r   r/   )r   r$   r#   r   r   r   r   r/      s    r/   c                 C   s   t || S r   )r   getUtilitiesForr   r   r   r   r   r1      s    r1   c                 C   s   t || S r   )r   getAllUtilitiesRegisteredForr2   r   r   r   r3      s    r3   c                 C   sX   zt | }W n tk
r$   | Y S X |j}|D ]"}|||t}|tk	r0|  S q0|S )zQuery for the next available utility.

    Find the next available utility providing `interface` and having the
    specified name. If no utility was found, return the specified `default`
    value.
    )r   r   	__bases__r/   _marker)r   r   r$   r#   Zsmbasesr   utilr   r   r   queryNextUtility   s    

r8   c                 C   s0   t | ||t}|tkr,tjjd||f |S )zfGet the next available utility.

    If no utility was found, a `ComponentLookupError` is raised.
    z/No more utilities for %s, '%s' have been found.)r8   r5   zopeZ	component
interfacesr   )r   r   r$   r7   r   r   r   getNextUtility   s     r;   c                 O   s   | dd}tt| |||S )zkInvoke the named factory and return the result.

    ``__factory_name`` is a positional-only argument.
    r   N)popr0   r   )Z__factory_namer   kwargsr   r   r   r   createObject   s    r>   c                 C   s   t t| | S )znReturn the interface provided by the named factory's objects

    Result might be a single interface. XXX
    )r0   r   getInterfaces)r$   r   r   r   r   getFactoryInterfaces   s    r@   c              	   c   sx   t |}|tD ]`\}}| }z|| r8||fV  W q tk
rp   |D ]}|| rN||fV   qlqNY qX qdS )zCReturn info on all factories implementing the given interface.
    N)r   r1   r   r?   ZisOrExtendsAttributeError)r   r   Zutilsr$   factoryr:   Zifacer   r   r   getFactoriesFor   s    


rC   )N)N)N)N)r   N)r   N)r   NN)N)N)r   N)r   )N)N)3__doc__r   typesZzope.interfacer   r   r   Zzope.component.interfacesr   r   r   r   r	   Zzope.component._compatr
   Zzope.component._declarationr   r   r   Zzope.hookabler   ImportErrorZzope.component.hookabler   r   r   r   r%   r"   r*   r(   r,   r-   r.   r&   Zzope.interface.interfacer9   r   Zadapter_hooksappendr0   r/   r1   r3   r   r5   r8   r;   r>   r@   rC   r   r   r   r   <module>   s`   












