o
    5‘ðié;  ã                   @  sÀ   d Z ddlm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
mZ ddlmZ ddlmZmZ dd	lmZ G d
d„ dƒZdd„ ZG dd„ deƒZejfddd„Zdd„ Zddd„ZdS )zsdistutils.filelist

Provides the FileList class, used for poking about the filesystem
and building lists of files.
é    )ÚannotationsN)ÚIterable)ÚLiteralÚoverloadé   )Úlog)ÚDistutilsInternalErrorÚDistutilsTemplateError©Úconvert_pathc                   @  s  e Zd ZdZd;d<dd	„Zd=dd„Zejfd>dd„Zd?dd„Z	d@dd„Z
dAdd„ZdBdd„ZdBdd„Zd d!„ ZdCd#d$„Ze	%		&dDdEd.d/„ƒZe	%	dFdGd2d/„ƒZedGd3d/„ƒZ	%		&dDdHd5d/„Ze	%		&dDdEd6d7„ƒZe	%	dFdGd8d7„ƒZedGd9d7„ƒZ	%		&dDdHd:d7„ZdS )IÚFileListaÑ  A list of files built by on exploring the filesystem and filtered by
    applying various patterns to what we find there.

    Instance attributes:
      dir
        directory from which files will be taken -- only used if
        'allfiles' not supplied to constructor
      files
        list of filenames currently being built/filtered/manipulated
      allfiles
        complete list of files under consideration (ie. without any
        filtering applied)
    NÚwarnÚobjectÚdebug_printÚreturnÚNonec                 C  s   d | _ g | _d S ©N)ÚallfilesÚfiles)Úselfr   r   © r   ú]/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/filelist.pyÚ__init__$   s   
zFileList.__init__r   úIterable[str]c                 C  s
   || _ d S r   )r   )r   r   r   r   r   Úset_allfiles*   s   
zFileList.set_allfilesÚdirústr | os.PathLike[str]c                 C  s   t |ƒ| _d S r   )Úfindallr   )r   r   r   r   r   r   -   s   zFileList.findallÚmsgc                 C  s    ddl m} |rt|ƒ dS dS )z~Print 'msg' to stdout if the global DEBUG (taken from the
        DISTUTILS_DEBUG environment variable) flag is true.
        r   )ÚDEBUGN)Údistutils.debugr   Úprint)r   r   r   r   r   r   r   0   s   ÿzFileList.debug_printÚitemÚstrc                 C  ó   | j  |¡ d S r   )r   Úappend)r   r"   r   r   r   r%   ;   ó   zFileList.appendÚitemsc                 C  r$   r   )r   Úextend)r   r'   r   r   r   r(   >   r&   zFileList.extendc                 C  s<   t ttjj| jƒƒ}g | _|D ]}| j tjj|Ž ¡ qd S r   )ÚsortedÚmapÚosÚpathÚsplitr   r%   Újoin)r   Úsortable_filesÚ
sort_tupler   r   r   ÚsortA   s
   ÿzFileList.sortc                 C  s@   t t| jƒd ddƒD ]}| j| | j|d  kr| j|= qd S )Nr   r   éÿÿÿÿ)ÚrangeÚlenr   )r   Úir   r   r   Úremove_duplicatesJ   s
   €þzFileList.remove_duplicatesc                 C  sî   |  ¡ }|d }d  } }}|dv r,t|ƒdk r td|› d�ƒ‚dd„ |dd … D ƒ}nE|d	v rPt|ƒd
k r>td|› d�ƒ‚t|d ƒ}dd„ |dd … D ƒ}n!|dv rit|ƒdkrbtd|› d�ƒ‚t|d ƒ}ntd|› d�ƒ‚||||fS )Nr   )ÚincludeÚexcludeúglobal-includeúglobal-excludeé   ú'z#' expects <pattern1> <pattern2> ...c                 S  ó   g | ]}t |ƒ‘qS r   r
   ©Ú.0Úwr   r   r   Ú
<listcomp>]   ó    z1FileList._parse_template_line.<locals>.<listcomp>r   )úrecursive-includeúrecursive-excludeé   z)' expects <dir> <pattern1> <pattern2> ...c                 S  r=   r   r
   r>   r   r   r   rA   d   rB   )ÚgraftÚprunez ' expects a single <dir_pattern>zunknown action ')r-   r4   r	   r   )r   ÚlineÚwordsÚactionÚpatternsr   Údir_patternr   r   r   Ú_parse_template_lineR   s0   
