o
    éT•j9  ã                   @   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 )z�Test 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¡}n„g }	| | dkr™|d n|d }
	 |  d|
|¡}
|
dk rªn|	 | ||
… ¡ |
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 < |	|
= qÜd 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 �s¢J ‚|d7 }||k�r°|dƒ nW|| |u�s¹J ‚g }||k �rÞ|| |u�rÞ| || ¡ |d7 }||k �rÞ|| |u�sÇd |¡}||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    
	
