o
    Ëý°jÛ9  ã                   @   s¤   d Z ddl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	 ddl
mZ dgZe e¡Ze dej¡Ze d	ejejB ¡Zejdd
… ZG dd„ deƒZdS )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                   @   s†   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zddd„Zdd„ Z	dd„ Z
dd„ Z		ddd„Z		ddd„Z		ddd„Zdd„ ZdS ) r   z~A list of files built by on exploring the filesystem and filtered by
    applying various patterns to what we find there.
    Nc                 C   s>   t j t j |pt  ¡ ¡¡| _| jt j | _d| _t	ƒ | _
dS )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   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/distlib/manifest.pyÚ__init__*   s   zManifest.__init__c                 C   s®   ddl m}m}m} g  | _}| j}|g}|j}|j}|rU|ƒ }t 	|¡}	|	D ])}
tj
 ||
¡}t  |¡}|j}||ƒrD| t|ƒ¡ q'||ƒrP||ƒsP||ƒ q'|sdS dS )zmFind all files under the base and set ``allfiles`` to the absolute
        pathnames of files found.
        r   )ÚS_ISREGÚS_ISDIRÚS_ISLNKN)Ústatr   r   r   r   r   ÚpopÚappendr	   Úlistdirr
   ÚjoinÚst_moder   )r   r   r   r   r   ÚrootÚstackr   ÚpushÚnamesÚnameÚfullnamer   Úmoder   r   r   Úfindall9   s&   


€ózManifest.findallc                 C   s4   |  | j¡stj | j|¡}| j tj |¡¡ dS )zz
        Add a file to the manifest.

        :param item: The pathname to add. This can be relative to the base.
        N)	Ú
startswithr   r	   r
   r   r   r   Úaddr   )r   Úitemr   r   r   r*   T   s   zManifest.addc                 C   s   |D ]}|   |¡ qdS )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+   r   r   r   Úadd_many^   s   ÿzManifest.add_manyFc                    sb   ‡ ‡fdd„‰ t ˆjƒ}|r#t ƒ }|D ]}ˆ |tj |¡ƒ q||O }dd„ tdd„ |D ƒƒD ƒS )z8
        Return sorted files in directory order
        c                    sN   |   |¡ t d|¡ |ˆjkr%tj |¡\}}|dvsJ ‚ˆ | |ƒ d S d S )Nzadd_dir added %s)Ú ú/)r*   ÚloggerÚdebugr   r	   r
   Úsplit)ÚdirsÚdÚparentÚ_©Úadd_dirr   r   r   r8   l   s   

ýz Manifest.sorted.<locals>.add_dirc                 S   s   g | ]}t jj|Ž ‘qS r   )r	   r
   r   )Ú.0Ú
path_tupler   r   r   Ú
<listcomp>z   s    z#Manifest.sorted.<locals>.<listcomp>c                 s   s   � | ]	}t j |¡V  qd S ©N)r	   r
   r2   )r9   r
   r   r   r   Ú	<genexpr>{   s   € z"Manifest.sorted.<locals>.<genexpr>)r   r   r	   r
   ÚdirnameÚsorted)r   ÚwantdirsÚresultr3   Úfr   r7   r   r?   g   s   