ÿ
ÿ
ÿzFileList._parse_template_linerH   c                 C  s>  |   |¡\}}}}|dkr+|  dd |¡ ¡ |D ]}| j|dd�s(t d|¡ qd S |dkrM|  dd |¡ ¡ |D ]}| j|dd�sJt d	|¡ q;d S |d
kro|  dd |¡ ¡ |D ]}| j|dd�slt d|¡ q]d S |dkr‘|  dd |¡ ¡ |D ]}| j|dd�sŽt d|¡ qd S |dkr¸|  d |d |¡¡¡ |D ]}| j||d�sµd}t |||¡ q£d S |dkrÝ|  d |d |¡¡¡ |D ]}| j||d�sÚt d||¡ qÊd S |dkrù|  d| ¡ | jd |d�s÷t d|¡ d S d S |dk�r|  d| ¡ | jd |d��st d|¡ d S d S td|› d�ƒ‚) Nr7   zinclude ú T)Úanchorz%warning: no files found matching '%s'r8   zexclude z9warning: no previously-included files found matching '%s'r9   zglobal-include Fz>warning: no files found matching '%s' anywhere in distributionr:   zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionrC   zrecursive-include {} {})Úprefixz:warning: no files found matching '%s' under directory '%s'rD   zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'rF   zgraft z+warning: no directories found matching '%s'rG   zprune z6no previously-included directories found matching '%s'z$this cannot happen: invalid action 'r<   )	rM   r   r.   Úinclude_patternr   ÚwarningÚexclude_patternÚformatr   )r   rH   rJ   rK   r   rL   Úpatternr   r   r   r   Úprocess_template_linep   s’   €þþ€þû€þ
û€þ
€ýú€þÿ
þÿ
ÿzFileList.process_template_lineTFrU   rO   ÚboolrP   ú
str | NoneÚis_regexúLiteral[False]c                 C  ó   d S r   r   ©r   rU   rO   rP   rY   r   r   r   rQ   È   ó   zFileList.include_patternústr | re.Pattern[str]úLiteral[True]c                C  r[   r   r   r\   r   r   r   rQ   Ð   ó   c                 C  r[   r   r   r\   r   r   r   rQ   Ù   r]   ústr | re.Patternc                 C  sp   d}t ||||ƒ}|  d|j› d�¡ | jdu r|  ¡  | jD ]}| |¡r5|  d| ¡ | j |¡ d}q|S )a—  Select strings (presumably filenames) from 'self.files' that
        match 'pattern', a Unix-style wildcard (glob) pattern.  Patterns
        are not quite the same as implemented by the 'fnmatch' module: '*'
        and '?'  match non-special characters, where "special" is platform-
        dependent: slash on Unix; colon, slash, and backslash on
        DOS/Windows; and colon on Mac OS.

        If 'anchor' is true (the default), then the pattern match is more
        stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
        'anchor' is false, both of these will match.

        If 'prefix' is supplied, then only filenames starting with 'prefix'
        (itself a pattern) and ending with 'pattern', with anything in between
        them, will match.  'anchor' is ignored in this case.

        If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
        'pattern' is assumed to be either a string containing a regex or a
        regex object -- no translation is done, the regex is just compiled
        and used as-is.

        Selected strings will be added to self.files.

        Return True if files are found, False otherwise.
        Fz"include_pattern: applying regex r'r<   Nz adding T)Útranslate_patternr   rU   r   r   Úsearchr   r%   )r   rU   rO   rP   rY   Úfiles_foundÚ
pattern_reÚnamer   r   r   rQ   á   s    


