a
    yŒ@h¿  ã                   @   sÐ   d 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„Z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e d¡Ze d¡Zdd„ Zd d!„ Zd"d#„ Zd$d%„ ZdS )&zFilename globbing utility.é    N)ÚglobÚiglobÚescapeF©Ú	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	   úlib/python3.9/glob.pyr      s    r   c                C   s:   t  d| |¡ t| |dƒ}|r6t| ƒr6t|ƒ}|r6J ‚|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.globF)ÚsysÚauditÚ_iglobÚ_isrecursiveÚnext)r   r   ÚitÚsr	   r	   r
   r      s    r   c                 c   s   t j | ¡\}}t| ƒsN|r J ‚|r8t j | ¡rJ| V  nt j |¡rJ| V  d S |sˆ|rrt|ƒrrt|||ƒE d H  nt|||ƒE d H  d S || kr¦t|ƒr¦t	||dƒ}n|g}t|ƒrÌ|rÆt|ƒrÆt}qÐt}nt
}|D ]&}||||ƒD ]}t j ||¡V  qäqÔd S )NT)ÚosÚpathÚsplitÚ	has_magicÚlexistsÚisdirr   Ú_glob2Ú_glob1r   Ú_glob0Újoin)r   r   ÚdironlyÚdirnameÚbasenameÚdirsZglob_in_dirÚnamer	   r	   r
   r   *   s2    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>U   ó    z_glob1.<locals>.<genexpr>)Ú_listdirr"   ÚfnmatchÚfilter)r   Úpatternr   Únamesr	   r	   r
   r   R   s    
r   c                 C   s8   |st j | ¡r4|gS nt j t j | |¡¡r4|gS g S r!   )r   r   r   r   r   )r   r   r   r	   r	   r
   r   X   s    r   c                 C   s   t | |dƒS ©NF)r   ©r   r*   r	   r	   r
   Úglob0e   s    r.   c                 C   s   t | |dƒS r,   )r   r-   r	   r	   r
   Úglob1h   s    r/   c                 c   s.   t |ƒsJ ‚|d d… V  t| |ƒE d H  d S )Nr   )r   Ú	_rlistdir)r   r*   r   r	   r	   r
   r   n   s    r   c              
   c   s    | s"t | tƒrttjdƒ} ntj} zdt | ¡�F}|D ]0}z|rF| ¡ rN|jV  W q4 tyb   Y q40 q4W d   ƒ n1 sz0    Y  W n tyš   Y d S 0 d S )NÚASCII)Ú
isinstanceÚbytesr   ÚcurdirÚscandirÚis_dirr    ÚOSError)r   r   r   Úentryr	   r	   r
   Ú_iterdiru   s    
*r9   c                 C   s<   t  t| |ƒ¡�}t|ƒW  d   ƒ S 1 s.0    Y  d S r!   )Ú
contextlibÚclosingr9   r   )r   r   r   r	   r	   r
   r'   †   s    r'   c                 c   s\   t | |ƒ}|D ]H}t|ƒs|V  | r2tj | |¡n|}t||ƒD ]}tj ||¡V  q@qd S r!   )r'   r"   r   r   r   r0   )r   r   r+   r$   r   Úyr	   r	   r
   r0   ‹   s    
r0   z([*?[])s   ([*?[])c                 C   s(   t | tƒrt | ¡}n
t | ¡}|d uS r!   )r2   r3   Ú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 d S )Ns   **z**)r2   r3   )r*   r	   r	   r
   r   ¢   s    
r   c                 C   s<   t j | ¡\}} t| tƒr(t d| ¡} nt d| ¡} ||  S )z#Escape all special characters.
    s   [\1]z[\1])r   r   Ú
splitdriver2   r3   r=   Úsubr?   )r   Zdriver	   r	   r
   r   ¨   s
    
r   )Ú__doc__r:   r   Úrer(   r   Ú__all__r   r   r   r   r   r.   r/   r   r9   r'   r0   Úcompiler?   r=   r   r"   r   r   r	   r	   r	   r
   Ú<module>   s.   (


