o
    Ëý°jåK  ã                   @   sÊ  d dl Z d dl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	m
Z
mZmZmZmZmZmZmZm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 d dlm Z m!Z! d d	l"m#Z#m$Z$m%Z% d d
l&m'Z' d dl(m)Z)m*Z* d dl+m,Z,m-Z- d dl.m/Z/ e
r�d dlm0Z0 ne1Z0eeef Z2ee3ej4f Z5e 6e7¡Z8G dd„ de0ƒZ9dee3df dee3df de3fdd„Z:G dd„ de0ƒZ;G dd„ dƒZ<G dd„ de0ƒZ=G dd„ de=ƒZ>G dd „ d e=ƒZ?dS )!é    N)
ÚIOÚTYPE_CHECKINGÚ
CollectionÚ	ContainerÚIterableÚIteratorÚListÚOptionalÚTupleÚUnion)ÚRequirement)ÚInvalidSpecifierÚSpecifierSet)ÚNormalizedName)ÚLegacyVersionÚVersion)ÚNoneMetadataError)Úsite_packagesÚ	user_site)ÚDIRECT_URL_METADATA_NAMEÚ	DirectUrlÚDirectUrlValidationError)Ústdlib_pkgs)Úegg_link_path_from_locationÚegg_link_path_from_sys_path)Úis_localÚnormalize_path)Úurl_to_path)ÚProtocolc                   @   sB   e Zd Zedefdd„ƒZedefdd„ƒZedefdd„ƒZdS )	ÚBaseEntryPointÚreturnc                 C   ó   t ƒ ‚©N©ÚNotImplementedError©Úself© r'   úŽ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_internal/metadata/base.pyÚname6   ó   zBaseEntryPoint.namec                 C   r!   r"   r#   r%   r'   r'   r(   Úvalue:   r*   zBaseEntryPoint.valuec                 C   r!   r"   r#   r%   r'   r'   r(   Úgroup>   r*   zBaseEntryPoint.groupN)Ú__name__Ú
__module__Ú__qualname__ÚpropertyÚstrr)   r+   r,   r'   r'   r'   r(   r   5   s    r   Úentry.Úinfor    c                 C   sj   | r)| d dkr)|r|d dkr|d7 }n|dd… }| dd… } | r)| d dkst tjg |¢| ¢R Ž ƒS )aì  Convert a legacy installed-files.txt path into modern RECORD path.

    The legacy format stores paths relative to the info directory, while the
    modern format stores paths relative to the package root, e.g. the
    site-packages directory.

    :param entry: Path parts of the installed-files.txt entry.
    :param info: Path parts of the egg-info directory relative to package root.
    :returns: The converted entry.

    For best compatibility with symlinks, this does not use ``abspath()`` or
    ``Path.resolve()``, but tries to work with path parts:

    1. While ``entry`` starts with ``..``, remove the equal amounts of parts
       from ``info``; if ``info`` is empty, start appending ``..`` instead.
    2. Join the two directly.
    r   ú..éÿÿÿÿ)r4   Né   ©r1   ÚpathlibÚPath)r2   r3   r'   r'   r(   Ú_convert_installed_files_pathC   s   
ûr:   c                   @   s|  e Zd Zdefdd„Zdefdd„Zedee fdd„ƒZedee fdd	„ƒZ	edee fd
d„ƒZ
edee fdd„ƒZedefdd„ƒZedefdd„ƒZedefdd„ƒZedefdd„ƒZedefdd„ƒZedefdd„ƒZedefdd„ƒZedee fdd„ƒZedefdd„ƒZedefd d!„ƒZedefd"d#„ƒZedefd$d%„ƒZedefd&d'„ƒZd(edefd)d*„Zd(edee j! fd+d,„Z"d(edefd-d.„Z#de$e% fd/d0„Z&ede'j(j)fd1d2„ƒZ*edee fd3d4„ƒZ+edefd5d6„ƒZ,ede-fd7d8„ƒZ.dFd:e/e de$e0 fd;d<„Z1de$e fd=d>„Z2deee  fd?d@„Z3deee  fdAdB„Z4deee  fdCdD„Z5dES )GÚBaseDistributionr    c                 C   s   | j › d| j› d| j› d�S )Nú z (ú))Úraw_nameÚversionÚlocationr%   r'   r'   r(   Ú__repr__b   s   zBaseDistribution.__repr__c                 C   s   | j › d| j› �S )Nr<   )r>   r?   r%   r'   r'   r(   Ú__str__e   s   zBaseDistribution.__str__c                 C   r!   )aÐ  Where the distribution is loaded from.

        A string value is not necessarily a filesystem path, since distributions
        can be loaded from other sources, e.g. arbitrary zip archives. ``None``
        means the distribution is created in-memory.

        Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
        this is a symbolic link, we want to preserve the relative path between
        it and files in the distribution.
        r#   r%   r'   r'   r(   r@   h   s   zBaseDistribution.locationc                 C   s8   | j }|r| ¡ rt|jƒS dS t| jƒ}|r| jS dS )zÉThe project location for editable distributions.

        This is the directory where pyproject.toml or setup.py is located.
        None if the distribution is not installed in editable mode.
        N)Ú
direct_urlÚis_local_editabler   Úurlr   r>   r@   )r&   rC   Úegg_link_pathr'   r'   r(   Úeditable_project_locationv   s   
	
ûz*BaseDistribution.editable_project_locationc                 C   s2   t | jƒ}|r|}t|ƒS | jr| j}t|ƒS dS )a’  The distribution's "installed" location.

        This should generally be a ``site-packages`` directory. This is
        usually ``dist.location``, except for legacy develop-installed packages,
        where ``dist.location`` is the source code location, and this is where
        the ``.egg-link`` file is.

        The returned location is normalized (in particular, with symlinks removed).
        N)r   r>   r@   r   )r&   Úegg_linkr@   r'   r'   r(   Úinstalled_locationŒ   s   
üÿz#BaseDistribution.installed_locationc                 C   r!   )a/  Location of the .[egg|dist]-info directory or file.

        Similarly to ``location``, a string value is not necessarily a
        filesystem path. ``None`` means the distribution is created in-memory.

        For a modern .dist-info installation on disk, this should be something
        like ``{location}/{raw_name}-{version}.dist-info``.

        Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
        this is a symbolic link, we want to preserve the relative path between
        it and other files in the distribution.
        r#   r%   r'   r'   r(   Úinfo_location    s   zBaseDistribution.info_locationc                 C   s   | j }|sdS t |¡ ¡ S )a  Whether this distribution is installed with legacy distutils format.

        A distribution installed with "raw" distutils not patched by setuptools
        uses one single file at ``info_location`` to store metadata. We need to
        treat this specially on uninstallation.
        F)rJ   r8   r9   Úis_file©r&   rJ   r'   r'   r(   Úinstalled_by_distutils°   s   z'BaseDistribution.installed_by_distutilsc                 C   s   | j }|sdS | d¡S )z¦Whether this distribution is installed as an egg.

        This usually indicates the distribution was installed by (older versions
        of) easy_install.
        Fz.egg)r@   Úendswith©r&   r@   r'   r'   r(   Úinstalled_as_egg½   s   
z!BaseDistribution.installed_as_eggc                 C   ó*   | j }|sdS | d¡sdS t |¡ ¡ S )aÙ  Whether this distribution is installed with the ``.egg-info`` format.

        This usually indicates the distribution was installed with setuptools
        with an old pip version or with ``single-version-externally-managed``.

        Note that this ensure the metadata store is a directory. distutils can
        also installs an ``.egg-info``, but as a file, not a directory. This
        property is *False* for that case. Also see ``installed_by_distutils``.
        Fz	.egg-info©rJ   rN   r8   r9   Úis_dirrL   r'   r'   r(   Ú"installed_with_setuptools_egg_infoÉ   s   
z3BaseDistribution.installed_with_setuptools_egg_infoc                 C   rQ   )aa  Whether this distribution is installed with the "modern format".

        This indicates a "modern" installation, e.g. storing metadata in the
        ``.dist-info`` directory. This applies to installations made by
        setuptools (but through pip, not directly), or anything using the
        standardized build backend interface (PEP 517).
        Fz
