509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
y¾œb€4  ã               @   s¢  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mZ d dl	m
Z
 ddlmZ ddlmZ ddlmZ dd	„ Zd5d
d„Zdd„ ZG dd„ de jƒZG dd„ de jƒZG dd„ deƒZG dd„ dƒZdd„ ZG dd„ dƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG d d!„ d!eƒZG d"d#„ d#eƒZeeeeehZe d$d%„ eD ƒƒZ!ed&d'ƒZ"G d(d)„ d)e
ƒZ#d*d+„ Z$d,d-„ Z%ed.fd/d0„Z&efd1d2„Z'efd3d4„Z(dS )6é    N)Ú
namedtuple)ÚEnumé   )Úshellpattern)Úclean_lines)ÚErrorc             C   sH   t | |d�}|jtjkr&|j|jƒ n|jtjkr:|j}n
|j|ƒ |S )zKParse a pattern-file line and act depending on which command it represents.)Úfallback)Úparse_inclexcl_commandÚcmdÚ	IECommandÚRootPathÚappendÚvalÚPatternStyle)ÚlineÚrootsÚie_commandsr   Z
ie_command© r   ú /usr/lib64/python3.6/patterns.pyÚparse_patternfile_line   s    
r   c             C   s0   |d krt }xt| ƒD ]}t||||ƒ}qW d S )N)ÚShellPatternr   r   )Úfileobjr   r   r   r   r   r   r   Úload_pattern_file   s    r   c             C   s$   xt | ƒD ]}|jt|ƒƒ q
W d S )N)r   r   Úparse_exclude_pattern)r   ÚpatternsZ
patternstrr   r   r   Úload_exclude_file#   s    r   c                   s(   e Zd Zd‡ fdd„	Zddd„Z‡  ZS )	ÚArgparsePatternActionr   c                s   t ƒ jf d|i|—Ž d S )NÚnargs)ÚsuperÚ__init__)Úselfr   Úkw)Ú	__class__r   r   r   )   s    zArgparsePatternAction.__init__Nc             C   s   t |d |j|jtƒ d S )Nr   )r   Úpathsr   r   )r    ÚparserÚargsÚvaluesÚoption_stringr   r   r   Ú__call__,   s    zArgparsePatternAction.__call__)r   )N)Ú__name__Ú
__module__Ú__qualname__r   r(   Ú__classcell__r   r   )r"   r   r   (   s   r   c                   s0   e Zd Zd	‡ fdd„	Zd
dd„Zdd„ Z‡  ZS )ÚArgparsePatternFileActionr   c                s   t ƒ jf d|i|—Ž d S )Nr   )r   r   )r    r   r!   )r"   r   r   r   1   s    z"ArgparsePatternFileAction.__init__Nc             C   s`   |d }y$t |ƒ�}| j||ƒ W dQ R X W n. tk
rZ } ztt|ƒƒ‚W Y dd}~X nX dS )z�Load and parse patterns from a file.
        Lines empty or starting with '#' after stripping whitespace on both line ends are ignored.
        r   N)ÚopenÚparseÚFileNotFoundErrorr   Ústr)r    r$   r%   r&   r'   ÚfilenameÚfÚer   r   r   r(   4   s    
z"ArgparsePatternFileAction.__call__c             C   s   t ||j|jƒ d S )N)r   r#   r   )r    Úfobjr%   r   r   r   r/   ?   s    zArgparsePatternFileAction.parse)r   )N)r)   r*   r+   r   r(   r/   r,   r   r   )r"   r   r-   0   s   
r-   c               @   s   e Zd Zdd„ ZdS )ÚArgparseExcludeFileActionc             C   s   t ||jƒ d S )N)r   r   )r    r5   r%   r   r   r   r/   D   s    zArgparseExcludeFileAction.parseN)r)   r*   r+   r/   r   r   r   r   r6   C   s   r6   c               @   sR   e Zd ZdZ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S )ÚPatternMatcherz¥Represents a collection of pattern objects to match paths against.

    *fallback* is a boolean value that *match()* returns if no matching patterns are found.

    Nc             C   s@   g | _ || _i | _d | _d| _g | _tjdtjdtj	di| _
d S )NTF)Ú_itemsr   Ú_path_full_patternsÚrecurse_dirÚrecurse_dir_defaultÚinclude_patternsr   ÚExcludeÚExcludeNoRecurseÚIncludeÚis_include_cmd)r    r   r   r   r   r   N   s    zPatternMatcher.__init__c             C   s   t | jƒ ot | jƒ S )N)Úlenr8   r9   )r    r   r   r   Úemptyi   s    zPatternMatcher.emptyc             C   s0   t |tƒr|j}|| j|< n| jj||fƒ dS )z%*cmd* is an IECommand value.
        N)Ú
isinstanceÚPathFullPatternÚpatternr9   r8   r   )r    rE   r
   Úkeyr   r   r   Ú_addl   s    
zPatternMatcher._addc             C   s   x|D ]}| j ||ƒ qW dS )z¼Add list of patterns to internal list. *cmd* indicates whether the
        pattern is an include/exclude pattern, and whether recursion should be
        done on excluded folders.
        N)rG   )r    r   r
   rE   r   r   r   Úaddu   s    
zPatternMatcher.addc             C   s.   dd„ |D ƒ}| j |tjƒ | | _|| _dS )zHUsed to add inclusion-paths from args.paths (from commandline).
        c             S   s   g | ]}t |tƒ‘qS r   )Úparse_patternÚPathPrefixPattern)Ú.0Úpr   r   r   ú
<listcomp>€   s    z3PatternMatcher.add_includepaths.<locals>.<listcomp>N)rH   r   r?   r   r<   )r    Zinclude_pathsr<   r   r   r   Úadd_includepaths}   s    zPatternMatcher.add_includepathsc             C   s   dd„ | j D ƒS )zBNote that this only returns patterns added via *add_includepaths*.c             S   s   g | ]}|j d kr|‘qS )r   )Úmatch_count)rK   rL   r   r   r   rM   ‡   s    zAPatternMatcher.get_unmatched_include_patterns.<locals>.<listcomp>)r<   )r    r   r   r   Úget_unmatched_include_patterns…   s    z-PatternMatcher.get_unmatched_include_patternsc             C   s"   x|D ]\}}| j ||ƒ qW dS )zBAdd list of patterns (of type CmdTuple) to internal list.
        N)rG   )r    r   rE   r
   r   r   r   Úadd_inclexcl‰   s    zPatternMatcher.add_inclexclc             C   sz   t |ƒ}tƒ }| jj||ƒ}||k	r8t|ƒ| _| j| S x2| jD ](\}}|j|dd�r@|j| _| j| S q@W | j	| _| j
S )zÐReturn True or False depending on whether *path* is matched.

        If no match is found among the patterns in this matcher, then the value
        in self.fallback is returned (defaults to None).

        F)Ú	normalize)Únormalize_pathÚobjectr9   ÚgetÚcommand_recurses_dirr:   r@   r8   Úmatchr;   r   )r    ÚpathZnon_existentÚvaluerE   r
   r   r   r   rW   �   s    

zPatternMatcher.match)N)r)   r*   r+   Ú__doc__r   rB   rG   rH   rN   rP   rQ   rW   r   r   r   r   r7   H   s   
	r7   c             C   s   t jdkrtjd| ƒS | S )z=normalize paths for MacOS (but do nothing on other platforms)ÚdarwinZNFD)ÚsysÚplatformÚunicodedatarR   )rX   r   r   r   rS   «   s    rS   c               @   sH   e Zd ZdZeZddd„Zddd„Zdd	„ Zd
d„ Z	dd„ Z
dd„ ZdS )ÚPatternBasez3Shared logic for inclusion/exclusion patterns.
    Fc             C   s(   || _ d| _t|ƒ}| j|ƒ || _d S )Nr   )Úpattern_origrO   rS   Ú_preparer:   )r    rE   r:   r   r   r   r   ·   s
    
zPatternBase.__init__Tc             C   s,   |rt |ƒ}| j|ƒ}|r(|  jd7  _|S )a   Return a boolean indicating whether *path* is matched by this pattern.

        If normalize is True (default), the path will get normalized using normalize_path(),
        otherwise it is assumed that it already is normalized using that function.
        r   )rS   Ú_matchrO   )r    rX   rR   Zmatchesr   r   r   rW   ¾   s    
zPatternBase.matchc             C   s   dt | ƒ| jf S )Nz%s(%s))ÚtyperE   )r    r   r   r   Ú__repr__Ë   s    zPatternBase.__repr__c             C   s   | j S )N)r`   )r    r   r   r   Ú__str__Î   s    zPatternBase.__str__c             C   s   t ‚dS )z$Should set the value of self.patternN)ÚNotImplementedError)r    rE   r   r   r   ra   Ñ   s    zPatternBase._preparec             C   s   t ‚d S )N)rf   )r    rX   r   r   r   rb   Õ   s    zPatternBase._matchN)F)T)r)   r*   r+   rZ   ÚNotImplementedÚPREFIXr   rW   rd   re   ra   rb   r   r   r   r   r_   ²   s   

