3
eb                 @   s   d Z ddlZddlZddlZdddg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ejdZej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   /usr/lib/python3.6/glob.pyr   	   s    c            C   s.   t | |d}|r*t| r*t|}| s*t|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.
    F)_iglob_isrecursivenextAssertionError)r   r   itsr   r   r	   r      s
    
c             c   s
  t jj| \}}t| sP| s"t|r:t jj| rL| V  nt jj|rL| V  d S |s|rtt|rtt|||E d H  nt	|||E d H  d S || krt|rt
||d}n|g}t|r|rt|rt}qt	}nt}x2|D ]*}x$||||D ]}t jj||V  qW qW d S )NT)ospathsplit	has_magicr   lexistsisdirr   _glob2_glob1r
   _glob0join)r   r   dironlydirnamebasenamedirsZglob_in_dirnamer   r   r	   r
   '   s2    

r
   c             C   s0   t t| |}t|s$dd |D }tj||S )Nc             s   s   | ]}t |s|V  qd S )N)	_ishidden).0xr   r   r	   	<genexpr>R   s    z_glob1.<locals>.<genexpr>)r   _iterdirr   fnmatchfilter)r   patternr   namesr   r   r	   r   O   s    r   c             C   s8   |st jj| r4|gS nt jjt jj| |r4|gS g S )N)r   r   r   r   r   )r   r   r   r   r   r	   r   U   s    r   c             C   s   t | |dS )NF)r   )r   r&   r   r   r	   glob0b   s    r(   c             C   s   t | |dS )NF)r   )r   r&   r   r   r	   glob1e   s    r)   c             c   s.   t |st|d d V  t| |E d H  d S )Nr   )r   r   	_rlistdir)r   r&   r   r   r   r	   r   k   s    r   c             c   s   | s"t | trttjd} ntj} yXtj| D}x<|D ]4}y| sJ|j rR|jV  W q6 tk
rh   Y q6X q6W W d Q R X W n tk
r   d S X d S )NASCII)
isinstancebytesr   curdirscandiris_dirr   OSError)r   r   r   entryr   r   r	   r#   r   s    

r#   c             c   sh   t t| |}xT|D ]L}t|s|V  | r8tjj| |n|}x"t||D ]}tjj||V  qHW qW d S )N)r   r#   r   r   r   r   r*   )r   r   r'   r!   r   yr   r   r	   r*      s    
r*   z([*?[])s   ([*?[])c             C   s(   t | trtj| }n
tj| }|d k	S )N)r,   r-   magic_check_bytessearchmagic_check)r   matchr   r   r	   r      s    

r   c             C   s   | d dkS )Nr   .   ..   )r8   r:   r   )r   r   r   r	   r      s    r   c             C   s   t | tr| dkS | dkS d S )Ns   **z**)r,   r-   )r&   r   r   r	   r      s    
r   c             C   s<   t jj| \}} t| tr(tjd| } ntjd| } ||  S )z#Escape all special characters.
    s   [\1]z[\1])r   r   
splitdriver,   r-   r4   subr6   )r   Zdriver   r   r	   r      s
    
)__doc__r   rer$   __all__r   r   r
   r   r   r(   r)   r   r#   r*   compiler6   r4   r   r   r   r   r   r   r   r	   <module>   s(   
(