.dist-inforR   rL   r'   r'   r(   Úinstalled_with_dist_infoÛ   s   	
z)BaseDistribution.installed_with_dist_infoc                 C   r!   r"   r#   r%   r'   r'   r(   Úcanonical_nameë   r*   zBaseDistribution.canonical_namec                 C   r!   r"   r#   r%   r'   r'   r(   r?   ï   r*   zBaseDistribution.versionc                 C   s   | j  dd¡S )z”Convert a project name to its setuptools-compatible filename.

        This is a copy of ``pkg_resources.to_filename()`` for compatibility.
        ú-Ú_)r>   Úreplacer%   r'   r'   r(   Úsetuptools_filenameó   s   z$BaseDistribution.setuptools_filenamec              
   C   sr   z|   t¡}W n
 ty   Y dS w zt |¡W S  ttjtfy8 } zt	 
dt| j|¡ W Y d}~dS d}~ww )z¬Obtain a DirectUrl from this distribution.

        Returns None if the distribution has no `direct_url.json` metadata,
        or if `direct_url.json` is invalid.
        NzError parsing %s for %s: %s)Ú	read_textr   ÚFileNotFoundErrorr   Ú	from_jsonÚUnicodeDecodeErrorÚjsonÚJSONDecodeErrorr   ÚloggerÚwarningrV   )r&   ÚcontentÚer'   r'   r(   rC   û   s*   ÿýü€õzBaseDistribution.direct_urlc              
   C   sP   z|   d¡}W n tttfy   Y dS w | ¡ D ]}| ¡ }|r%|  S qdS )NÚ	INSTALLERÚ )r[   ÚOSErrorÚ
ValueErrorr   Ú
splitlinesÚstrip)r&   Úinstaller_textÚlineÚcleaned_liner'   r'   r(   Ú	installer  s   ÿÿzBaseDistribution.installerc                 C   s
   t | jƒS r"   )ÚboolrG   r%   r'   r'   r(   Úeditable!  s   
zBaseDistribution.editablec                 C   s   | j du rdS t| j ƒS )z|If distribution is installed in the current virtual environment.

        Always True if we're not in a virtualenv.
        NF)rI   r   r%   r'   r'   r(   Úlocal%  s   

zBaseDistribution.localc                 C   ó&   | j d u s	td u rdS | j  ttƒ¡S ©NF)rI   r   Ú
startswithr   r%   r'   r'   r(   Úin_usersite/  ó   zBaseDistribution.in_usersitec                 C   rr   rs   )rI   r   rt   r   r%   r'   r'   r(   Úin_site_packages5  rv   z!BaseDistribution.in_site_packagesÚpathc                 C   r!   )z7Check whether an entry in the info directory is a file.r#   ©r&   rx   r'   r'   r(   rK   ;  r*   zBaseDistribution.is_filec                 C   r!   )a$  Iterate through a directory in the info directory.

        Each item yielded would be a path relative to the info directory.

        :raise FileNotFoundError: If ``name`` does not exist in the directory.
        :raise NotADirectoryError: If ``name`` does not point to a directory.
        r#   ry   r'   r'   r(   Úiterdir?  s   zBaseDistribution.iterdirc                 C   r!   )zçRead a file in the info directory.

        :raise FileNotFoundError: If ``name`` does not exist in the directory.
        :raise NoneMetadataError: If ``name`` exists in the info directory, but
            cannot be read.
        r#   ry   r'   r'   r(   r[   I  ó   zBaseDistribution.read_textc                 C   r!   r"   r#   r%   r'   r'   r(   Úiter_entry_pointsR  ó   z"BaseDistribution.iter_entry_pointsc                 C   r!   )a  Metadata of distribution parsed from e.g. METADATA or PKG-INFO.

        This should return an empty message if the metadata file is unavailable.

        :raises NoneMetadataError: If the metadata file is available, but does
            not contain valid metadata.
        r#   r%   r'   r'   r(   ÚmetadataU  s   	zBaseDistribution.metadatac                 C   s   | j  d¡S )zDValue of "Metadata-Version:" in distribution metadata, if available.zMetadata-Version)r~   Úgetr%   r'   r'   r(   Úmetadata_version`  s   z!BaseDistribution.metadata_versionc                 C   s   | j  d| j¡S )z*Value of "Name:" in distribution metadata.ÚName)r~   r   rV   r%   r'   r'   r(   r>   e  s   zBaseDistribution.raw_namec              
   C   sl   | j  d¡}|du rtƒ S z	tt|ƒƒ}W |S  ty5 } zd}t || j|¡ tƒ W  Y d}~S d}~ww )z±Value of "Requires-Python:" in distribution metadata.

        If the key does not exist or contains an invalid value, an empty
        SpecifierSet should be returned.
        zRequires-PythonNz-Package %r has an invalid Requires-Python: %s)r~   r   r   r1   r   ra   rb   r>   )r&   r+   Úspecrd   Úmessager'   r'   r(   Úrequires_pythonl  s   ü€ýz BaseDistribution.requires_pythonr'   Úextrasc                 C   r!   )z®Dependencies of this distribution.

        For modern .dist-info distributions, this is the collection of
        "Requires-Dist:" entries in distribution metadata.
        r#   )r&   r…   r'   r'   r(   Úiter_dependencies  ó   z"BaseDistribution.iter_dependenciesc                 C   r!   )z²Extras provided by this distribution.

        For modern .dist-info distributions, this is the collection of
        "Provides-Extra:" entries in distribution metadata.
        r#   r%   r'   r'   r(   Úiter_provided_extras‡  r‡   z%BaseDistribution.iter_provided_extrasc                 C   s<   z|   d¡}W n
 ty   Y d S w dd„ t | ¡ ¡D ƒS )NÚRECORDc                 s   s"   � | ]}t t |d  ¡ƒV  qdS )r   Nr7   )Ú.0Úrowr'   r'   r(   Ú	<genexpr>•  s   €  zFBaseDistribution._iter_declared_entries_from_record.<locals>.<genexpr>)r[   r\   ÚcsvÚreaderri   )r&   Útextr'   r'   r(   Ú"_iter_declared_entries_from_record�  s   ÿz3BaseDistribution._iter_declared_entries_from_recordc                    s¢   z|   d¡}W n
 ty   Y d S w dd„ |jdd�D ƒ}| j}| j}|d u s+|d u r-|S z
