o
    "gW                      @   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deejef dejddfddZe	de
jd	ed
edd fddZdedeej fddZdedee fddZdeedf dejf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.
    filesinfo_locationreturnNc                 C   s   || _ || _d S N)_filesr"   )selfr!   r"    r'   f/root/parts/websockify/install/lib/python3.10/site-packages/pip/_internal/metadata/importlib/_dists.py__init__5   s   
zWheelDistribution.__init__zfnamelocationc                    sL   t |\ } fdd D }fdd|D }t| }| ||S )Nc                 3   s:    | ]}|   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pathc                 C   s&   t t|| jv rt| jS t|r$   )r0   r1   strr%   iterFileNotFoundErrorr&   r>   r'   r'   r(   iterdirQ   s   
zWheelDistribution.iterdirfilenamec              
   C   s|   z
| j t| }W n
 ty   Y d S w z|d}W |S  ty= } z| jj}d| d| d| d}t|d }~ww )Nzutf-8zError decoding metadata for z: z in z file)	r%   r0   r1   KeyErrordecodeUnicodeDecodeErrorr"   parentr   )r&   rD   datatextewheelerrorr'   r'   r(   	read_textW   s   zWheelDistribution.read_textzPathLike[str]c                 C   s   t r$   )NotImplementedErrorrB   r'   r'   r(   locate_filed   s   zWheelDistribution.locate_file)__name__
__module____qualname____doc__r   r0   r1   bytesr)   classmethodzipfileZipFiler?   r=   r   r   rC   r   rN   r
   PathrP   r'   r'   r'   r(   r    *   s,    

 r    c                	   @   s  e Zd Zdejjdee dee ddfddZe	de
defd	d
Ze	dede
de
defddZe	dede
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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e
 fd#d$Zd ede
fd%d&Zde e! fd'd(Z"de#j$j%fd)d*Z&de e fd+d,Z'd1d.e(e
 de e) fd/d0Z*dS )2Distributiondistr"   installed_locationr#   Nc                 C   s   || _ || _|| _d S r$   )_dist_info_location_installed_location)r&   r[   r"   r\   r'   r'   r(   r)   k   s   
zDistribution.__init__	directoryc                 C   s&   t |}tjj|}| |||jS r$   )r0   rY   	importlibmetadatarZ   atrH   )r:   r`   r"   r[   r'   r'   r(   from_directoryu   s   
zDistribution.from_directorymetadata_contentsrD   project_namec                 C   sD   t tdddj}|d }|| tjj|j	}| ||j	d S )Nrb   T)kindglobally_managedMETADATA)
r0   rY   r   r>   write_bytesra   rb   rZ   rc   rH   )r:   re   rD   rf   temp_dirmetadata_pathr[   r'   r'   r(   from_metadata_file_contents{   s   
z(Distribution.from_metadata_file_contentsrL   r+   c              
   C   s|   z|  }t|||j}W d    n1 sw   Y  W n tjy2 } zt|j||d }~ww | ||jt	|jS r$   )

as_zipfiler    r=   r,   rW   
BadZipFiler   r"   r0   r1   )r:   rL   r+   r*   r[   rK   r'   r'   r(   
from_wheel   s   
zDistribution.from_wheelc                 C   s   | j d u rd S t| j jS r$   )r^   r?   rH   r&   r'   r'   r(   r,      s   
zDistribution.locationc                 C   s   | j d u rd S t| j S r$   )r^   r?   rq   r'   r'   r(   r"      s   

zDistribution.info_locationc                 C   s   | j d u rd S tt| j S r$   )r_   r   r?   rq   r'   r'   r(   r\      s   
zDistribution.installed_locationc                 C   s
   t | jS r$   )r   r]   rq   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&   rt   r'   r'   r(   rt      s   zDistribution.versionc                 C      | j jS r$   )r]   rt   rq   r'   r'   r(   raw_version      zDistribution.raw_versionr>   c                 C   s   | j t|d uS r$   )r]   rN   r?   rB   r'   r'   r(   is_file   s   zDistribution.is_filec                 c   s6    t | jtjs
d S | jd D ]}|jV  qd S )Nscripts)
isinstancer^   r0   rY   joinpathrC   r+   )r&   childr'   r'   r(   iter_distutils_script_names   s   
z(Distribution.iter_distutils_script_namesc                 C   s$   | j t|}|d u rt||S r$   )r]   rN   r?   rA   )r&   r>   contentr'   r'   r(   rN      s   zDistribution.read_textc                 C   ru   r$   )r]   entry_pointsrq   r'   r'   r(   iter_entry_points   rw   zDistribution.iter_entry_pointsc                 C   s   t tjj| jjS r$   )r   emailmessageMessager]   rb   rq   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)rb   get_allrq   r'   r'   r(   iter_provided_extras   s   z!Distribution.iter_provided_extrasr'   extrasc                 #   sz    dd |D }| j dg D ]+}t|   js V  q|s, jddir, V  qt fdd|D r: V  qd S )Nc                 S   s   g | ]}d |iqS )r   r'   )r3   rK   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>)rb   r   r   stripr   r   any)r&   r   contexts
req_stringr'   r   r(   iter_dependencies   s   zDistribution.iter_dependencies)r'   )+rQ   rR   rS   ra   rb   rZ   r   r   r)   rV   r?   r   rd   rU   rm   r   rp   propertyr,   r"   r\   r   rr   r   rt   rv   r   boolrx   r   r}   rN   r   r   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   rZ   j   sV    

	 rZ   )3email.messager   importlib.metadatara   r0   rW   osr   typingr   r   r   r   r   r   r	   r
   r   "pip._vendor.packaging.requirementsr   pip._vendor.packaging.utilsr   r   pip._vendor.packaging.versionr   r   rs   pip._internal.exceptionsr   r   pip._internal.metadata.baser   r   r   r   pip._internal.utils.miscr   pip._internal.utils.packagingr   pip._internal.utils.temp_dirr   pip._internal.utils.wheelr   r   _compatr   r   r   rb   rZ   r    r'   r'   r'   r(   <module>   s&    ,@