o
    6i"                     @  s0  d dl m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 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 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/m0Z0 G dd dej1j2Z3G dd deZ2dS )    )annotationsN)
CollectionIterableIteratorMappingSequence)PathLike)cast)Requirement)NormalizedNamecanonicalize_name)Version)parse)InvalidWheelUnsupportedWheel)BaseDistributionBaseEntryPointInfoPathWheel)normalize_path)get_requirement)TempDirectory)parse_wheelread_wheel_metadata_file   )BadMetadataBasePathget_dist_canonical_name*parse_name_and_version_from_info_directoryc                   @  sF   e Zd ZdZddd	Zed ddZd!ddZd"ddZ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.
    files%Mapping[pathlib.PurePosixPath, bytes]info_locationpathlib.PurePosixPathreturnNonec                 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__1   s   
zWheelDistribution.__init__zfzipfile.ZipFilenamestr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>A   s    
z1WheelDistribution.from_zipfile.<locals>.<genexpr>c                   s   i | ]
\}}|t  |qS r)   )r   )r7   fullpathrelpath)r,   r)   r*   
<dictcomp>F   s    
z2WheelDistribution.from_zipfile.<locals>.<dictcomp>)r   namelistr4   r5   )clsr,   r.   r0   _pathsr    r"   r)   )r8   r,   r*   from_zipfile9   s   


zWheelDistribution.from_zipfilepathr   Iterator[pathlib.PurePosixPath]c                 C  s&   t t|| jv rt| jS t|r&   )r4   r5   r/   r'   iterFileNotFoundErrorr(   rB   r)   r)   r*   iterdirM   s   
zWheelDistribution.iterdirfilename
str | Nonec              
   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'   r4   r5   KeyErrordecodeUnicodeDecodeErrorr"   parentr   )r(   rH   datatextewheelerrorr)   r)   r*   	read_textS   s   zWheelDistribution.read_textstr | PathLike[str]pathlib.Pathc                 C  s   t r&   )NotImplementedErrorrF   r)   r)   r*   locate_file`   s   zWheelDistribution.locate_fileN)r    r!   r"   r#   r$   r%   )r,   r-   r.   r/   r0   r/   r$   r   )rB   r   r$   rC   )rH   r/   r$   rI   )rB   rT   r$   rU   )
__name__
__module____qualname____doc__r+   classmethodrA   rG   rS   rW   r)   r)   r)   r*   r   &   s    



r   c                   @  s   e Zd ZdCdd	ZedDddZedEddZedFddZedGddZ	edGddZ
edGdd ZedHd"d#ZedId%d&ZedJd'd(ZdKd,d-ZdLd/d0ZdMd1d2ZdNd4d5ZdOd7d8ZdPd:d;ZdQdRd@dAZdBS )SDistributiondistimportlib.metadata.Distributionr"   BasePath | Noneinstalled_locationr$   r%   c                 C  s   || _ || _|| _d S r&   )_dist_info_location_installed_location)r(   r^   r"   ra   r)   r)   r*   r+   g   s   
zDistribution.__init__	directoryr/   r   c                 C  s&   t |}tjj|}| |||jS r&   )r4   Path	importlibmetadatar]   atrM   )r>   re   r"   r^   r)   r)   r*   from_directoryq   s   
zDistribution.from_directorymetadata_contentsbytesrH   project_namec                 C  sD   t tdddj}|d }|| tjj|j	}| ||j	d S )Nrh   T)kindglobally_managedMETADATA)
r4   rf   r   rB   write_bytesrg   rh   r]   ri   rM   )r>   rk   rH   rm   temp_dirmetadata_pathr^   r)   r)   r*   from_metadata_file_contentsw   s   
z(Distribution.from_metadata_file_contentsrQ   r   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   rA   r0   zipfile
BadZipFiler   r"   r4   r5   )r>   rQ   r.   r,   r^   rP   r)   r)   r*   
from_wheel   s   
zDistribution.from_wheelrI   c                 C  s   | j d u rd S t| j jS r&   )rc   r/   rM   r(   r)   r)   r*   r0      s   
zDistribution.locationc                 C  s   | j d u rd S t| j S r&   )rc   r/   ry   r)   r)   r*   r"      s   

zDistribution.info_locationc                 C  s   | j d u rd S tt| j S r&   )rd   r   r/   ry   r)   r)   r*   ra      s   
zDistribution.installed_locationr   c                 C  s
   t | jS r&   )r   rb   ry   r)   r)   r*   canonical_name   s   
zDistribution.canonical_namer   c                 C  s>   zt | jd p| jj}t|W S  ty   t| jddw )Nr   z invalid metadata entry `version`)reason)r   rb   versionparse_version	TypeErrorr   )r(   r|   r)   r)   r*   r|      s   
zDistribution.versionc                 C     | j jS r&   )rb   r|   ry   r)   r)   r*   raw_version      zDistribution.raw_versionrB   r   boolc                 C  s   | j t|d uS r&   )rb   rS   r/   rF   r)   r)   r*   is_file   s   zDistribution.is_fileIterator[str]c                 c  s6    t | jtjs
d S | jd D ]}|jV  qd S )Nscripts)
isinstancerc   r4   rf   joinpathrG   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&   )rb   rS   r/   rE   )r(   rB   contentr)   r)   r*   rS      s   zDistribution.read_textIterable[BaseEntryPoint]c                 C  r   r&   )rb   entry_pointsry   r)   r)   r*   iter_entry_points   r   zDistribution.iter_entry_pointsemail.message.Messagec                 C  s(   | j j}|d u rtj S ttjj|S r&   )rb   rh   emailmessageMessager	   )r(   rh   r)   r)   r*   _metadata_impl   s   
zDistribution._metadata_implIterable[NormalizedName]c                 C  s   dd | j dg D S )Nc                 S  s   g | ]}t |qS r)   )r   )r7   extrar)   r)   r*   
<listcomp>   s    z5Distribution.iter_provided_extras.<locals>.<listcomp>zProvides-Extra)rh   get_allry   r)   r)   r*   iter_provided_extras   s   z!Distribution.iter_provided_extrasr)   extrasCollection[str]Iterable[Requirement]c                 #  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)   )r7   rP   r)   r)   r*   r      s    z2Distribution.iter_dependencies.<locals>.<listcomp>zRequires-Distr    c                 3  s    | ]	} j |V  qd S r&   )markerevaluate)r7   contextreqr)   r*   r9      s    z1Distribution.iter_dependencies.<locals>.<genexpr>)rh   r   r   stripr   r   any)r(   r   contexts
req_stringr)   r   r*   iter_dependencies   s   zDistribution.iter_dependenciesN)r^   r_   r"   r`   ra   r`   r$   r%   )re   r/   r$   r   )rk   rl   rH   r/   rm   r/   r$   r   )rQ   r   r.   r/   r$   r   )r$   rI   )r$   r   )r$   r   )r$   r/   )rB   r   r$   r   )r$   r   )rB   r   r$   r/   )r$   r   )r$   r   )r$   r   )r)   )r   r   r$   r   )rX   rY   rZ   r+   r\   rj   rt   rx   propertyr0   r"   ra   rz   r|   r   r   r   rS   r   r   r   r   r)   r)   r)   r*   r]   f   s6    





	


r]   )4
__future__r   email.messager   importlib.metadatarg   r4   rv   collections.abcr   r   r   r   r   osr   typingr	   "pip._vendor.packaging.requirementsr
   pip._vendor.packaging.utilsr   r   pip._vendor.packaging.versionr   r   r}   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   r   rh   r]   r   r)   r)   r)   r*   <module>   s*    @