t |¡ |¡‰ W n tyB   | Y S w ˆ j	sH|S ‡ fdd„|D ƒS )Nzinstalled-files.txtc                 s   s   � | ]}|r|V  qd S r"   r'   ©rŠ   Úpr'   r'   r(   rŒ   œ  s   € zFBaseDistribution._iter_declared_entries_from_legacy.<locals>.<genexpr>F)Úkeependsc                 3   s$   � | ]}t t |¡jˆ jƒV  qd S r"   )r:   r8   r9   Úpartsr‘   ©Úinfo_relr'   r(   rŒ   §  s
   € ÿ
ÿ)
r[   r\   ri   r@   rJ   r8   r9   Úrelative_torh   r”   )r&   r�   ÚpathsÚrootr3   r'   r•   r(   Ú"_iter_declared_entries_from_legacy—  s(   ÿÿ
þz3BaseDistribution._iter_declared_entries_from_legacyc                 C   s   |   ¡ p|  ¡ S )aò  Iterate through file entires declared in this distribution.

        For modern .dist-info distributions, this is the files listed in the
        ``RECORD`` metadata file. For legacy setuptools distributions, this
        comes from ``installed-files.txt``, with entries normalized to be
        compatible with the format used by ``RECORD``.

        :return: An iterator for listed entries, or None if the distribution
            contains neither ``RECORD`` nor ``installed-files.txt``.
        )r�   rš   r%   r'   r'   r(   Úiter_declared_entries¬  s   þz&BaseDistribution.iter_declared_entriesN)r'   )6r-   r.   r/   r1   rA   rB   r0   r	   r@   rG   rI   rJ   ro   rM   rP   rT   rU   r   rV   ÚDistributionVersionr?   rZ   r   rC   rn   rp   rq   ru   rw   ÚInfoPathrK   r   r8   ÚPurePosixPathrz   r[   r   r   r|   Úemailrƒ   ÚMessager~   r€   r>   r   r„   r   r   r†   rˆ   r�   rš   r›   r'   r'   r'   r(   r;   a   sl    	
	
r;   c                   @   s¬   e Zd ZdZeddd„ƒZedeee  dd fdd„ƒZ	deded	 fd
d„Z
ded	 fdd„Zded	 fdd„Zdedddfdedee dedededee fdd„ZdS )ÚBaseEnvironmentz6An environment containing distributions to introspect.r    c                 C   r!   r"   r#   )Úclsr'   r'   r(   ÚdefaultÀ  r*   zBaseEnvironment.defaultr˜   c                 C   r!   r"   r#   )r¢   r˜   r'   r'   r(   Ú
from_pathsÄ  r*   zBaseEnvironment.from_pathsr)   r;   c                 C   r!   )z«Given a requirement name, return the installed distributions.

        The name may not be normalized. The implementation must canonicalize
        it for lookup.
        r#   )r&   r)   r'   r'   r(   Úget_distributionÈ  r‡   z BaseEnvironment.get_distributionc                 C   r!   )a  Iterate through installed distributions.

        This function should be implemented by subclass, but never called
        directly. Use the public ``iter_distribution()`` instead, which
        implements additional logic to make sure the distributions are valid.
        r#   r%   r'   r'   r(   Ú_iter_distributionsÐ  r{   z#BaseEnvironment._iter_distributionsc                 c   sF   � |   ¡ D ]}tjd|jtjd�}|st d|j|j¡ q|V  qdS )z(Iterate through installed distributions.z)^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$)Úflagsz%Ignoring invalid distribution %s (%s)N)r¦   ÚreÚmatchrV   Ú
