o
    zqfi                      @   s  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 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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* G dd dej+j,Z-G dd deZ,dS )    N)
CollectionDictIterableIteratorMappingOptionalSequencecast)Requirement)NormalizedNamecanonicalize_name)parse)InvalidWheelUnsupportedWheel)BaseDistributionBaseEntryPointDistributionVersionInfoPathWheel)normalize_path)TempDirectory)parse_wheelread_wheel_metadata_file   )BasePathget_dist_namec                	   @   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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__/   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>?   s    
z1WheelDistribution.from_zipfile.<locals>.<genexpr>c                    s   i | ]
\}}|t  |qS r#   )r   )r/   fullpathrelpath)r&   r#   r$   
<dictcomp>D   s    
z2WheelDistribution.from_zipfile.<locals>.<dictcomp>)r   namelistr,   r-   )clsr&   r'   r(   _pathsr   r   r#   )r0   r&   r$   from_zipfile7   s   


zWheelDistribution.from_zipfilepathc                 C   s&   t t|| jv rt| jS t|r    )r,   r-   strr!   iterFileNotFoundErrorr"   r:   r#   r#   r$   iterdirK   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!   r,   r-   KeyErrordecodeUnicodeDecodeErrorr   parentr   )r"   r@   datatextewheelerrorr#   r#   r$   	read_textQ   s   zWheelDistribution.read_text)__name__
__module____qualname____doc__r   r,   r-   bytesr%   classmethodzipfileZipFiler;   r9   r   r   r?   r   rJ   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de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'd-e
defd.d/Z(d4d1e)e
 de e* fd2d3Z+dS )5Distributiondistr   installed_locationr   Nc                 C   s   || _ || _|| _d S r    )_dist_info_location_installed_location)r"   rT   r   rU   r#   r#   r$   r%   `   s   
zDistribution.__init__	directoryc                 C   s&   t |}tjj|}| |||jS r    )r,   Path	importlibmetadatarS   atrD   )r6   rY   r   rT   r#   r#   r$   from_directoryj   s   
zDistribution.from_directorymetadata_contentsr@   project_namec                 C   sD   t tdddj}|d }|| tjj|j	}| ||j	d S )Nr\   T)kindglobally_managedMETADATA)
r,   rZ   r   r:   write_bytesr[   r\   rS   r]   rD   )r6   r_   r@   r`   temp_dirmetadata_pathrT   r#   r#   r$   from_metadata_file_contentsp   s   
z(Distribution.from_metadata_file_contentsrH   r'   c              
   C   s   z|  }t|||j}W d    n1 sw   Y  W n( tjy2 } zt|j||d }~w tyF } z	t| d| d }~ww | ||jt	
|jS )Nz has an invalid wheel, )
as_zipfiler   r9   r(   rQ   
BadZipFiler   r   r   r,   r-   )r6   rH   r'   r&   rT   rG   r#   r#   r$   
from_wheel   s   
zDistribution.from_wheelc                 C   s   | j d u rd S t| j jS r    )rW   r;   rD   r"   r#   r#   r$   r(      s   
zDistribution.locationc                 C   s   | j d u rd S t| j S r    )rW   r;   rk   r#   r#   r$   r      s   

zDistribution.info_locationc                 C   s   | j d u rd S tt| j S r    )rX   r   r;   rk   r#   r#   r$   rU      s   
zDistribution.installed_locationc                 C   s>   | j du rdS tj| j j\}}|dvrdS |ddd S )zrTry to get the name from the metadata directory name.

        This is much faster than reading metadata.
        N)z
.dist-infoz	.egg-info-r   r   )rW   osr:   splitextr'   r.   )r"   stemsuffixr#   r#   r$   _get_dist_name_from_location   s   
z)Distribution._get_dist_name_from_locationc                 C   s   |   pt| j}t|S r    )rq   r   rV   r   )r"   r'   r#   r#   r$   canonical_name   s   zDistribution.canonical_namec                 C   s   t | jjS r    )parse_versionrV   versionrk   r#   r#   r$   rt      s   zDistribution.versionr:   c                 C   s   | j t|d uS r    )rV   rJ   r;   r>   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)
isinstancerW   r,   rZ   joinpathr?   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    )rV   rJ   r;   r=   )r"   r:   contentr#   r#   r$   rJ      s   zDistribution.read_textc                 C   s   | j jS r    )rV   entry_pointsrk   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MessagerV   r\   rk   r#   r#   r$   _metadata_impl   s   zDistribution._metadata_implc                 C   s   | j dg S )NProvides-Extra)r\   get_allrk   r#   r#   r$   iter_provided_extras   s   z!Distribution.iter_provided_extrasextrac                    s    t  fdd| jdg D S )Nc                 3   s     | ]}t |t  kV  qd S r    )r   )r/   provided_extrar   r#   r$   r1      s
    
z1Distribution.is_extra_provided.<locals>.<genexpr>r   )anyr\   r   )r"   r   r#   r   r$   is_extra_provided   s   zDistribution.is_extra_providedr#   extrasc                 #   sv    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 r8 V  qd S )Nc                 S   s   g | ]}d |iqS r   r#   )r/   rG   r#   r#   r$   
<listcomp>   s    z2Distribution.iter_dependencies.<locals>.<listcomp>zRequires-Distr    c                 3   s    | ]	} j |V  qd S r    )markerevaluate)r/   contextreqr#   r$   r1      s    z1Distribution.iter_dependencies.<locals>.<genexpr>)r\   r   r
   r   r   r   )r"   r   contexts
req_stringr#   r   r$   iter_dependencies   s   zDistribution.iter_dependencies)r#   ),rK   rL   rM   r[   r\   rS   r   r   r%   rP   r;   r   r^   rO   rg   r   rj   propertyr(   r   rU   rq   r   rr   r   rt   r   boolru   r   rz   rJ   r   r   r}   r~   r   r   r   r   r   r   r
   r   r#   r#   r#   r$   rS   _   sV    


	 rS   ).email.messager~   importlib.metadatar[   rm   r,   rQ   typingr   r   r   r   r   r   r   r	   "pip._vendor.packaging.requirementsr
   pip._vendor.packaging.utilsr   r   pip._vendor.packaging.versionr   rs   pip._internal.exceptionsr   r   pip._internal.metadata.baser   r   r   r   r   pip._internal.utils.miscr   pip._internal.utils.temp_dirr   pip._internal.utils.wheelr   r   _compatr   r   r\   rS   r   r#   r#   r#   r$   <module>   s"    (;