U
    Íø.e­  ã                   @  sî   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ eeegef 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œdd„Zddœdd„Zeƒ  eƒ  e d¡ edƒD ]\ZZeejfežŽ  qÐdS )zPattern matching registry.é    )Úannotations)Úfnmatch)Úmatch)ÚCallableÚcasté   )Ú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-48hrr5dg/kombu/matcher.pyr
      s   r
   c                   @  sr   e Zd ZdZeZdgZddœdd„Zdddd	œd
d„Zdddœdd„Zdddœdd„Z	dddddddœdd„Z
dS )ÚMatcherRegistryz#Pattern matching function registry.ÚpcreÚNone©Úreturnc                 C  s   i | _ d | _d S )N)Ú	_matchersÚ_default_matcher)Úselfr   r   r   Ú__init__   s    zMatcherRegistry.__init__ÚstrÚMatcherFunction)ÚnameÚmatcherr   c                 C  s   || j |< dS )z$Add matcher by name to the registry.N)r   )r   r   r   r   r   r   Úregister   s    zMatcherRegistry.register)r   r   c                 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_matcherNÚbytesz
str | Nonezdict[str, str] | NoneÚbool)ÚdataÚpatternr   Úmatcher_kwargsr   c                 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   r'   r(   r   r)   Z
match_funcZ	first_argZ
second_argr   r   r   r   ;   s    ÿ

zMatcherRegistry.match)NN)r   r   r   r   r
   r,   r   r   r#   r$   r   r   r   r   r   r      s   	  ûr   r   r   c                   C  s   t  dt¡ dS )z$Register glob into default registry.r*   N)Úregistryr   r   r   r   r   r   Úregister_glob}   s    r.   c                   C  s   t  dtttƒ¡ dS )z$Register pcre into default registry.r   N)r-   r   r   r   Úrematchr   r   r   r   Úregister_pcre‚   s    r0   r*   zkombu.matchersN)r   Ú
__future__r   r   Úrer   r/   Útypingr   r   Zutils.compatr   Zutils.encodingr	   r   r&   r   Ú	Exceptionr
   r   r-   r   r#   r.   r0   r$   ÚepÚargsr   r   r   r   r   Ú<module>   s(   ?	
