
    i;                        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          Zd Z G d de          Zej        fddZd Z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                  <   e Zd ZdZd/d0dZd1dZej        fd2dZd3dZ	d4dZ
d5dZd6dZd6dZd Zd7dZe	 	 	 d8d9d$            Ze	 	 d:d;d'            Zed;d(            Z	 	 	 d8d<d*Ze	 	 	 d8d9d+            Ze	 	 d:d;d,            Zed;d-            Z	 	 	 d8d<d.ZdS )=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                "    d | _         g | _        d S N)allfilesfiles)selfr   r   s      V/srv/django_bis/venv311/lib/python3.11/site-packages/setuptools/_distutils/filelist.py__init__zFileList.__init__$   s     /3 "


    r   Iterable[str]c                    || _         d S r   )r   )r   r   s     r   set_allfileszFileList.set_allfiles*   s     r   dirstr | os.PathLike[str]c                .    t          |          | _        d S r   )findallr   )r   r   s     r   r"   zFileList.findall-   s    r   msgc                8    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%   s      r   r   zFileList.debug_print0   s7     	*))))) 	#JJJJJ	 	r   itemstrc                :    | j                             |           d S r   )r   append)r   r(   s     r   r+   zFileList.append;   s    
$r   itemsc                :    | j                             |           d S r   )r   extend)r   r,   s     r   r.   zFileList.extend>   s    
%     r   c                    t          t          t          j        j        | j                            }g | _        |D ]-}| j                            t          j        j        |            .d S r   )sortedmapospathsplitr   r+   join)r   sortable_files
sort_tuples      r   sortzFileList.sortA   sa    BGM4: > >??
( 	9 	9JJbglJ78888	9 	9r   c                    t          t          | j                  dz
  dd          D ])}| j        |         | j        |dz
           k    r| j        |= *d S )Nr   r   )rangelenr   )r   is     r   remove_duplicateszFileList.remove_duplicatesJ   sZ    s4:*Ar22 	" 	"Az!}
1q5 111JqM	" 	"r   c                   |                                 }|d         }d x}x}}|dv r;t          |          dk     rt          d| d          d |dd          D             }n|dv rPt          |          d	k     rt          d| d
          t          |d                   }d |dd          D             }nS|dv r<t          |          dk    rt          d| d          t          |d                   }nt          d| d          ||||fS )Nr   )includeexcludeglobal-includeglobal-exclude   'z#' expects <pattern1> <pattern2> ...c                ,    g | ]}t          |          S  r   .0ws     r   
<listcomp>z1FileList._parse_template_line.<locals>.<listcomp>]       ;;;AQ;;;r   r   )recursive-includerecursive-exclude   z)' expects <dir> <pattern1> <pattern2> ...c                ,    g | ]}t          |          S rG   r   rH   s     r   rK   z1FileList._parse_template_line.<locals>.<listcomp>d   rL   r   )graftprunez ' expects a single <dir_pattern>zunknown action ')r4   r<   r
   r   )r   linewordsactionpatternsr   dir_patterns          r   _parse_template_linezFileList._parse_template_lineR   se   

q'+++3OOO5zzA~~,CCCC   <;qrr;;;HHAAA5zzA~~,IIII   uQx((C;;qrr;;;HH)))5zzQ,@@@@   'uQx00KK()EF)E)E)EFFF#{33r   rS   c                   |                      |          \  }}}}|dk    r^|                     dd                    |          z              |D ].}|                     |d          st	          j        d|           /d S |dk    r^|                     dd                    |          z              |D ].}|                     |d          st	          j        d	|           /d S |d
k    r^|                     dd                    |          z              |D ].}|                     |d          st	          j        d|           /d S |dk    r^|                     dd                    |          z              |D ].}|                     |d          st	          j        d|           /d S |dk    rr|                     d                    |d                    |                               |D ]1}|                     ||          sd}t	          j        |||           2d S |dk    rp|                     d                    |d                    |                               |D ]/}|                     ||          st	          j        d||           0d S |dk    rH|                     d|z              |                     d |          st	          j        d|           d S d S |dk    rH|                     d|z              |                     d |          st	          j        d|           d S d S t          d| d          ) Nr@   zinclude  T)anchorz%warning: no files found matching '%s'rA   zexclude z9warning: no previously-included files found matching '%s'rB   zglobal-include Fz>warning: no files found matching '%s' anywhere in distributionrC   zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionrM   zrecursive-include {} {})prefixz:warning: no files found matching '%s' under directory '%s'rN   zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'rQ   zgraft z+warning: no directories found matching '%s'rR   zprune z6no previously-included directories found matching '%s'z$this cannot happen: invalid action 'rE   )	rX   r   r5   include_patternr   warningexclude_patternformatr	   )r   rS   rU   rV   r   rW   patternr#   s           r   process_template_linezFileList.process_template_linep   sI    04/H/H/N/N,3
 YZ#((8*<*<<===# R R++GD+AA RK GQQQR R y  Z#((8*<*<<===#  ++GD+AA KS    '''.(1C1CCDDD#  ++GE+BB K7      '''.(1C1CCDDD#  ++GE+BB KB      ***6==c388HCUCUVVWWW# 3 3++GC+@@ 3VCKWc2223 3
 ***6==c388HCUCUVVWWW# 	 	++GC+@@ K>    	 	 wX3444''['AA XI;WWWWWX X wX3444''['AA M      )@v@@@  r   TFra   r[   boolr\   
