
    wgV5                         d 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  G d d      Zd	 Z G d
 de      Zej                   fdZd ZddZy)zsdistutils.filelist

Provides the FileList class, used for poking about the filesystem
and building lists of files.
    N   )log)DistutilsInternalErrorDistutilsTemplateError)convert_pathc                   v    e Zd ZdZddZd Zej                  fdZd Z	d Z
d Zd	 Zd
 Zd Zd ZddZddZy)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)
    Nc                      d | _         g | _        y N)allfilesfiles)selfwarndebug_prints      c/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/setuptools/_distutils/filelist.py__init__zFileList.__init__    s     
    c                     || _         y r   )r   )r   r   s     r   set_allfileszFileList.set_allfiles&   s	     r   c                 $    t        |      | _        y r   )findallr   )r   dirs     r   r   zFileList.findall)   s    r   c                 ,    ddl m} |rt        |       yy)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   msgr   s      r   r   zFileList.debug_print,   s     	*#J r   c                 :    | j                   j                  |       y r   )r   append)r   items     r   r   zFileList.append7   s    

$r   c                 :    | j                   j                  |       y r   )r   extend)r   itemss     r   r"   zFileList.extend:   s    

% r   c                     t        t        t        j                  j                  | j
                              }g | _        |D ]7  }| j
                  j                  t        j                  j                  |        9 y r   )sortedmapospathsplitr   r   join)r   sortable_files
sort_tuples      r   sortzFileList.sort=   sT    BGGMM4:: >?
( 	9JJJbggllJ78	9r   c                     t        t        | j                        dz
  dd      D ]2  }| j                  |   | j                  |dz
     k(  s&| j                  |= 4 y )Nr   r   )rangelenr   )r   is     r   remove_duplicateszFileList.remove_duplicatesF   sO    s4::*Ar2 	"Azz!}

1q5 11JJqM	"r   c                    |j                         }|d   }d x}x}}|dv r9t        |      dk  rt        d| d      |dd  D cg c]  }t        |       }}n|dv rGt        |      dk  rt        d| d	      t        |d         }|dd  D cg c]  }t        |       }}n?|d
v r,t        |      dk7  rt        d| d      t        |d         }nt        d| d      ||||fS c c}w c c}w )Nr   )includeexcludeglobal-includeglobal-exclude   'z#' expects <pattern1> <pattern2> ...r   )recursive-includerecursive-exclude   z)' expects <dir> <pattern1> <pattern2> ...)graftprunez ' expects a single <dir_pattern>zunknown action ')r)   r1   r   r   )r   linewordsactionpatternsr   dir_patternws           r   _parse_template_linezFileList._parse_template_lineN   s9   

q'+++3OO5zA~,xBC  27qr;AQ;H;AA5zA~,xHI  uQx(C16qr;AQ;H;))5zQ,x?@  'uQx0K(+;F81)EFF#{33# < <s   C)C.c                    | j                  |      \  }}}}|dk(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d|       . y |dk(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d	|       . y |d
k(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d|       . y |dk(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d|       . y |dk(  re| j                  dj                  |dj                  |                   |D ]/  }| j                  ||      rd}t	        j
                  |||       1 y |dk(  rc| j                  dj                  |dj                  |                   |D ]-  }| j                  ||      rt	        j
                  d||       / y |dk(  r?| j                  d|z          | j                  d |      st	        j
                  d|       y y |dk(  r?| j                  d|z          | j                  d |      st	        j
                  d|       y y t        d| d      ) Nr5   zinclude  T)anchorz%warning: no files found matching '%s'r6   zexclude z9warning: no previously-included files found matching '%s'r7   zglobal-include Fz>warning: no files found matching '%s' anywhere in distributionr8   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'r<   zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'r>   zgraft z+warning: no directories found matching '%s'r?   zprune z6no previously-included directories found matching '%s'z$this cannot happen: invalid action 'r:   )	rF   r   r*   include_patternr   warningexclude_patternformatr   )r   r@   rB   rC   r   rD   patternr   s           r   process_template_linezFileList.process_template_linel   s    04/H/H/N,3
 YZ#((8*<<=# R++GD+AKK GQR y Z#((8*<<=# ++GD+AKK2   ''.(1CCD# ++GE+BKK7   ''.(1CCD# ++GE+BKKB   **6==c388HCUVW# 3++GC+@VCKKWc23
 **6==c388HCUVW# 	++GC+@KK>  	 wX34''['AI;W B wX34''['AM B )6vha@ r   c                 D   d}t        ||||      }| j                  d|j                   d       | j                  | j	                          | j                  D ]E  }|j                  |      s| j                  d|z          | j                  j                  |       d}G |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:   z adding T)translate_patternr   rO   r   r   searchr   r   )r   rO   rI   rJ   is_regexfiles_found
