a
    ,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y   ddlmZ Y n0 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u r t du rddlm a  t S z
t| W S  tyX } zt|j W Y d}~n
d}~0 0 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 u rt| ||S N)queryAdapterInContextr   )object	interfacer   r   r   r   r   getAdapterInContext?   s    
r   c                 C   sv   t | dd }|d urTz||}W n& tyF   t d jd urB Y n0 |d urT|S || rb| 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 u r$t| |||S r   )r"   r   )r   r   namer   r   r   r   r   
getAdapter`   s    r%   c                 C   s*   |d u 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 u r$t| |||S N)r   )queryMultiAdapterr   )objectsr   r$   r   r   r   r   r   getMultiAdapterm   s    r*   c                 C   s4   zt |}W n ty"   | Y S 0 || |||S r   )r   r   r(   )r)   r   r$   r#   r   sitemanagerr   r   r   r(   s   s
    
r(   c                 C   s0   zt |}W n ty"   g  Y S 0 || |S r   )r   r   getAdapters)r)   Zprovidedr   r+   r   r   r   r,   }   s
    
r,   c                 C   s0   zt |}W n ty"   g  Y S 0 || |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   s0   z
t  }W n ty   Y d S 0 ||| ||S r   )r   r   r"   )r   r   r$   r#   r+   r   r   r   r&      s
    
r&   c                 C   s(   t | ||d}|d u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   sV   zt | }W n ty"   | Y S 0 |j}|D ]"}|||t}|tur.|  S q.|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u 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| ||i |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   sv   t |}|tD ]^\}}| }z|| r8||fV  W q tyn   |D ]}|| rL||fV   qjqLY q0 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`   




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