o
    f9                     @   s|   d Z ddlZddlZddlZddlZg dZddlmZ e jZ	[dd Z
ejddd	d
d Zdd Z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)filterfnmatchfnmatchcase	translate)countc                 C   s"   t j| } t j|}t| |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).
    )ospathnormcaser   )namepat r   /usr/lib/python3.10/fnmatch.pyr      s   
r      T)maxsizetypedc                 C   s<   t | trt| d}t|}t|d}nt| }t|jS )Nz
ISO-8859-1)
isinstancebytesstrr   recompilematch)r   pat_strres_strresr   r   r   _compile_pattern,   s   

r   c                 C   sj   g }t j|}t|}t jtu r!| D ]}||r|| q|S | D ]}|t j|r2|| q#|S )zJConstruct a list from those elements of the iterable NAMES that match PAT.)r   r   r	   r   	posixpathappend)namesr   resultr   r
   r   r   r   r   6   s   


r   c                 C   s   t |}|| du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   F   s   r   c                 C   s2  t  }g }|j}dt| }}||k r]| | }|d }|dkr.|r(|d |ur,|| n+|dkr8|d n!|dkrR|}||k rM| | dkrM|d }||k r[| | d	kr[|d }||k rs| | d	krs|d }||k rs| | d	kse||kr||d
 n| || }d|vr|dd}ng }	| | dkr|d n|d }
	 | d|
|}
|
dk rn|	| ||
  |
d }|
d }
q| || }|r|	| n|	d  d7  < tt|	d ddD ]*}
|	|
d  d |	|
 d kr|	|
d  dd |	|
 dd  |	|
d < |	|
= qddd |	D }tdd|}|d }|s$|d n5|dkr.|d n+|d dkr>d|dd  }n|d dv rId| }|d| d	 n|t	| ||k s||ksdJ |}g }|j}dt|}}||k r|| |ur|||  |d7 }||k r|| |us~||k r|| |u sJ |d7 }||kr|d nW|| |usJ g }||k r|| |ur|||  |d7 }||k r|| |usd|}||kr|d || nt
 }|d| d| d| d ||k s||ksJ d|}d| d S )!zfTranslate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.
    r      *?.[!]z\[-\\\   T   Nc                 s   s$    | ]}| d d ddV  qdS )r(   r)   r'   z\-N)replace).0sr   r   r   	<genexpr>   s    ztranslate.<locals>.<genexpr>z([&~|])z\\\1z(?!)^)r0   r$   z.* z(?=(?P<gz>.*?z))(?P=g)z(?s:z)\Z)objectr   lenr,   findrangejoinr   subescape_nextgroupnum)r   STARr   addincjstuffchunkskchunkinpfixedgroupnumr   r   r   r   P   s   


,



@






r   )__doc__r   r   r   	functools__all__	itertoolsr   __next__r:   r   	lru_cacher   r   r   r   r   r   r   r   <module>   s    
	
