B
    Yp                  @   s   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 yddl
mZ W n ek
rh   eZY nX G dd	 d	eZe ZejZejZ[ed
ZedZdd Zdd ZdddZdS )zFilename globbing utility.    )absolute_importN)join   )fnmatch)imapc               @   sh   e Zd ZeejZeejjZeejjZeejj	Z
dddZdddZddd	Zd
d Zdd ZdS )GlobberFNc       
   
   c   s   y|  |}W n$ tjk
r2 } zdS d}~X Y nX g }x|D ]}|| q>W ||fV  xF|D ]>}t||g|d}|s| |s`x| ||D ]
}	|	V  qW q`W dS )zA simplified version of os.walk (code copied) that uses
        ``self.listdir``, and the other local filesystem methods.

        Because we don't care about file/directory distinctions, only
        a single list is returned.
        N)sep)listdiroserrorappend_join_pathsislinkwalk)
selftopfollowlinksr   nameserritemsnamenew_pathx r   )lib/python3.7/site-packages/glob2/impl.pyr      s    


zGlobber.walkTc          	   C   s   t | ||||||S )a  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 ``include_hidden`` is True, then files and folders starting with
        a dot are also returned.
        )listiglob)r   pathnamewith_matchesinclude_hidden	recursive
norm_pathscase_sensitiver   r   r   r   glob0   s    zGlobber.globc       	      C   s*   |  |d||||}|r|S tdd |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 ``with_matches`` is True, then for each matching path
        a 2-tuple will be returned; the second element if the tuple
        will be a list of the parts of the path that matched the individual
        wildcards.

        If ``include_hidden`` is True, then files and folders starting with
        a dot are also returned.
        Tc             S   s   | d S )Nr   r   )sr   r   r   <lambda>U   s    zGlobber.iglob.<locals>.<lambda>)_iglobr   )	r   r   r   r   r    r!   r"   r   resultr   r   r   r   ?   s
    

zGlobber.iglobc          
   c   s   t |s | |r|dfV  dS tj|\}}||krVt |rV| |d||||}	n
|dfg}	xP|	D ]H\}}
x>| ||| ||||D ]"\}}t||g|d|
| fV  qW qfW dS )ai  Internal implementation that backs :meth:`iglob`.

        ``rootcall`` is required to differentiate between the user's call to
        iglob(), and subsequent recursive calls, for the purposes of resolving
        certain special cases of ** wildcards. Specifically, "**" is supposed
        to include the current directory for purposes of globbing, but the
        directory itself should never be returned. So if ** is the lastmost
        part of the ``pathname`` given the user to the root call, we want to
        ignore the current directory. For this, we need to know which the root
        call is.
        r   NF)r   )	has_magicexistsr
   pathsplitr&   resolve_patternr   )r   r   Zrootcallr   r!   r"   r   dirnamebasenamedirsZ
dir_groupsr   groupsr   r   r   r&   W   s    




zGlobber._iglobc                sT  t jd dkr&t|trPttjd n*t|trPt tsPt t  pLt   t	|s|dkrv| 
 r|dfgS n | t |gdr|dfgS g S  stj yf|dkr|rdgng }x:| j dD ](\}	 fdd	}
|t|
|	 qW d
}n
|  }W n tjk
r"   g S X |sBt|sBtdd	 |}t||||S )aw  Apply ``pattern`` (contains no path elements) to the
        literal directory in ``dirname``.

        If pattern=='', this will filter for directories. This is
        a special case that happens when the user's glob expression ends
        with a slash (in which case we only want directories). It simpler
        and faster to filter here than in :meth:`_iglob`.
        r      ASCII r   )r   z**c                s    t t d d  | gdS )Nr   )r   )r   len)r$   )r-   r   r   r   r   r%      s    z)Globber.resolve_pattern.<locals>.<lambda>*c             S   s   |  pt |  S )N)	_ishidden)r   r   r   r   r%      s    )sysversion_info
isinstancebytesr
   curdirZunicodegetfilesystemencodinggetdefaultencodingr(   isdirr)   r   r   extendmapr	   r   r6   filterr   )r   r-   patternZglobstar_with_rootr   r!   r"   r   r   entriesZ_mkabsr   )r-   r   r   r   r,      s8    



zGlobber.resolve_pattern)FN)FFTTTN)FFTTTN)__name__
__module____qualname__staticmethodr
   r	   r*   r>   r   lexistsr)   r   r#   r   r&   r,   r   r   r   r   r      s   

 
 
-r   z[*?[]s   [*?[]c             C   s(   t | trt| }n
t| }|d k	S )N)r9   r:   magic_check_bytessearchmagic_check)r$   matchr   r   r   r(      s    

r(   c             C   s   | d dkS )Nr   )..   r   )r*   r   r   r   r6      s    r6   c             C   s   t |  }|rtd||}|S )Nz\/)r   resub)pathsr   r*   r   r   r   r      s    r   )N)__doc__Z
__future__r   r7   r
   rO   os.pathr   r3   r   	itertoolsr   ImportErrorr@   objectr   Zdefault_globberr#   r   compilerK   rI   r(   r6   r   r   r   r   r   <module>   s*   
 -