r_   c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )rD   zFull match of a path.Zpfc             C   s   t jj|ƒ| _d S )N)ÚosrX   ÚnormpathrE   )r    rE   r   r   r   ra   Ý   s    zPathFullPattern._preparec             C   s
   || j kS )N)rE   )r    rX   r   r   r   rb   à   s    zPathFullPattern._matchN)r)   r*   r+   rZ   rh   ra   rb   r   r   r   r   rD   Ù   s   rD   c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )rJ   zóLiteral files or directories listed on the command line
    for some operations (e.g. extract, but not create).
    If a directory is specified, all paths that start with that
    path match as well.  A trailing slash makes no difference.
    Zppc             C   s$   t jj|ƒjt jjƒt jj | _d S )N)ri   rX   rj   ÚrstripÚseprE   )r    rE   r   r   r   ra   ñ   s    zPathPrefixPattern._preparec             C   s   |t jj j| jƒS )N)ri   rX   rl   Ú
startswithrE   )r    rX   r   r   r   rb   ô   s    zPathPrefixPattern._matchN)r)   r*   r+   rZ   rh   ra   rb   r   r   r   r   rJ   é   s   rJ   c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚFnmatchPatternz†Shell glob patterns to exclude.  A trailing slash means to
    exclude the contents of a directory, but not the directory itself.
    Zfmc             C   sp   |j tjjƒr:tjj|ƒjtjjƒtjj d tjj }ntjj|ƒtjj d }|| _tjt	j
