U
    ÌZjN#  ã                   @   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   úV/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-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)   Ú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    r1   c                 C   s   t |ƒ | ||¡S r   )r   r0   )r   r$   r#   r   r   r   r   r0   «   s    r0   c                 C   s   t |ƒ | ¡S r   )r   ÚgetUtilitiesFor©r   r   r   r   r   r2   ®   s    r2   c                 C   s   t |ƒ | ¡S r   )r   ÚgetAllUtilitiesRegisteredForr3   r   r   r   r4   ²   s    r4   c                 C   sX   zt | ƒ}W n tk
r$   | Y S X |j}|D ]"}| ||t¡}|tk	r0|  S q0|S )zËQuery 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__r0   Ú_marker)r   r   r$   r#   ÚsmÚbasesr   Úutilr   r   r   ÚqueryNextUtility¸   s    

r:   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.)r:   r6   ÚzopeÚ	componentÚ
interfacesr   )r   r   r$   r9   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)Úpopr1   r   )Z__factory_namer   Úkwargsr   r   r   r   ÚcreateObjectÚ   s    rA   c                 C   s   t t| |ƒ ¡ S )znReturn the interface provided by the named factory's objects

    Result might be a single interface. XXX
    )r1   r   ÚgetInterfaces)r$   r   r   r   r   ÚgetFactoryInterfacesâ   s    rC   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   r2   r   rB   ZisOrExtendsÚAttributeError)r   r   Úutilsr$   Úfactoryr=   Zifacer   r   r   ÚgetFactoriesForé   s    


rG   )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.interfacer;   r   Zadapter_hooksÚappendr1   r0   r2   r4   r   r6   r:   r>   rA   rC   rG   r   r   r   r   Ú<module>   s`   
ÿ
ÿ


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