pattern_renames           r   rK   zFileList.include_pattern   s    4 &wI
=j>P>P=QQRST == LLNMM 	#D  &  d!23

!!$'"		#
 r   c                 R   d}t        ||||      }| j                  d|j                   d       t        t	        | j
                        dz
  dd      D ]Q  }|j                  | j
                  |         s"| j                  d| j
                  |   z          | j
                  |= d}S |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   r/   z
 removing T)rR   r   rO   r0   r1   r   rS   )r   rO   rI   rJ   rT   rU   rV   r2   s           r   rM   zFileList.exclude_pattern   s     &wI
=j>P>P=QQRSTs4::*B3 	#A  A/  

1!=>JJqM"		#
 r   )NNTNF)__name__
__module____qualname____doc__r   r   r'   curdirr   r   r   r"   r-   r3   rF   rP   rK   rM    r   r   r	   r	      sO    ! )) % !9"4<Xx'Rr   r	   c                     t         j                  t        j                  | d            }d |D        }t        t        j                  j
                  |      S )z%
    Find all files under 'path'
    T)followlinksc              3   r   K   | ]/  \  }}}|D ]$  }t         j                  j                  ||       & 1 y wr   )r'   r(   r*   ).0basedirsr   files        r   	<genexpr>z#_find_all_simple.<locals>.<genexpr>  s=      %6T4QVIMT4  s   57)_UniqueDirsfilterr'   walkr(   isfile)r(   
all_uniqueresultss      r   _find_all_simplern     sE     ##BGGDd$CDJ:DG "''..'**r   c                   &    e Zd ZdZd Zed        Zy)rh   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= | j	                  |       | 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_itemrd   re   r   rq   	candidatefounds           r   __call__z_UniqueDirs.__call__  sW     &dEwwt}KK,	T!Qyr   c                 $    t         |        |      S r   )ri   )clsr#   s     r   ri   z_UniqueDirs.filter'  s    ceU##r   N)rZ   r[   r\   r]   rx   classmethodri   r_   r   r   rh   rh     s      $ $r   rh   c                     t        |       }| t        j                  k(  r;t        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)	rn   r'   r^   	functoolspartialr(   relpathr&   list)r   r   make_rels      r   r   r   ,  sJ    
 S!E
bii$$RWW__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	translater'   sepresub)rO   rV   r   escapeds       r   
glob_to_rer   8  sW     ""7+J &&C	vv~ cU!nG-w
CJr   c                    |r't        | t              rt        j                  |       S | S t	        d      j                  d      \  }}}| r/t	        |       }|j                  |      r|j                  |      sJ d}|t	        |      }|j                  |      r|j                  |      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.*)
isinstancestrr   compiler   	partition
startswithendswithr1   r'   r   )
rO   rI   rJ   rT   r}   r   endrV   	prefix_rer   s
             r   rR   rR   O  sD    gs#::g&&N sO--c2ME1c(
$$U+
0C0CC0HHH
v&	##E*y/A/A#/FFFc%j3y>CH+DE	ff66T>CE
S_s3x-GH
r)SEJ<uE
"G2jU&>%?@J::j!!r   rY   )r]   r   r~   r'   r   _logr   errorsr   r   utilr   r	   rn   setrh   r^   r   r   rR   r_   r   r   <module>r      sW      	 	  B o oj+$# $6 		 	.""r   