| jƒƒ| _d S )NÚ*)Úendswithri   rX   rl   rj   rk   rE   ÚreÚcompileÚfnmatchÚ	translateÚregex)r    rE   r   r   r   ra   þ   s
    ,zFnmatchPattern._preparec             C   s   | j j|tjj ƒd k	S )N)ru   rW   ri   rX   rl   )r    rX   r   r   r   rb   
  s    zFnmatchPattern._matchN)r)   r*   r+   rZ   rh   ra   rb   r   r   r   r   rn   ø   s   rn   c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )r   z†Shell glob patterns to exclude.  A trailing slash means to
    exclude the contents of a directory, but not the directory itself.
    Zshc             C   st   t jj}|j|ƒr:t jj|ƒj|ƒ| d | d | }nt jj|ƒ| d | d }|| _tjt	j
| jƒƒ| _d S )Nz**ro   )ri   rX   rl   rp   rj   rk   rE   rq   rr   r   rt   ru   )r    rE   rl   r   r   r   ra     s    
(zShellPattern._preparec             C   s   | j j|tjj ƒd k	S )N)ru   rW   ri   rX   rl   )r    rX   r   r   r   rb     s    zShellPattern._matchN)r)   r*   r+   rZ   rh   ra   rb   r   r   r   r   r     s   r   c               @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚRegexPatternz#Regular expression to exclude.
    rq   c             C   s   || _ tj|ƒ| _d S )N)rE   rq   rr   ru   )r    rE   r   r   r   ra   (  s    zRegexPattern._preparec             C   s,   t jjdkr|jt jjdƒ}| jj|ƒd k	S )Nú/)ri   rX   rl   Úreplaceru   Úsearch)r    rX   r   r   r   rb   ,  s    zRegexPattern._matchN)r)   r*   r+   rZ   rh   ra   rb   r   r   r   r   rv   #  s   rv   c             c   s   | ]}|j |fV  qd S )N)rh   )rK   Úir   r   r   ú	<genexpr><  s    r{   ÚCmdTuplezval cmdc               @   s$   e Zd ZdZdZdZdZdZdZdS )r   z8A command that an InclExcl file line can represent.
    r   é   é   é   é   N)	r)   r*   r+   rZ   r   r   r?   r=   r>   r   r   r   r   r   A  s   r   c             C   s   | t jgkS )N)r   r>   )r
   r   r   r   rV   K  s    rV   c             C   s2   yt |  S  tk