str | Noneis_regexLiteral[False]c                    d S r   rG   r   ra   r[   r\   re   s        r   r]   zFileList.include_pattern   	     sr   str | re.Pattern[str]Literal[True]c                   d S r   rG   rh   s        r   r]   zFileList.include_pattern   	     sr   c                    d S r   rG   rh   s        r   r]   zFileList.include_pattern   ri   r   str | re.Patternc                F   d}t          ||||          }|                     d|j         d           | j        |                                  | j        D ]K}|                    |          r4|                     d|z              | j                            |           d}L|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'rE   Nz adding T)translate_patternr   ra   r   r"   searchr   r+   )r   ra   r[   r\   re   files_found
pattern_renames           r   r]   zFileList.include_pattern   s    @ &wII
Sj>PSSSTTT = LLNNNM 	# 	#D  && #  d!2333
!!$'''"r   c                    d S r   rG   rh   s        r   r_   zFileList.exclude_pattern  ri   r   c                   d S r   rG   rh   s        r   r_   zFileList.exclude_pattern  rm   r   c                    d S r   rG   rh   s        r   r_   zFileList.exclude_pattern!  ri   r   c                V   d}t          ||||          }|                     d|j         d           t          t	          | j                  dz
  dd          D ]O}|                    | j        |                   r-|                     d| j        |         z              | j        |= d}P|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'rE   r   r:   z
 removing T)rq   r   ra   r;   r<   r   rr   )r   ra   r[   r\   re   rs   rt   r=   s           r   r_   zFileList.exclude_pattern)  s     &wII
Sj>PSSSTTTs4:*B33 	# 	#A  A// #  
1!=>>>JqM"r   )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   )rS   r)   r   r   TNF)
ra   r)   r[   rc   r\   rd   re   rf   r   rc   )TN)
ra   rj   r[   rc   r\   rd   re   rk   r   rc   )
ra   ro   r[   rc   r\   rd   re   rc   r   rc   )__name__
__module____qualname____doc__r   r   r2   curdirr"   r   r+   r.   r8   r>   rX   rb   r   r]   r_   rG   r   r   r   r      s:        # # # # #! ! ! ! 57I % % % % %          ! ! ! !9 9 9 9" " " "4 4 4<U U U Up  !#(    X  !	    X    X !- - - - -^  !#(    X  !	    X    X !      r   r   c                    t                               t          j        | d                    }d |D             }t          t          j        j        |          S )z%
    Find all files under 'path'
    T)followlinksc              3  h   K   | ]-\  }}}|D ]$}t           j                            ||          V  %.d S r   )r2   r3   r5   )rI   basedirsr   files        r   	<genexpr>z#_find_all_simple.<locals>.<genexpr>I  s^        %6T4QV IMT4        r   )_UniqueDirsfilterr2   walkr3   isfile)r3   
all_uniqueresultss      r   _find_all_simpler   D  sZ     ##BGDd$C$C$CDDJ :D  G "'.'***r   c                  .    e Zd ZdZd Zed             ZdS )r   z
    Exclude previously-seen dirs from walk results,
    avoiding infinite recursion.
    Ref https://bugs.python.org/issue44497.
    c                    |\  }}}t          j        |          }|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)r2   statst_devst_inoadd)r   	walk_itemr   r   r   r   	candidatefounds           r   __call__z_UniqueDirs.__call__V  sb     &dEwt}}K,	T! 	QQQyr   c                2    t           |             |          S r   )r   )clsr,   s     r   r   z_UniqueDirs.filtere  s    cceeU###r   N)r{   r|   r}   r~   r   classmethodr   rG   r   r   r   r   O  sH            $ $ [$ $ $r   r   r   r    c                    t          |           }| t          j        k    r5t          j        t          j        j        |           }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)	r   r2   r   	functoolspartialr3   relpathr1   list)r   r   make_rels      r   r"   r"   j  sR    
 S!!E
bi$RW_C@@@He$$;;r   c                    t          j        |           }t          j        }t          j        dk    rd}d| d}t	          j        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	translater2   sepresub)ra   rt   r   escapeds       r   
glob_to_rer   v  sV     "7++J &C	v~~ cnnnG-w
CCJr   TFc                0   |r+t          | t                    rt          j        |           S | S t	          d                              d          \  }}}| r<t	          |           }|                    |          r|                    |          sJ nd}|t	          |          }|                    |          r|                    |          sJ |t          |          t          |          t          |          z
           }t          j
        }	t          j
        dk    rd}	|t          |          t          |          t          |          z
           }| d| |	 d| | }n|r| d|t          |          d          }t          j        |          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endswithr<   r2   r   )
ra   r[   r\   re   r   r   endrt   	prefix_rer   s
             r   rq   rq     s     gs## 	:g&&&N sOO--c22ME1c ((
$$U++H
0C0CC0H0HHHHH
v&&	##E**Fy/A/A#/F/FFFFc%jj3y>>CHH+DDE	f6T>>CE

S__s3xx-G GH
EE)ESEEJEEE

 	A"@@jU&>@@J:j!!!r   )r   r    rz   )r~   
__future__r   r   r   r2   r   collections.abcr   typingr   r   _logr   errorsr	   r
   utilr   r   r   setr   r   r"   r   rq   rG   r   r   <module>r      sg    # " " " " "      				 				 $ $ $ $ $ $ $ $ $ $ $ $ $ $       B B B B B B B B      i i i i i i i i^	+ + +$ $ $ $ $# $ $ $6 +-) 	 	 	 	 	  ."" "" "" "" "" ""r   