€c                 C  r[   r   r   r\   r   r   r   rS     r]   zFileList.exclude_patternc                C  r[   r   r   r\   r   r   r   rS     r`   c                 C  r[   r   r   r\   r   r   r   rS   !  r]   c                 C  sv   d}t ||||ƒ}|  d|j› d�¡ tt| jƒd ddƒD ]}| | j| ¡r8|  d| j|  ¡ | j|= d}q|S )a  Remove strings (presumably filenames) from 'files' that match
        'pattern'.  Other parameters are the same as for
        'include_pattern()', above.
        The list 'self.files' is modified in place.
        Return True if files are found, False otherwise.
        Fz"exclude_pattern: applying regex r'r<   r   r2   z
 removing T)rb   r   rU   r3   r4   r   rc   )r   rU   rO   rP   rY   rd   re   r5   r   r   r   rS   )  s   €)NN)r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r"   r#   r   r   )r'   r   r   r   )r   r   )rH   r#   r   r   ©TNF)
rU   r#   rO   rW   rP   rX   rY   rZ   r   rW   )TN)
rU   r^   rO   rW   rP   rX   rY   r_   r   rW   )
rU   ra   rO   rW   rP   rX   rY   rW   r   rW   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r+   Úcurdirr   r   r%   r(   r1   r6   rM   rV   r   rQ   rS   r   r   r   r   r      sT    





	
Xûü
û/ûü
ûr   c                 C  s0   t  tj| dd�¡}dd„ |D ƒ}ttjj|ƒS )z%
    Find all files under 'path'
    T)Úfollowlinksc                 s  s.   � | ]\}}}|D ]
}t j ||¡V  q	qd S r   )r+   r,   r.   )r?   ÚbaseÚdirsr   Úfiler   r   r   Ú	<genexpr>I  s   € 
ÿÿz#_find_all_simple.<locals>.<genexpr>)Ú_UniqueDirsÚfilterr+   Úwalkr,   Úisfile)r,   Ú
all_uniqueÚresultsr   r   r   Ú_find_all_simpleD  s
   ÿrx   c                   @  s$   e Zd ZdZdd„ Zedd„ ƒZdS )rr   z†
    Exclude previously-seen dirs from walk results,
    avoiding infinite recursion.
    Ref https://bugs.python.org/issue44497.
    c                 C  sF   |\}}}t  |¡}|j|jf}|| v }|r|dd…= |  |¡ | S )z®
        Given an item from an os.walk result, determine
        if the item represents a unique dir for this instance
        and if not, prevent further traversal.
        N)r+   ÚstatÚst_devÚst_inoÚadd)r   Ú	walk_itemrn   ro   r   ry   Ú	candidateÚfoundr   r   r   Ú__call__V  s   



z_UniqueDirs.__call__c                 C  s   t | ƒ |ƒS r   )rs   )Úclsr'   r   r   r   rs   e  s   z_UniqueDirs.filterN)rh   ri   rj   rk   r€   Úclassmethodrs   r   r   r   r   rr   O  s
    rr   r   r   c                 C  s6   t | ƒ}| tjkrtjtjj| d�}t||ƒ}t|ƒS )zŒ
    Find all files under 'dir' and return the list of full filenames.
    Unless dir is '.', return full filenames with dir prepended.
    )Ústart)	rx   r+   rl   Ú	functoolsÚpartialr,   Úrelpathr*   Úlist)r   r   Úmake_relr   r   r   r   j  s
   

r   c                 C  s<   t  | ¡}tj}tjdkrd}d|› d�}t d||¡}|S )zæTranslate a shell-like glob pattern to a regular expression; return
    a string containing the regex.  Differs from 'fnmatch.translate()' in
    that '*' does not match "special characters" (which are
    platform-specific).
    ú\z\\\\z\1[^ú]z((?<!\\)(\\\\)*)\.)ÚfnmatchÚ	translater+   ÚsepÚreÚsub)rU   re   r�   Úescapedr   r   r   Ú
glob_to_rev  s   

r‘   TFc           
      C  s  |rt | tƒrt | ¡S | S tdƒ d¡\}}}| r+t| ƒ}| |¡r(| |¡s*J ‚nd}|durvt|ƒ}| |¡r?| |¡sAJ ‚|t|ƒt|ƒt|ƒ … }t	j
}	t	j
dkrYd}	|t|ƒt|ƒt|ƒ … }|› d|› |	› d|› |› �}n|r…|› d|t|ƒd… › �}t |¡S )a  Translate a shell-like wildcard pattern to a compiled regular
    expression.  Return the compiled regex.  If 'is_regex' true,
    then 'pattern' is directly compiled to a regex (if it's a string)
    or just returned as-is (assumes it's a regex object).
    Ú_Ú Nr‰   z\\z\Az.*)Ú
isinstancer#   rŽ   Úcompiler‘   Ú	partitionÚ
startswithÚendswithr4   r+   r�   )
rU   rO   rP   rY   rƒ   r’   Úendre   Ú	prefix_rer�   r   r   r   rb   �  s*   



rb   )r   r   rg   )rk   Ú
__future__r   r‹   r„   r+   rŽ   Úcollections.abcr   Útypingr   r   Ú_logr   Úerrorsr   r	   Úutilr   r   rx   Úsetrr   rl   r   r‘   rb   r   r   r   r   Ú<module>   s&      1