o
    éT•jÐ  ã                   @   s  d Z ddlZddlZddlZddlZddlZddlZddlZg d¢Zddddœdd„Z	ddddœdd	„Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Ze d"¡Ze d#¡Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zejeed,dƒB Z dS )-zFilename globbing utility.é    N)ÚglobÚiglobÚescapeF©Úroot_dirÚdir_fdÚ	recursivec                C   s   t t| |||d�ƒS )ay  Return a list of paths matching a pathname pattern.

    The pattern may contain simple shell-style wildcards a la
    fnmatch. However, unlike fnmatch, filenames starting with a
    dot are special cases that are not matched by '*' and '?'
    patterns.

    If recursive is true, the pattern '**' will match any files and
    zero or more directories and subdirectories.
    r   )Úlistr   )Úpathnamer   r   r   © r   ú/usr/lib/python3.10/glob.pyr      s   r   c                C   s¨   t  d| |¡ t  d| |||¡ |durt |¡}n| dd… }t| |||dƒ}| r4|rRt| dd… ƒrRzt|ƒ}|rEt |f|¡}W |S W |S  t	yQ   Y |S w |S )aŒ  Return an iterator which yields the paths matching a pathname pattern.

    The pattern may contain simple shell-style wildcards a la
    fnmatch. However, unlike fnmatch, filenames starting with a
    dot are special cases that are not matched by '*' and '?'
    patterns.

    If recursive is true, the pattern '**' will match any files and
    zero or more directories and subdirectories.
    z	glob.globzglob.glob/2Nr   Fé   )
ÚsysÚauditÚosÚfspathÚ_iglobÚ_isrecursiveÚnextÚ	itertoolsÚchainÚStopIteration)r
   r   r   r   ÚitÚsr   r   r   r      s&   üþþr   c           
      c   s  � t j | ¡\}}t| ƒs-|rJ ‚|r tt|| ƒ|ƒr| V  d S tt||ƒ|ƒr+| V  d S |sM|rAt|ƒrAt||||ƒE d H  d S t	||||ƒE d H  d S || kr^t|ƒr^t
||||dƒ}n|g}t|ƒrq|rnt|ƒrnt}nt	}nt}|D ]}|t||ƒ|||ƒD ]
}	t j ||	¡V  q�qud S )NT)r   ÚpathÚsplitÚ	has_magicÚ_lexistsÚ_joinÚ_isdirr   Ú_glob2Ú_glob1r   Ú_glob0Újoin)
r
   r   r   r   ÚdironlyÚdirnameÚbasenameÚdirsÚglob_in_dirÚnamer   r   r   r   5   s<   €þÿÿÿr   c                 C   s.   t | ||ƒ}t|ƒsdd„ |D ƒ}t ||¡S )Nc                 s   s   � | ]	}t |ƒs|V  qd S ©N)Ú	_ishidden)Ú.0Úxr   r   r   Ú	<genexpr>`   s   € z_glob1.<locals>.<genexpr>)Ú_listdirr+   ÚfnmatchÚfilter)r%   Úpatternr   r$   Únamesr   r   r   r!   ]   s   r!   c                 C   s2   |rt t| |ƒ|ƒr|gS g S t| |ƒr|gS g S r*   )r   r   r   )r%   r&   r   r$   r   r   r   r"   c   s   
þr"   c                 C   ó   t | |d dƒS ©NF)r"   ©r%   r2   r   r   r   Úglob0p   ó   r7   c                 C   r4   r5   )r!   r6   r   r   r   Úglob1s   r8   r9   c                 c   s2   � t |ƒsJ ‚|d d… V  t| ||ƒE d H  d S )Nr   )r   Ú	_rlistdir)r%   r2   r   r$   r   r   r   r    y   s   €r    c              
   c   s,  � zŠd }d }|d ur"| rt j| t|d� }}n|}t| tƒr!t j}n| r'| }nt| tƒr3tt jdƒ}nt j}zJt  |¡�-}|D ]"}z|rH| ¡ rW|d urS||j	ƒV  n|j	V  W q? t
ya   Y q?w W d   ƒ n1 slw   Y  W |d ur~t  |¡ W d S W d S |d ur‹t  |¡ w w  t
y•   Y d S w )N©r   ÚASCII)r   ÚopenÚ_dir_open_flagsÚ
isinstanceÚbytesÚfsencodeÚcurdirÚscandirÚis_dirr)   ÚOSErrorÚclose)r%   r   r$   ÚfdrA   Úargr   Úentryr   r   r   Ú_iterdir€   sN   €
€
€ÿùÿ€ÿÿÿrJ   c                 C   s>   t  t| ||ƒ¡�}t|ƒW  d   ƒ S 1 sw   Y  d S r*   )Ú
contextlibÚclosingrJ   r	   )r%   r   r$   r   r   r   r   r/   ¢   s   $ÿr/   c                 c   sZ   � t | ||ƒ}|D ]!}t|ƒs*|V  | rt| |ƒn|}t|||ƒD ]}t||ƒV  q!q	d S r*   )r/   r+   r   r:   )r%   r   r$   r3   r-   r   Úyr   r   r   r:   §   s   €€ûr:   c              	   C   sB   |d u r
t j | ¡S z
t j| |d� W dS  ttfy    Y dS w )Nr;   FT)r   r   ÚlexistsÚlstatrE   Ú
ValueError)r
   r   r   r   r   r   ±   s   ýÿr   c              	   C   sL   |d u r
t j | ¡S z	t j| |d�}W n ttfy   Y dS w t |j¡S )Nr;   F)r   r   ÚisdirÚstatrE   rP   ÚS_ISDIRÚst_mode)r
   r   Ústr   r   r   r   ¼   s   ÿr   c                 C   s   | r|s| p|S t j | |¡S r*   )r   r   r#   )r%   r&   r   r   r   r   Ç   s   r   z([*?[])s   ([*?[])c                 C   s.   t | tƒrt | ¡}|d uS t | ¡}|d uS r*   )r?   r@   Úmagic_check_bytesÚsearchÚmagic_check)r   Úmatchr   r   r   r   Ð   s
   


ÿr   c                 C   s   | d dv S )Nr   )Ú.é.   r   )r   r   r   r   r+   ×   s   r+   c                 C   s   t | tƒr	| dkS | dkS )Ns   **z**)r?   r@   )r2   r   r   r   r   Ú   s   
r   c                 C   sB   t j | ¡\}} t| tƒrt d| ¡} ||  S t d| ¡} ||  S )z#Escape all special characters.
    s   [\1]z[\1])r   r   Ú
splitdriver?   r@   rV   ÚsubrX   )r
   Údriver   r   r   r   à   s   
ÿr   ÚO_DIRECTORY)!Ú__doc__rK   r   Úrer0   r   rR   r   Ú__all__r   r   r   r!   r"   r7   r9   r    rJ   r/   r:   r   r   r   ÚcompilerX   rV   r   r+   r   r   ÚO_RDONLYÚgetattrr>   r   r   r   r   Ú<module>   s<    ("


