U
    ‰d2  ã                   @   s¶   d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd„ de	ƒZ
G d	d
„ d
ƒZeƒ ZejZejZejZdd„ Zdd„ Zeƒ  eƒ  e d¡ edƒD ]\ZZeejfežŽ  q˜dS )zPattern matching registry.é    )Úfnmatch)Úmatché   )Úentrypoints)Úbytes_to_strc                   @   s   e Zd ZdZdS )ÚMatcherNotInstalledzMatcher not installed/found.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú1/tmp/pip-unpacked-wheel-hqfrjlvz/kombu/matcher.pyr   
   s   r   c                   @   sD   e Zd ZdZeZdgZdd„ Zdd„ Zdd„ Zd	d
„ Z	ddd„Z
dS )ÚMatcherRegistryz#Pattern matching function registry.Úpcrec                 C   s   i | _ d | _d S )N)Ú	_matchersÚ_default_matcher)Úselfr   r   r   Ú__init__   s    zMatcherRegistry.__init__c                 C   s   || j |< dS )z$Add matcher by name to the registry.N)r   )r   ÚnameÚmatcherr   r   r   Úregister   s    zMatcherRegistry.registerc                 C   s:   z| j  |¡ W n$ tk
r4   |  d|› ¡‚Y nX dS )z)Remove matcher by name from the registry.úNo matcher installed for N)r   ÚpopÚKeyErrorr   ©r   r   r   r   r   Ú
unregister   s    ÿzMatcherRegistry.unregisterc                 C   s:   z| j | | _W n$ tk
r4   |  d|› ¡‚Y nX dS )aH  Set the default matching method.

        :param name: The name of the registered matching method.
            For example, `glob` (default), `pcre`, or any custom
            methods registered using :meth:`register`.

        :raises MatcherNotInstalled: If the matching method requested
            is not available.
        r   N)r   r   r   r   r   r   r   r   Ú_set_default_matcher%   s    
ÿz$MatcherRegistry._set_default_matcherNc                 C   sl   |r | j  |¡s |  d|› ¡‚| j |p*d }|| jkrJt|ƒ}t|ƒ}nt|ƒ}t|ƒ}|||f|phi ŽS )zCall the matcher.r   Úglob)r   Úgetr   Úmatcher_pattern_firstr   )r   ÚdataÚpatternr   Zmatcher_kwargsZ
match_funcZ	first_argZ
second_argr   r   r   r   6   s    ÿ

zMatcherRegistry.match)NN)r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r      s   	r   c                   C   s   t  dt¡ dS )z$Register glob into default registry.r   N)Úregistryr   r   r   r   r   r   Úregister_globr   s    r#   c                   C   s   t  dt¡ dS )z$Register pcre into default registry.r   N)r"   r   Úrematchr   r   r   r   Úregister_pcrew   s    r%   r   zkombu.matchersN)r   r   Úrer   r$   Zutils.compatr   Zutils.encodingr   Ú	Exceptionr   r   r"   r   r   r#   r%   r   ÚepÚargsr   r   r   r   r   Ú<module>   s"   9	