IGNORECASEra   rb   r@   )r&   ÚdistÚproject_name_validr'   r'   r(   Úiter_distributionsÙ  s    €ýýïz"BaseEnvironment.iter_distributionsTFÚ
local_onlyÚskipÚinclude_editablesÚeditables_onlyÚ	user_onlyc                    sb   |   ¡ }|rdd„ |D ƒ}|sdd„ |D ƒ}|rdd„ |D ƒ}|r(dd„ |D ƒ}‡ fdd„|D ƒS )a  Return a list of installed distributions.

        :param local_only: If True (default), only return installations
        local to the current virtualenv, if in a virtualenv.
        :param skip: An iterable of canonicalized project names to ignore;
            defaults to ``stdlib_pkgs``.
        :param include_editables: If False, don't report editables.
        :param editables_only: If True, only report editables.
        :param user_only: If True, only report installations in the user
        site directory.
        c                 s   ó   � | ]}|j r|V  qd S r"   )rq   ©rŠ   Údr'   r'   r(   rŒ     ó   € z?BaseEnvironment.iter_installed_distributions.<locals>.<genexpr>c                 s   s   � | ]}|j s|V  qd S r"   ©rp   r´   r'   r'   r(   rŒ     r¶   c                 s   r³   r"   r·   r´   r'   r'   r(   rŒ     r¶   c                 s   r³   r"   )ru   r´   r'   r'   r(   rŒ   	  r¶   c                 3   s   � | ]
}|j ˆ vr|V  qd S r"   )rV   r´   ©r¯   r'   r(   rŒ   
  s   € )r­   )r&   r®   r¯   r°   r±   r²   Úitr'   r¸   r(   Úiter_installed_distributionsî  s   z,BaseEnvironment.iter_installed_distributionsN)r    r¡   )r-   r.   r/   Ú__doc__Úclassmethodr£   r	   r   r1   r¤   r¥   r   r¦   r­   r   ro   r   r;   rº   r'   r'   r'   r(   r¡   ½  s6    	úþýüûúùr¡   c                   @   s&   e Zd ZU eed< dejfdd„ZdS )ÚWheelr@   r    c                 C   r!   r"   r#   r%   r'   r'   r(   Ú
