o
    ,W                     @   s   d 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
dZdd ZdddZdddZdddZdddZdd Zdd Zdd ZdS )zInterface utility functions
    )alsoProvides)
IInterface)getGlobalSiteManager)ComponentLookupError)queryUtility)CLASS_TYPESN c                 C   s|   | s
d|j |jf } t|st|tst| ddS |dur/|ts)t|dt|| nt}t	 }|
||| | dS )z@ Mark 'interface' as a named utilty providing 'iface_type'.
    %s.%szis not an interface or classNzis not an interface type)
__module____name__r   
providedBy
isinstancer   	TypeErrorextendsr   r   registerUtility)id	interface
iface_typeinfogsm r   :/usr/lib/python3/dist-packages/zope/component/interface.pyprovideInterface   s   




r   c                 C   s   t |d}|du rt||S )z3Return interface or raise ComponentLookupError
    N)queryInterfacer   contextr   ifacer   r   r   getInterface.   s   
r   c                 C   s   t t| |S )z$Return an interface or ``None``
    )r   r   )r   defaultr   r   r   r   7   s   r   c                 C      dd t | ||D S )Interfaces search
    c                 S      g | ]}|d  qS    r   .0
iface_utilr   r   r   
<listcomp>@       z#searchInterface.<locals>.<listcomp>searchInterfaceUtilitiesr   search_stringbaser   r   r   searchInterface=      
r.   c                 C   r   )r    c                 S   r!   )r   r   r$   r   r   r   r'   G   r(   z&searchInterfaceIds.<locals>.<listcomp>r)   r+   r   r   r   searchInterfaceIdsD   r/   r0   c                    sZ   t  }|t}r fdd|D } r$ fdd|D }|S dd |D }|S )Nc                    s&   g | ]}t |d   dkr|qS )r#   r   )getInterfaceAllDocsfindr$   )r,   r   r   r'   Q   s    
z,searchInterfaceUtilities.<locals>.<listcomp>c                    s   g | ]}|d    r|qS r"   )isOrExtendsr$   r-   r   r   r'   U   s    
c                 S   s   g | ]}|qS r   r   r$   r   r   r   r'   X   s    )r   getUtilitiesForr   lower)r   r,   r-   r   iface_utilitiesresr   )r-   r,   r   r*   K   s   
r*   c                 C   sf   d| j | jf }t| t| j g}t| r.t| D ]}|t| 	|j  qd
|S )Nr	   
)r
   r   strr6   __doc__r   r   sortedappendgetDescriptionForjoin)r   iface_iddocsnamer   r   r   r1   \   s   


r1   c                 C   s   |dkrd S t | |}|S )NNone)r   r   r   r   r   nameToInterfacei   s   
rD   c                    s^    d u rdS t |  d} fdd|D }|s jd  j S t|dks+J d| |d S )	NrC   r4   c                    s$   g | ]}| krd |j |jf qS )r	   )r
   r   )r%   r   r   r   r   r'   u   s
    z#interfaceToName.<locals>.<listcomp>.r#   zAmbiguous interface names: %sr   )r.   r
   r   len)r   r   itemsidsr   rE   r   interfaceToNameo   s   
rJ   )Nr   )N)NN)r;   zope.interfacer   zope.interface.interfacesr   zope.component.globalregistryr   zope.component.interfacesr   zope.component._apir   zope.component._compatr   r   r   r   r.   r0   r*   r1   rD   rJ   r   r   r   r   <module>   s    

	


