U cfX7@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dgZ e eZedejZed ejejBZejdd ZGd ddeZdS) zu Class representing the list of files in a distribution. Equivalent to distutils.filelist, but fixes some problems. N)DistlibException)fsdecode convert_pathManifestz\\w* z#.*?(?= )| (?=$)c@szeZdZdZdddZddZddZd d Zdd d ZddZ ddZ ddZ dddZ d ddZ d!ddZddZdS)"rz A list of files built by exploring the filesystem and filtered by applying various patterns to what we find there. NcCs>tjtj|pt|_|jtj|_d|_t |_ dS)zd Initialise an instance. :param base: The base directory to explore under. N) ospathabspathnormpathgetcwdbasesepprefixallfilessetfiles)selfrrJ/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/distlib/manifest.py__init__,szManifest.__init__cCsddlm}m}m}g|_}|j}|g}|j}|j}|r|}t |} | D]R} tj || } t| } | j } || r|t | qN|| rN|| sN|| qNq6dS)zmFind all files under the base and set ``allfiles`` to the absolute pathnames of files found. r)S_ISREGS_ISDIRS_ISLNKN)statrrrrrpopappendr listdirr joinst_moder)rrrrrrootstackrpushnamesnamefullnamermoderrrfindall;s"   zManifest.findallcCs4||jstj|j|}|jtj|dS)zz Add a file to the manifest. :param item: The pathname to add. This can be relative to the base. N) startswithrr r rrraddr )ritemrrrr*Vs z Manifest.addcCs|D]}||qdS)z Add a list of files to the manifest. :param items: The pathnames to add. These can be relative to the base. N)r*)ritemsr+rrradd_many`szManifest.add_manyFcsbfddtj}|rFt}|D]}|tj|q&||O}ddtdd|DDS)z8 Return sorted files in directory order csJ||td||jkrFtj|\}}|dks.add_dircSsg|]}tjj|qSr)r r r).0Z path_tuplerrr |sz#Manifest.sorted..css|]}tj|VqdS)N)r r r2)r:r rrr }sz"Manifest.sorted..)rrr r dirnamesorted)rZwantdirsresultr4frr8rr>is zManifest.sortedcCst|_g|_dS)zClear all collected files.N)rrr)rrrrclearszManifest.clearcCsj||\}}}}|dkrB|D]}|j|ddstd|qn$|dkrf|D]}|j|ddqNn|dkr|D]}|j|ddsrtd|qrn|d kr|D]}|j|ddqn|d kr|D] }|j||d std ||qn|d kr |D]}|j||d qn\|dkr2|jd|d sftd|n4|dkrZ|jd|d sftd|n td|dS)av Process a directive which either adds some files from ``allfiles`` to ``files``, or removes some files from ``files``. :param directive: The directive to process. This should be in a format compatible with distutils ``MANIFEST.in`` files: http://docs.python.org/distutils/sourcedist.html#commands includeT)anchorzno files found matching %rexcludeglobal-includeFz3no files found matching %r anywhere in distributionglobal-excluderecursive-include)rz-no files found matching %r under directory %rrecursive-excludegraftNz no directories found matching %rprunez4no previously-included directories found matching %rzinvalid action %r)_parse_directive_include_patternr0warning_exclude_patternr)r directiveactionpatternsthedirZ dirpatternpatternrrrprocess_directivesP   zManifest.process_directivecCs|}t|dkr,|ddkr,|dd|d}d}}}|dkrxt|dkr`td|d d |ddD}n~|d krt|d krtd |t|d}dd |ddD}n:|dkrt|dkrtd|t|d}n td|||||fS)z Validate a directive. :param directive: The directive to validate. :return: A tuple of action, patterns, thedir, dir_patterns rr)rBrDrErFrGrHrIrJrBN)rBrDrErFrz$%r expects ...cSsg|] }t|qSrrr:wordrrrr;sz-Manifest._parse_directive..)rGrHz*%r expects ...cSsg|] }t|qSrrrUrrrr;s)rIrJz!%r expects a single zunknown action %r)r2leninsertrr)rrOwordsrPrQrRZ dir_patternrrrrKs4       zManifest._parse_directiveTcCsPd}|||||}|jdkr&||jD]}||r,|j|d}q,|S)aSelect 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. FNT)_translate_patternrr(searchrr*)rrSrCris_regexfound pattern_rer%rrrrLs    zManifest._include_patterncCsBd}|||||}t|jD]}||r|j|d}q|S)atRemove 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. This API is public to allow e.g. exclusion of SCM subdirs, e.g. when packaging source distributions FT)r[listrr\remove)rrSrCrr]r^r_r@rrrrN s   zManifest._exclude_patternc Cs|rt|trt|S|Stdkr:|dd\}}}|rj||}tdkrn||rd||snt nd}t t j |jd} |dk rftdkr|d} ||dt|  } n>||} | |r| |st | t|t| t|} t j} t jdkrd} tdkr4d| | | d|f}n0|t|t|t|}d || | | ||f}n8|rtdkrd| |}nd || |t|df}t|S) aTranslate 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). )rWrr7r.N\z\\^z.*z%s%s%s%s.*%s%sz%s%s%s) isinstancestrrecompile_PYTHON_VERSION _glob_to_re partitionr)endswithr3escaper r rrrXr) rrSrCrr]startr7endr_rZ empty_patternZ prefix_rerrrrr[4sH             zManifest._translate_patterncCs8t|}tj}tjdkrd}d|}td||}|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). rbz\\\\z\1[^%s]z((?rArTrKrLrNr[rirrrrr&s&   D/ )  7)rvrologgingr rfsysr.rcompatrutilr__all__ getLoggerrsr0rgMZ_COLLAPSE_PATTERNSZ_COMMENTED_LINE version_inforhobjectrrrrrs