a
    ,ò¿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 |¡s6t|tƒs2t| dƒ‚dS |dur^| t¡sRt|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   Ú	TypeErrorZextendsr   r   ZregisterUtility)ÚidÚ	interfaceZ
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   s   dd„ t | ||ƒD ƒS )úInterfaces search
    c                 S   s   g | ]}|d  ‘qS ©é   r   ©Ú.0Z
iface_utilr   r   r   Ú
<listcomp>@   ó    z#searchInterface.<locals>.<listcomp>©ÚsearchInterfaceUtilities©r   Úsearch_stringÚbaser   r   r   ÚsearchInterface=   s    
ÿr(   c                 C   s   dd„ t | ||ƒD ƒS )r   c                 S   s   g | ]}|d  ‘qS )r   r   r   r   r   r   r!   G   r"   z&searchInterfaceIds.<locals>.<listcomp>r#   r%   r   r   r   ÚsearchInterfaceIdsD   s    
ÿr)   c                    sX   t ƒ }| t¡}ˆr.ˆ ¡ ‰‡fdd„|D ƒ}ˆ rF‡ fdd„|D ƒ}n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   )ZisOrExtendsr   ©r'   r   r   r!   U   s   ÿc                 S   s   g | ]}|‘qS r   r   r   r   r   r   r!   X   r"   )r   ZgetUtilitiesForr   Úlower)r   r&   r'   r   Z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   Ústrr-   Ú__doc__r   r   ÚsortedÚappendZgetDescriptionForÚjoin)r   Ziface_idZdocsÚnamer   r   r   r*   \   s    
ÿ
ÿr*   c                 C   s   |dkrd S t | |ƒ}|S )NÚNone)r   r   r   r   r   ÚnameToInterfacei   s    
r7   c                    s^   ˆ d u rdS t | ˆ d}‡ fdd„|D ƒ}|s>ˆ jd ˆ j S t|ƒdksVJ d| ƒ‚|d S )	Nr6   r,   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   ÚitemsZidsr   r8   r   ÚinterfaceToNameo   s    
ÿr<   )Nr   )N)NN)NN)NN)r1   Zzope.interfacer   Zzope.interface.interfacesr   Zzope.component.globalregistryr   Zzope.component.interfacesr   Zzope.component._apir   Zzope.component._compatr   r   r   r   r(   r)   r$   r*   r7   r<   r   r   r   r   Ú<module>   s   
	



