B
    [o                 @   s   d Z ddlZddlZyddlmZ W n  ek
rD   ddlmZ Y nX ddddgZd	d
 ZdddZ	eddddd Z
dddZdddZdd ZdS )a  Filename matching with shell patterns.

fnmatch(FILENAME, PATTERN) matches according to the local convention.
fnmatchcase(FILENAME, PATTERN) always takes case in account.

The functions operate by translating the pattern into a regular
expression.  They cache the compiled regular expressions for speed.

The function translate(PATTERN) returns a regular expression
corresponding to PATTERN.  (It does not compile it.)
    N)	lru_cache   filterfnmatchfnmatchcase	translatec             C   s2   |d krt d|ptj| } n|r.tj| } | S )Nz\/)resubosseppathnormcase)r   
norm_pathsr    r   ,lib/python3.7/site-packages/glob2/fnmatch.py_norm_paths   s
    r   Tc                s*    fdd| |fD \} }t | ||dS )a  Test whether FILENAME matches PATTERN.

    Patterns are Unix shell style:

    *       matches everything
    ?       matches any single character
    [seq]   matches any character in seq
    [!seq]  matches any char not in seq

    An initial period in FILENAME is not special.
    Both FILENAME and PATTERN are first case-normalized
    if the operating system requires it.
    If you don't want this, use fnmatchcase(FILENAME, PATTERN).

    :param slashes:
    :param norm_paths:
        A tri-state boolean:
        when true, invokes `os.path,.normcase()` on both paths,
        when `None`, just equalize slashes/backslashes to `os.sep`,
        when false, does not touch paths at all.

        Note that a side-effect of `normcase()` on *Windows* is that
        it converts to lower-case all matches of `?glob()` functions.
    :param case_sensitive:
        defines the case-sensitiviness of regex doing the matches
    :param sep:
        in case only slahes replaced, what sep-char to substitute with;
        if false, `os.sep` is used.

    Notice that by default, `normcase()` causes insensitive matching
    on *Windows*, regardless of `case_insensitive` param.
    Set ``norm_paths=None, case_sensitive=False`` to preserve
    verbatim mathces.
    c                s   g | ]}t | qS r   )r   ).0p)r   r   r   r   
<listcomp>A   s   zfnmatch.<locals>.<listcomp>)case_sensitive)r   )namepatr   r   r   r   )r   r   r   r      s    #   )maxsizetypedc             C   sL   t | tr(| d}t|}|d}nt| }|r8dntj}t||jS )Nz
ISO-8859-1r   )	
isinstancebytesdecoder   encoder   
IGNORECASEcompilematch)r   r   Zpat_strZres_strresflagsr   r   r   _compile_patternG   s    

r$   c       	         sf   g }t | }t||}xF| D ]>}|t | }|r ||t fdd| D f q W |S )z3Return the subset of the list NAMES that match PAT.c             3   s   | ]}t | V  qd S )N)r   )r   r   )r   r   r   r   	<genexpr>\   s    zfilter.<locals>.<genexpr>)r   r$   appendtuplegroups)	namesr   r   r   r   resultr!   r   mr   )r   r   r   r   S   s    

$c             C   s   t ||}|| dk	S )zTest whether FILENAME matches PATTERN, including case.

    This is a version of fnmatch() which doesn't case-normalize
    its arguments.
    N)r$   )r   r   r   r!   r   r   r   r   `   s    
c             C   sL  dt |  }}d}x*||k r>| | }|d }|dkrB|d }q|dkrT|d }q|dkr.|}||k r~| | d	kr~|d }||k r| | d
kr|d }x ||k r| | d
kr|d }qW ||kr|d }n^| || dd}|d }|d d	kr
d|dd  }n|d dkr d| }d||f }q|t| }qW d| d S )zfTranslate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.
    r    r   *z(.*)?z(.)[!]z\[\z\\^Nz%s([%s])z(?ms)z\Z)lenreplacer   escape)r   inr"   cjZstuffr   r   r   r   j   s8    



)TTN)TTN)T)__doc__r
   r   	functoolsr   ImportErrorcompat__all__r   r   r$   r   r   r   r   r   r   r   <module>   s   
)


