o
    NZh;                     @  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   M/var/www/auris/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)Z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   Zsortable_filesZ
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   r>   d   r?   )graftprunez ' expects a single <dir_pattern>zunknown action ')r,   r1   r	   r   )r   linewordsactionpatternsr   dir_patternr   r   r   _parse_template_lineR   s0   


zFileList._parse_template_linerE   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std| qd S |dkr| d|d| |D ]}| j||dsd}t||| qd S |dkr| d|d| |D ]}| j||dstd|| qd S |dkr| d|  | jd |dstd| d S d S |dkr| d|  | jd |dstd| d S d S td| d) Nr4   zinclude  T)anchorz%warning: no files found matching '%s'r5   zexclude z9warning: no previously-included files found matching '%s'r6   zglobal-include Fz>warning: no files found matching '%s' anywhere in distributionr7   zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionr@   zrecursive-include {} {})prefixz:warning: no files found matching '%s' under directory '%s'rA   zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'rC   zgraft z+warning: no directories found matching '%s'rD   zprune z6no previously-included directories found matching '%s'z$this cannot happen: invalid action 'r9   )	rJ   r   r-   include_patternr   warningexclude_patternformatr   )r   rE   rG   rH   r   rI   patternr   r   r   r   process_template_linep   s   



zFileList.process_template_lineTFrR   rL   boolrM   
str | Noneis_regexLiteral[False]c                 C     d S r   r   r   rR   rL   rM   rV   r   r   r   rN         zFileList.include_patternstr | re.Pattern[str]Literal[True]c                C  rX   r   r   rY   r   r   r   rN         c                 C  rX   r   r   rY   r   r   r   rN      rZ   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'r9   Nz adding T)translate_patternr   rR   r   r   searchr   r$   )r   rR   rL   rM   rV   files_found
pattern_renamer   r   r   rN      s    


c                 C  rX   r   r   rY   r   r   r   rP     rZ   zFileList.exclude_patternc                C  rX   r   r   rY   r   r   r   rP     r]   c                 C  rX   r   r   rY   r   r   r   rP   !  rZ   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'r9   r   r/   z
 removing T)r_   r   rR   r0   r1   r   r`   )r   rR   rL   rM   rV   ra   rb   r2   r   r   r   rP   )  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   )rE   r"   r   r   TNF)
rR   r"   rL   rT   rM   rU   rV   rW   r   rT   )TN)
rR   r[   rL   rT   rM   rU   rV   r\   r   rT   )
rR   r^   rL   rT   rM   rU   rV   rT   r   rT   )__name__
__module____qualname____doc__r   r   r*   curdirr   r   r$   r'   r.   r3   rJ   rS   r   rN   rP   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+   Z
all_uniqueresultsr   r   r   _find_all_simpleD  s
   rt   c                   @  s$   e Zd ZdZdd Zedd ZdS )ro   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   Z	walk_itemrk   rl   r   ru   	candidatefoundr   r   r   __call__V  s   



z_UniqueDirs.__call__c                 C  s   t |  |S r   )rp   )clsr&   r   r   r   rp   e  s   z_UniqueDirs.filterN)re   rf   rg   rh   r{   classmethodrp   r   r   r   r   ro   O  s
    ro   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)	rt   r*   ri   	functoolspartialr+   relpathr)   list)r   r   Z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 )zTranslate 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)rR   rb   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endswithr1   r*   r   )
rR   rL   rM   rV   r~   r   endrb   Z	prefix_rer   r   r   r   r_     s*   



r_   )r   r   rd   )rh   
__future__r   r   r   r*   r   collections.abcr   typingr   r   _logr   errorsr   r	   utilr   r   rt   setro   ri   r   r   r_   r   r   r   r   <module>   s&      1