U
    8hW                      @   s$  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	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 d dlmZmZ d d	lmZm Z m!Z!m"Z" d d
l#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ G dd dej0j1Z2G dd deZ1dS )    N)PathLike)	
CollectionDictIterableIteratorMappingOptionalSequenceUnioncast)Requirement)NormalizedNamecanonicalize_name)Version)parse)InvalidWheelUnsupportedWheel)BaseDistributionBaseEntryPointInfoPathWheel)normalize_path)get_requirement)TempDirectory)parse_wheelread_wheel_metadata_file   )BasePathget_dist_canonical_name*parse_name_and_version_from_info_directoryc                   @   s   e Zd ZdZeejef ejddddZe	e
jeed dddZeeej d	d
dZeee dddZeedf ejd	ddZdS )WheelDistributiona  An ``importlib.metadata.Distribution`` read from a wheel.

    Although ``importlib.metadata.PathDistribution`` accepts ``zipfile.Path``,
    its implementation is too "lazy" for pip's needs (we can't keep the ZipFile
    handle open for the entire lifetime of the distribution object).

    This implementation eagerly reads the entire metadata directory into the
    memory instead, and operates from that.
    N)filesinfo_locationreturnc                 C   s   || _ || _d S N)_filesr"   )selfr!   r"    r'   eC:\Users\jeffr\AppData\Local\Temp\pip-install-hfyjq797\pip\pip\_internal\metadata\importlib\_dists.py__init__5   s    zWheelDistribution.__init__)zfnamelocationr#   c                    sL   t |\ } fdd D }fdd|D }t| }| ||S )Nc                 3   s8   | ]0}|   d r|t|d dd fV  qdS )/r   N)
startswithpathlibPurePosixPathsplit).0r+   )info_dirr'   r(   	<genexpr>E   s   z1WheelDistribution.from_zipfile.<locals>.<genexpr>c                    s   i | ]\}}|t  |qS r'   )r   )r3   fullpathrelpath)r*   r'   r(   
<dictcomp>J   s    z2WheelDistribution.from_zipfile.<locals>.<dictcomp>)r   namelistr0   r1   )clsr*   r+   r,   _pathsr!   r"   r'   )r4   r*   r(   from_zipfile=   s    

zWheelDistribution.from_zipfilepathr#   c                 C   s*   t t|| jkrt| jS t|d S r$   )r0   r1   strr%   iterFileNotFoundErrorr&   r?   r'   r'   r(   iterdirQ   s    
zWheelDistribution.iterdir)filenamer#   c              
   C   s   z| j t| }W n tk
r*   Y d S X z|d}W nJ tk
r } z,| jj}d| d| d| d}t|W 5 d }~X Y nX |S )Nzutf-8zError decoding metadata for z: z in z file)	r%   r0   r1   KeyErrordecodeUnicodeDecodeErrorr"   parentr   )r&   rE   datatextewheelerrorr'   r'   r(   	read_textW   s    zWheelDistribution.read_textzPathLike[str]c                 C   s   t d S r$   )NotImplementedErrorrC   r'   r'   r(   locate_filed   s    zWheelDistribution.locate_file)__name__
__module____qualname____doc__r   r0   r1   bytesr)   classmethodzipfileZipFiler@   r=   r   r   rD   r   rO   r
   PathrQ   r'   r'   r'   r(   r    *   s   r    c                   @   sh  e Zd Zejjee ee ddddZe	e
edddZe	ee
e
edd	d
Ze	ee
edddZeee
 dddZe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#j$j%dd$d%Z&e e dd&d'Z'd,e(e
 e e) d)d*d+Z*dS )-DistributionN)distr"   installed_locationr#   c                 C   s   || _ || _|| _d S r$   )_dist_info_location_installed_location)r&   r\   r"   r]   r'   r'   r(   r)   k   s    zDistribution.__init__)	directoryr#   c                 C   s&   t |}tjj|}| |||jS r$   )r0   rZ   	importlibmetadatar[   atrI   )r:   ra   r"   r\   r'   r'   r(   from_directoryu   s    
