U
    
Ha                     @   s   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 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 erd dlmZ d dlmZ neZeeef ZeeZ G d	d
 d
eZ!G dd deZ"G dd dZ#dS )    N)TYPE_CHECKING
Collection	ContainerIterableIteratorListOptionalUnion)Requirement)LegacyVersionVersion)DIRECT_URL_METADATA_NAME	DirectUrlDirectUrlValidationError)stdlib_pkgs)Protocol)NormalizedNamec                   @   sB   e Zd ZeedddZeedddZeedddZdS )	BaseEntryPointreturnc                 C   s
   t  d S NNotImplementedErrorself r   ?/tmp/pip-unpacked-wheel-tx790h60/pip/_internal/metadata/base.pyname'   s    zBaseEntryPoint.namec                 C   s
   t  d S r   r   r   r   r   r   value+   s    zBaseEntryPoint.valuec                 C   s
   t  d S r   r   r   r   r   r   group/   s    zBaseEntryPoint.groupN)__name__
__module____qualname__propertystrr   r   r   r   r   r   r   r   &   s   r   c                   @   sF  e Zd Zeee dddZeee dddZeddddZee	dd	d
Z
eee dddZeedddZeedddZeedddZeedddZeedddZeedddZee dddZeejjdddZeee dddZeedd d!Zd'ee ee d#d$d%Zd&S )(BaseDistributionr   c                 C   s
   t  dS )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.
        Nr   r   r   r   r   location5   s    zBaseDistribution.locationc                 C   s
   t  dS )a'  Location of the .[egg|dist]-info directory.

        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.
        Nr   r   r   r   r   info_directoryC   s    zBaseDistribution.info_directoryr   c                 C   s
   t  d S r   r   r   r   r   r   canonical_nameS   s    zBaseDistribution.canonical_namec                 C   s
   t  d S r   r   r   r   r   r   versionW   s    zBaseDistribution.versionc              
   C   sz   z|  t}W n tk
r$   Y dS X zt|W S  ttjtfk
rt } zt	
dt| j| W Y dS d}~X Y nX dS )zObtain 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   Z	from_jsonUnicodeDecodeErrorjsonJSONDecodeErrorr   loggerwarningr(   )r   contenter   r   r   
direct_url[   s$    zBaseDistribution.direct_urlc                 C   s
   t  d S r   r   r   r   r   r   	installeru   s    zBaseDistribution.installerc                 C   s
   t  d S r   r   r   r   r   r   editabley   s    zBaseDistribution.editablec                 C   s
   t  d S r   r   r   r   r   r   local}   s    zBaseDistribution.localc                 C   s
   t  d S r   r   r   r   r   r   in_usersite   s    zBaseDistribution.in_usersitec                 C   s
   t  d S r   r   r   r   r   r   in_site_packages   s    z!BaseDistribution.in_site_packagesr   r   c                 C   s
   t  dS )zRead a file in the .dist-info (or .egg-info) directory.

        Should raise ``FileNotFoundError`` if ``name`` does not exist in the
        metadata directory.
        Nr   r   r   r   r   r   r*      s    zBaseDistribution.read_textc                 C   s
   t  d S r   r   r   r   r   r   iter_entry_points   s    z"BaseDistribution.iter_entry_pointsc                 C   s
   t  dS )z?Metadata of distribution parsed from e.g. METADATA or PKG-INFO.Nr   r   r   r   r   metadata   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=   r(   r   r   r   r   raw_name   s    zBaseDistribution.raw_namer   )extrasr   c                 C   s
   t  d S r   r   )r   rA   r   r   r   iter_dependencies   s    z"BaseDistribution.iter_dependenciesN)r   ) r    r!   r"   r#   r   r$   r&   r'   r(   DistributionVersionr)   r   r3   r4   boolr5   r6   r7   r8   r*   r   r   r;   emailmessageMessager<   r>   r@   r   r
   rB   r   r   r   r   r%   4   s:   r%   c                   @   s   e Zd ZdZed dddZeeee  d dddZ	eed d	d
dZ
ed dddZed dddZdedddfeee eeeee dddZdS )BaseEnvironmentz6An environment containing distributions to introspect.r   c                 C   s
   t  d S r   r   )clsr   r   r   default   s    zBaseEnvironment.default)pathsr   c                 C   s
   t  d S r   r   )rI   rK   r   r   r   
from_paths   s    zBaseEnvironment.from_pathsr%   r9   c                 C   s
   t  dS )z=Given a requirement name, return the installed distributions.Nr   r:   r   r   r   get_distribution   s    z BaseEnvironment.get_distributionc                 C   s
   t  dS )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.
        Nr   r   r   r   r   _iter_distributions   s    z#BaseEnvironment._iter_distributionsc                 c   sD   |   D ]6}tjd|jtjd}|s8t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)rN   rematchr(   
IGNORECASEr/   r0   r&   )r   distZproject_name_validr   r   r   iter_distributions   s    z"BaseEnvironment.iter_distributionsTF)
local_onlyskipinclude_editableseditables_only	user_onlyr   c                    sb   |   }|rdd |D }|s,dd |D }|r>dd |D }|rPd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   s   | ]}|j r|V  qd S r   )r6   .0dr   r   r   	<genexpr>   s      z?BaseEnvironment.iter_installed_distributions.<locals>.<genexpr>c                 s   s   | ]}|j s|V  qd S r   r5   rZ   r   r   r   r]      s      c                 s   s   | ]}|j r|V  qd S r   r^   rZ   r   r   r   r]      s      c                 s   s   | ]}|j r|V  qd S r   )r7   rZ   r   r   r   r]      s      c                 3   s   | ]}|j  kr|V  qd S r   )r(   rZ   rV   r   r   r]      s     
 )rT   )r   rU   rV   rW   rX   rY   itr   r_   r   iter_installed_distributions   s    z,BaseEnvironment.iter_installed_distributionsN)r    r!   r"   __doc__classmethodrJ   r   r   r$   rL   rM   r   rN   rT   r   rD   r   r%   ra   r   r   r   r   rH      s*   	rH   )$email.messagerE   r-   loggingrP   typingr   r   r   r   r   r   r   r	   "pip._vendor.packaging.requirementsr
   Zpip._vendor.packaging.versionr   r   Zpip._internal.models.direct_urlr   r   r   pip._internal.utils.miscr   r   pip._vendor.packaging.utilsr   objectrC   	getLoggerr    r/   r   r%   rH   r   r   r   r   <module>   s"   (
u