
    obp                         d Z ddlmZmZ ddlZddlZddlmZ ddlm	Z	 ej                  rddlmZmZmZmZmZ  e	d      Zd	 Zd
 Zd Zd Zd ZddZy)zMatch wildcard filenames.
    )print_functionunicode_literalsN)partial   )LRUCache)CallableIterablePatternTextTuplei  c                     	 t         | df   }|j                  |      duS # t        $ r4 dt        |       z   dz   }t        j                  |      xt         | df<   }Y Ow xY w)zTest whether a name matches a wildcard pattern.

    Arguments:
        pattern (str): A wildcard pattern, e.g. ``"*.py"``.
        name (str): A filename.

    Returns:
        bool: `True` if the filename matches the pattern.

    T(?ms)\ZN)_PATTERN_CACHEKeyError
_translaterecompilematchpatternnamere_patress       -/usr/lib/python3/dist-packages/fs/wildcard.pyr   r      sn    C$0 <<T))  C
7++e335::c?B'&Cs     :AAc                     	 t         | df   }|j                  |      duS # t        $ rE dt        | d      z   dz   }t        j                  |t        j
                        xt         | df<   }Y `w xY w)zTest whether a name matches a wildcard pattern (case insensitive).

    Arguments:
        pattern (str): A wildcard pattern, e.g. ``"*.py"``.
        name (bool): A filename.

    Returns:
        bool: `True` if the filename matches the pattern.

    Fr   )case_sensitiver   N)r   r   r   r   r   
IGNORECASEr   r   s       r   imatchr   )   sy    S% 01 <<T))  S
75AAEI46JJsBMM4RR'(6Ss     AA.-A.c                 2    | syt        fd| D              S )aQ  Test if a name matches any of a list of patterns.

    Will return `True` if ``patterns`` is an empty list.

    Arguments:
        patterns (list): A list of wildcard pattern, e.g ``["*.py",
            "*.pyc"]``
        name (str): A filename.

    Returns:
        bool: `True` if the name matches at least one of the patterns.

    Tc              3   6   K   | ]  }t        |        y wN)r   .0r   r   s     r   	<genexpr>zmatch_any.<locals>.<genexpr>N   s     <uWd#<   anypatternsr   s    `r   	match_anyr+   =   s     <8<<<    c                 2    | syt        fd| D              S )ad  Test if a name matches any of a list of patterns (case insensitive).

    Will return `True` if ``patterns`` is an empty list.

    Arguments:
        patterns (list): A list of wildcard pattern, e.g ``["*.py",
            "*.pyc"]``
        name (str): A filename.

    Returns:
        bool: `True` if the name matches at least one of the patterns.

    Tc              3   6   K   | ]  }t        |        y wr"   )r   r#   s     r   r%   zimatch_any.<locals>.<genexpr>b   s     =vgt$=r&   r'   r)   s    `r   
imatch_anyr/   Q   s     =H===r,   c                 P    | sd S |rt        t        |       S t        t        |       S )a  Get a callable that matches names against the given patterns.

    Arguments:
        patterns (list): A list of wildcard pattern. e.g. ``["*.py",
            "*.pyc"]``
        case_sensitive (bool): If ``True``, then the callable will be case
            sensitive, otherwise it will be case insensitive.

    Returns:
        callable: a matcher that will return `True` if the name given as
        an argument matches any of the given patterns.

    Example:
        >>> from fs import wildcard
        >>> is_python = wildcard.get_matcher(['*.py'], True)
        >>> is_python('__init__.py')
        True
        >>> is_python('foo.txt')
        False

    c                      y)NT )r   s    r   <lambda>zget_matcher.<locals>.<lambda>}   s    r,   )r   r+   r/   )r*   r   s     r   get_matcherr4   e   s*    .   y(++z8,,r,   c                    |s| j                         } dt        |       }}d}||k  r| |   }|dz   }|dk(  r|dz   }n|dk(  r|dz   }n|dk(  r|}||k  r| |   d	k(  r|dz   }||k  r| |   d
k(  r|dz   }||k  r| |   d
k7  r|dz   }||k  r	| |   d
k7  r||k\  r|dz   }nY| || j                  dd      }|dz   }|d   d	k(  r	d|dd z   }n|d   dk(  rd|z   }|d|d
}n|t        j                  |      z   }||k  r|S )aU  Translate a wildcard pattern to a regular expression.

    There is no way to quote meta-characters.

    Arguments:
        pattern (str): A wildcard pattern.
        case_sensitive (bool): Set to `False` to use a case
            insensitive regex (default `True`).

    Returns:
        str: A regex equivalent to the given pattern.

    r    r   *z[^/]*?.[!]z\[\z\\^N)lowerlenreplacer   escape)r   r   inr   cjstuffs           r   r   r      sY    --/c'lqA
C
a%AJE8-C#X)C#XA1us*E1us*Ea%GAJ#-E a%GAJ#-AvEk!,,T6:E8s?%)OE1X_ 5LE"%u-		!$C5 a%6 Jr,   )T)__doc__
__future__r   r   typingr   	functoolsr   lrucacher   TYPE_CHECKINGr   r	   r
   r   r   r   r   r   r+   r/   r4   r   r2   r,   r   <module>rN      sS    8  	  	?? $*(*(=(>(->.r,   