U ��.e�9�@s�dZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dgZ e� e�Ze�dej�Ze�d ejejB�Zejdd �ZGd d�de�ZdS) zu Class representing the list of files in a distribution. Equivalent to distutils.filelist, but fixes some problems. �N�)�DistlibException)�fsdecode�� convert_path�Manifestz\\w* z#.*?(?= )| (?=$)�c@szeZdZdZddd�Zdd�Zdd�Zd d �Zdd d �Zdd�Z dd�Z dd�Z ddd�Z d dd�Z d!dd�Zdd�ZdS)"rz~A list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. NcCs>tj�tj�|pt����|_|jtj|_d|_t �|_ dS)zd Initialise an instance. :param base: The base directory to explore under. N) �os�path�abspath�normpath�getcwd�base�sep�prefix�allfiles�set�files)�selfr�r�@/usr/lib/python3.8/site-packages/pip/_vendor/distlib/manifest.py�__init__*szManifest.__init__cCs�ddlm}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_ISREG�S_ISDIR�S_ISLNKN)�statrrrrr�pop�appendr �listdirr �join�st_moder)rrrrr�root�stackr�push�names�name�fullnamer�moderrr�findall9s"   zManifest.findallcCs4|�|j�stj�|j|�}|j�tj�|��dS)zz Add a file to the manifest. :param item: The pathname to add. This can be relative to the base. N) � startswithrr r rrr�addr )r�itemrrrr*Ts 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*)r�itemsr+rrr�add_many^szManifest.add_manyFcsb��fdd��t�j�}|rFt�}|D]}�|tj�|��q&||O}dd�tdd�|D��D�S)z8 Return sorted files in directory order csJ|�|�t�d|�|�jkrFtj�|�\}}|dks.add_dircSsg|]}tjj|��qSr)r r r)�.0Z path_tuplerrr� zsz#Manifest.sorted..css|]}tj�|�VqdS)N)r r r2)r:r rrr� {sz"Manifest.sorted..)rrr r �dirname�sorted)rZwantdirs�resultr4�frr8rr>gs �zManifest.sortedcCst�|_g|_dS)zClear all collected files.N)rrr)rrrr�clear}szManifest.clearcCsj|�|�\}}}}|dkrB|D]}|j|dd�st�d|�q�n$|dkrf|D]}|j|dd�}qN�n|dkr�|D]}|j|dd�srt�d|�qrn�|d kr�|D]}|j|dd�}q�n�|d kr�|D] }|j||d �s�t�d ||�q�n�|d k�r |D]}|j||d �}q�n\|dk�r2|jd|d ��sft�d|�n4|dk�rZ|jd|d ��sft�d|�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 %r�exclude�global-includeFz3no files found matching %r anywhere in distribution�global-exclude�recursive-include)rz-no files found matching %r under directory %r�recursive-exclude�graftNz no directories found matching %r�prunez4no previously-included directories found matching %rzinvalid action %r)�_parse_directive�_include_patternr0Zwarning�_exclude_patternr)r� directive�action�patterns�thedirZ dirpattern�pattern�foundrrr�process_directive�sP��  � ��zManifest.process_directivecCs|��}t|�dkr,|ddkr,|�dd�|d}d}}}|dkrxt|�dkr`td|��d d �|dd�D�}n~|d kr�t|�d kr�td |��t|d�}dd �|dd�D�}n:|dkr�t|�dkr�td|��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|��qSrr�r:Zwordrrrr;�sz-Manifest._parse_directive..)rGrH�z*%r expects ...cSsg|] }t|��qSrrrUrrrr;�s)rIrJz!%r expects a single zunknown action %r)r2�len�insertrr)rrNZwordsrOrPrQZ dir_patternrrrrK�s4   � �  � zManifest._parse_directiveTcCsPd}|�||||�}|jdkr&|��|jD]}|�|�r,|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. FNT)�_translate_patternrr(�searchrr*)rrRrCr�is_regexrS� pattern_rer%rrrrLs    zManifest._include_patterncCsBd}|�||||�}t|j�D]}|�|�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)rY�listrrZ�remove)rrRrCrr[rSr\r@rrrrM)s   zManifest._exclude_patternc Cs�|rt|t�rt�|�S|Stdkr:|�d��d�\}}}|rj|�|�}tdkrn|�|�rd|�|�snt �nd}t� t j � |jd��} |dk �rftdkr�|�d�} |�|�dt| � �} n>|�|�} | �|�r�| �|�s�t �| t|�t| �t|��} t j} t jdk�rd} tdk�r4d| | � | d|f�}n0|t|�t|�t|��}d || | | ||f}n8|�r�tdk�r�d| |}nd || |t|�d�f}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). )rVrr7r.N�\z\\�^z.*z%s%s%s%s.*%s%sz%s%s%s)� isinstance�str�re�compile�_PYTHON_VERSION� _glob_to_re� partitionr)�endswithr3�escaper r rrrWr) rrRrCrr[�startr7�endr\rZ empty_patternZ prefix_rerrrrrY=sH          �  � zManifest._translate_patterncCs8t�|�}tj}tjdkrd}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). r_z\\\\z\1[^%s]z((?rArTrKrLrMrYrfrrrrr%s&   O/� )� � 7)rrrlZloggingr rc�sysr.r�compatr�utilr�__all__Z getLoggerror0rd�MZ_COLLAPSE_PATTERN�SZ_COMMENTED_LINE� version_infore�objectrrrrr�s