zDistribution.from_directory)metadata_contentsrE   project_namer#   c                 C   sD   t tdddj}|d }|| tjj|j	}| ||j	d S )Nrc   T)kindZglobally_managedMETADATA)
r0   rZ   r   r?   write_bytesrb   rc   r[   rd   rI   )r:   rf   rE   rg   temp_dirZmetadata_pathr\   r'   r'   r(   from_metadata_file_contents{   s    
z(Distribution.from_metadata_file_contents)rM   r+   r#   c              
   C   sr   z(|  }t|||j}W 5 Q R X W n2 tjk
rZ } zt|j||W 5 d }~X Y nX | ||jt	|jS r$   )
Z
as_zipfiler    r=   r,   rX   
BadZipFiler   r"   r0   r1   )r:   rM   r+   r*   r\   rL   r'   r'   r(   
from_wheel   s    
 zDistribution.from_wheel)r#   c                 C   s   | j d krd S t| j jS r$   )r_   r@   rI   r&   r'   r'   r(   r,      s    
zDistribution.locationc                 C   s   | j d krd S t| j S r$   )r_   r@   ro   r'   r'   r(   r"      s    
zDistribution.info_locationc                 C   s   | j d krd S tt| j S r$   )r`   r   r@   ro   r'   r'   r(   r]      s    
zDistribution.installed_locationc                 C   s
   t | jS r$   )r   r^   ro   r'   r'   r(   canonical_name   s    zDistribution.canonical_namec                 C   s&   t | jd  }rt|S t| jjS )Nr   )r   r^   parse_versionversion)r&   rr   r'   r'   r(   rr      s    zDistribution.versionc                 C   s   | j jS r$   )r^   rr   ro   r'   r'   r(   raw_version   s    zDistribution.raw_versionr>   c                 C   s   | j t|d k	S r$   )r^   rO   r@   rC   r'   r'   r(   is_file   s    zDistribution.is_filec                 c   s4   t | jtjsd S | jd D ]}|jV  q"d S )Nscripts)
isinstancer_   r0   rZ   joinpathrD   r+   )r&   childr'   r'   r(   iter_distutils_script_names   s    z(Distribution.iter_distutils_script_namesc                 C   s$   | j t|}|d kr t||S r$   )r^   rO   r@   rB   )r&   r?   contentr'   r'   r(   rO      s    zDistribution.read_textc                 C   s   | j jS r$   )r^   entry_pointsro   r'   r'   r(   iter_entry_points   s    zDistribution.iter_entry_pointsc                 C   s   t tjj| jjS r$   )r   emailmessageMessager^   rc   ro   r'   r'   r(   _metadata_impl   s    zDistribution._metadata_implc                 C   s   dd | j dg D S )Nc                 S   s   g | ]}t |qS r'   )r   )r3   extrar'   r'   r(   
<listcomp>   s   z5Distribution.iter_provided_extras.<locals>.<listcomp>zProvides-Extra)rc   get_allro   r'   r'   r(   iter_provided_extras   s    z!Distribution.iter_provided_extrasr'   )extrasr#   c                 #   sx   dd |D }| j dg D ]V}t|   js: V  q|sV jddirV V  qt fdd|D r V  qd S )Nc                 S   s   g | ]}d |iqS )r   r'   )r3   rL   r'   r'   r(   r      s     z2Distribution.iter_dependencies.<locals>.<listcomp>zRequires-Distr    c                 3   s   | ]} j |V  qd S r$   )markerevaluate)r3   contextreqr'   r(   r5      s     z1Distribution.iter_dependencies.<locals>.<genexpr>)rc   r   r   stripr   r   any)r&   r   Zcontexts
req_stringr'   r   r(   iter_dependencies   s    zDistribution.iter_dependencies)r'   )+rR   rS   rT   rb   rc   r[   r   r   r)   rW   r@   r   re   rV   rl   r   rn   propertyr,   r"   r]   r   rp   r   rr   rs   r   boolrt   r   ry   rO   r   r   r|   r}   r~   r   r   r   r   r   r   r'   r'   r'   r(   r[   j   sD   
	r[   )3email.messager}   importlib.metadatarb   r0   rX   osr   typingr   r   r   r   r   r   r	   r
   r   Z"pip._vendor.packaging.requirementsr   pip._vendor.packaging.utilsr   r   Zpip._vendor.packaging.versionr   r   rq   pip._internal.exceptionsr   r   Zpip._internal.metadata.baser   r   r   r   pip._internal.utils.miscr   pip._internal.utils.packagingr   pip._internal.utils.temp_dirr   Zpip._internal.utils.wheelr   r   _compatr   r   r   rc   r[   r    r'   r'   r'   r(   <module>   s$   ,@