r,   tdj| ƒƒd ‚Y nX d S )NzUnknown pattern style: {})Ú_PATTERN_CLASS_BY_PREFIXÚKeyErrorÚ
ValueErrorÚformat)Úprefixr   r   r   Úget_pattern_classP  s    r†   Tc             C   sZ   t | ƒdkrL| d dkrL| dd… jƒ rL| dd… | dd…  }} t|ƒ}n|}|| |ƒS )z^Read pattern from string and return an instance of the appropriate implementation class.

    r}   ú:Nr~   )rA   Úisalnumr†   )rE   r   r:   ZstyleÚclsr   r   r   rI   W  s
    (
rI   c             C   s   t | |dd�}t|tjƒS )z]Read pattern from string and return an instance of the appropriate implementation class.
    F)r:   )rI   r|   r   r>   )Zpattern_strr   Zepattern_objr   r   r   r   c  s    r   c             C   sä   t jt jt jt jt jt jt jdœ}| s0tjdƒ‚|j| d ƒ}|dkrZtjddj	|ƒ ƒ‚| dd… j
ƒ }|sxtjdƒ‚|t jkrˆ|}nR|t jkrÆyt|ƒ}W qÚ tk
rÂ   tjd	j|ƒƒ‚Y qÚX nt|ƒ}t|||ƒ}t||ƒS )
zHRead a --patterns-from command from string and return a CmdTuple object.)ú-ú!ú+ÚRÚrÚPrL   z$A pattern/command must not be empty.r   Nz/A pattern/command must start with anyone of: %sz, r   z)A pattern/command must have a value part.zInvalid pattern style: {})r   r=   r>   r?   r   r   ÚargparseZArgumentTypeErrorrU   ÚjoinÚlstripr†   rƒ   r„   rV   rI   r|   )Zcmd_line_strr   Zcmd_prefix_mapr
   Zremainder_strr   r:   r   r   r   r	   j  s4    




r	   )N))r�   rs   Zos.pathri   rq   r\   r^   Úcollectionsr   Úenumr   Ú r   Zhelpersr   r   r   r   r   ZActionr   r-   r6   r7   rS   r_   rD   rJ   rn   r   rv   Z_PATTERN_CLASSESÚdictr�   r|   r   rV   r†   rI   r   r	   r   r   r   r   Ú<module>   sJ   
c'