as_zipfile  r}   zWheel.as_zipfileN)r-   r.   r/   r1   Ú__annotations__ÚzipfileÚZipFiler¾   r'   r'   r'   r(   r½     s   
 r½   c                   @   s.   e Zd Zdeddfdd„Zdejfdd„ZdS )ÚFilesystemWheelr@   r    Nc                 C   s
   || _ d S r"   )r@   rO   r'   r'   r(   Ú__init__  s   
zFilesystemWheel.__init__c                 C   ó   t j| jdd�S ©NT)Ú
allowZip64)rÀ   rÁ   r@   r%   r'   r'   r(   r¾     ó   zFilesystemWheel.as_zipfile)r-   r.   r/   r1   rÃ   rÀ   rÁ   r¾   r'   r'   r'   r(   rÂ     s    rÂ   c                   @   s6   e Zd Zdedee ddfdd„Zdejfdd„Z	dS )	ÚMemoryWheelr@   Ústreamr    Nc                 C   s   || _ || _d S r"   )r@   rÉ   )r&   r@   rÉ   r'   r'   r(   rÃ     s   
zMemoryWheel.__init__c                 C   rÄ   rÅ   )rÀ   rÁ   rÉ   r%   r'   r'   r(   r¾   !  rÇ   zMemoryWheel.as_zipfile)
r-   r.   r/   r1   r   ÚbytesrÃ   rÀ   rÁ   r¾   r'   r'   r'   r(   rÈ     s    rÈ   )@r�   Úemail.messagerŸ   r_   Úloggingr8   r¨   rÀ   Útypingr   r   r   r   r   r   r   r	   r
   r   Ú"pip._vendor.packaging.requirementsr   Ú pip._vendor.packaging.specifiersr   r   Úpip._vendor.packaging.utilsr   Úpip._vendor.packaging.versionr   r   Úpip._internal.exceptionsr   Úpip._internal.locationsr   r   Úpip._internal.models.direct_urlr   r   r   Úpip._internal.utils.compatr   Úpip._internal.utils.egg_linkr   r   Úpip._internal.utils.miscr   r   Úpip._internal.utils.urlsr   r   Úobjectrœ   r1   rž   r�   Ú	getLoggerr-   ra   r   r:   r;   r¡   r½   rÂ   rÈ   r'   r'   r'   r(   Ú<module>   sP    0

ÿ
þ
ý  ^P