ÿzManifest.sortedc                 C   s   t ƒ | _g | _dS )zClear all collected files.N)r   r   r   )r   r   r   r   Úclear}   s   
zManifest.clearc                 C   sp  |   |¡\}}}}|dkr!|D ]}| j|dd�st d|¡ qdS |dkr3|D ]	}| j|dd�}q'dS |dkrK|D ]}| j|dd�sHt d|¡ q9dS |d	kr]|D ]	}| j|dd�}qQdS |d
krv|D ]}| j||d�sst d||¡ qcdS |dkrˆ|D ]	}| j||d�}q|dS |dkr�| jd|d�s›t d|¡ dS dS |dkr²| jd|d�s°t d|¡ dS dS td| ƒ‚)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)Úanchorzno files found matching %rÚexcludeúglobal-includeFz3no files found matching %r anywhere in distributionúglobal-excludeúrecursive-include)r   z-no files found matching %r under directory %rúrecursive-excludeÚgraftNz no directories found matching %rÚprunez4no previously-included directories found matching %rzinvalid action %r)Ú_parse_directiveÚ_include_patternr0   ÚwarningÚ_exclude_patternr   )r   Ú	directiveÚactionÚpatternsÚthedirÚ
dirpatternÚpatternÚfoundr   r   r   Úprocess_directive‚   sd   €þÿÿ€þÿÿ€þÿÿÿÿÿÿzManifest.process_directivec                 C   s  |  ¡ }t|ƒdkr|d dvr| dd¡ |d }d } }}|dv r<t|ƒdk r0td| ƒ‚d	d
„ |dd… D ƒ}n?|dv r^t|ƒdk rLtd| ƒ‚t|d ƒ}dd
„ |dd… D ƒ}n|dv rut|ƒdkrntd| ƒ‚t|d ƒ}ntd| ƒ‚||||fS )zŸ
        Validate a directive.
        :param directive: The directive to validate.
        :return: A tuple of action, patterns, thedir, dir_patterns
        r   r   )rD   rF   rG   rH   rI   rJ   rK   rL   rD   N)rD   rF   rG   rH   r   z$%r expects <pattern1> <pattern2> ...c                 S   ó   g | ]}t |ƒ‘qS r   r   ©r9   Úwordr   r   r   r;   ê   ó    z-Manifest._parse_directive.<locals>.<listcomp>)rI   rJ   é   z*%r expects <dir> <pattern1> <pattern2> ...c                 S   rY   r   r   rZ   r   r   r   r;   ò   r\   )rK   rL   z!%r expects a single <dir_pattern>zunknown action %r)r2   ÚlenÚinsertr   r   )r   rQ   ÚwordsrR   rS   rT   Údir_patternr   r   r   rM   Ñ   s4   ÿÿÿzManifest._parse_directiveTc                 C   sP   d}|   ||||¡}| jdu r|  ¡  | jD ]}| |¡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_patternr   r(   Úsearchr   r*   )r   rV   rE   r   Úis_regexrW   Ú
pattern_rer%   r   r   r   rN      s   


€zManifest._include_patternc                 C   sB   d}|   ||||¡}t| jƒD ]}| |¡r| j |¡ d}q|S )at  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.

        This API is public to allow e.g. exclusion of SCM subdirs, e.g. when
        packaging source distributions
        FT)rb   Úlistr   rc   Úremove)r   rV   rE   r   rd   rW   re   rB   r   r   r   rP   )  s   
€zManifest._exclude_patternc                 C   sž  |rt |tƒrt |¡S |S tdkr|  d¡ d¡\}}}|r5|  |¡}tdkr4| |¡r2| |¡s4J ‚nd}t 	t
j | jd¡¡}	|dur°tdkr\|  d¡}
|  |¡dt|
ƒ … }n|  |¡}| |¡rk| |¡smJ ‚|t|ƒt|ƒt|ƒ … }t
j}t
jdkr…d}tdkr—d|	 | |d| f¡ }n3|t|ƒt|ƒt|ƒ … }d	||	||||f }n|rÊtdkr½d|	 | }nd
||	|t|ƒd… f }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).
        )r]   r   r6   r.   Nú\z\\ú^z.*z%s%s%s%s.*%s%sz%s%s%s)Ú
isinstanceÚstrÚreÚcompileÚ_PYTHON_VERSIONÚ_glob_to_reÚ	partitionr)   ÚendswithÚescaper	   r
   r   r   r^   r   )r   rV   rE   r   rd   Ústartr6   Úendre   r   Úempty_patternÚ	prefix_rer   r   r   r   rb   =  sH   	


€



ÿ
ÿ
zManifest._translate_patternc                 C   s8   t  |¡}tj}tjdkrd}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).
        rh   z\\\\z\1[^%s]z((?<!\\)(\\\\)*)\.)ÚfnmatchÚ	translater	   r   rl   Úsub)r   rV   re   r   Úescapedr   r   r   ro   t  s   

zManifest._glob_to_rer<   )F)TNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r*   r-   r?   rC   rX   rM   rN   rP   rb   ro   r   r   r   r   r   %   s(    


	O/
ÿ)
ÿ
ÿ7)r~   rw   Úloggingr	   rl   Úsysr.   r   Úcompatr   Úutilr   Ú__all__Ú	getLoggerr{   r0   rm   ÚMÚ_COLLAPSE_PATTERNÚSÚ_COMMENTED_LINEÚversion_inforn   Úobjectr   r   r   r   r   Ú<module>   s   
