Current File : //lib/python3.9/site-packages/pip/_internal/utils/__pycache__/wheel.cpython-39.pyc
a

[��f�@s0dZddlZddlmZddlmZddlmZmZddl	m
Z
mZddlm
Z
ddlmZmZdd	lmZdd
lmZdZe�e�ZGdd
�d
e�Zeeeed�dd�Zeeeeefd�dd�Zeeed�dd�Zeeed�dd�Zeeed�dd�Z eee!dfd�dd �Z"ee!dfedd!�d"d#�Z#dS)$z0Support functions for working with wheel files.
�N)�Message)�Parser)�Dict�Tuple)�
BadZipFile�ZipFile)�canonicalize_name)�DistInfoDistribution�Distribution)�UnsupportedWheel)�DictMetadata)�rcsFeZdZdZeeefedd��fdd�Zeed��fdd�Z�Z	S)	�
WheelMetadatazaMetadata provider that maps metadata decoding exceptions to our
    internal exception type.
    N)�metadata�
wheel_name�returncst��|�||_dS)N)�super�__init__�_wheel_name)�selfrr��	__class__��=/usr/lib/python3.9/site-packages/pip/_internal/utils/wheel.pyrszWheelMetadata.__init__)�namerc
sNzt��|�WStyH}z"td|j�d|����WYd}~n
d}~00dS)NzError decoding metadata for �: )r�get_metadata�UnicodeDecodeErrorrr)rr�errrrs�zWheelMetadata.get_metadata)
�__name__�
__module__�__qualname__�__doc__r�str�bytesrr�
__classcell__rrrrrsr)�	wheel_zipr�locationrc
s�t||�\�}�fdd�|��D�}i}|D]`}|�dd�\}}zt||�||<Wq,ty�}z td�|t|����WYd}~q,d}~00q,t||�}	t||	|d�S)zaGet a pkg_resources distribution given a wheel.

    :raises UnsupportedWheel: on any errors
    cs g|]}|���d��r|�qS)�/)�
startswith��.0�p��info_dirrr�
<listcomp>2�z8pkg_resources_distribution_for_wheel.<locals>.<listcomp>r(r
�{} has an invalid wheel, {}N)r'rZproject_name)	�parse_wheel�namelist�split�read_wheel_metadata_filer�formatr#rr	)
r&rr'�_Zmetadata_filesZ
metadata_text�pathZ
metadata_namerrrr-r�$pkg_resources_distribution_for_wheel)s,
r9)r&rrc
Cslz t||�}t||�}t|�}Wn8tyX}z td�|t|����WYd}~n
d}~00t||�||fS)z�Extract information from the provided wheel, ensuring it meets basic
    standards.

    Returns the name of the .dist-info directory and the parsed WHEEL metadata.
    r1N)�wheel_dist_info_dir�wheel_metadata�
wheel_versionrr6r#�check_compatibility)r&rr.r�versionrrrrr2Bs

*
r2)�sourcerrcCs�dd�|��D�}dd�|D�}|s,td��t|�dkrLtd�d�|����|d	}t|�}t|�}|�|�s~td
�||���|S)z�Returns the name of the contained .dist-info directory.

    Raises AssertionError or UnsupportedWheel if not found, >1 found, or
    it doesn't match the provided name.
    cSsh|]}|�dd�d�qS)r(r
r)r4r*rrr�	<setcomp>[r0z&wheel_dist_info_dir.<locals>.<setcomp>cSsg|]}|�d�r|�qS)z
.dist-info)�endswith)r+�srrrr/]r0z'wheel_dist_info_dir.<locals>.<listcomp>z.dist-info directory not foundr
z)multiple .dist-info directories found: {}z, rz2.dist-info directory {!r} does not start with {!r})r3r�lenr6�joinrr))r?r�subdirsZ	info_dirsr.Z
info_dir_nameZcanonical_namerrrr:Ts$�
��r:)r?r8rc
CsPz|�|�WStttfyJ}z td|�d|����WYd}~n
d}~00dS)Nzcould not read z file: )�readr�KeyError�RuntimeErrorr)r?r8rrrrr5usr5)r?�
dist_info_dirrc
Csf|�d�}t||�}z|��}Wn8tyX}z td|�d|����WYd}~n
d}~00t��|�S)ziReturn the WHEEL metadata of an extracted wheel, if possible.
    Otherwise, raise UnsupportedWheel.
    z/WHEELzerror decoding rN)r5�decoderrrZparsestr)r?rIr8Zwheel_contentsZ
wheel_textrrrrr;~s

*r;.)�
wheel_datarcCs\|d}|durtd��|��}zttt|�d���WStyVtd|����Yn0dS)zbGiven WHEEL metadata, return the parsed Wheel-Version.
    Otherwise, raise UnsupportedWheel.
    z
Wheel-VersionNzWHEEL is missing Wheel-Version�.zinvalid Wheel-Version: )r�strip�tuple�map�intr4�
ValueError)rKZversion_textr>rrrr<�sr<)r>rrc	CsR|dtdkr.td�|d�tt|�����n |tkrNt�dd�tt|���dS)a�Raises errors or warns if called with an incompatible Wheel-Version.

    pip should refuse to install a Wheel-Version that's a major series
    ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
    installing a version only minor version ahead (e.g 1.2 > 1.1).

    version: a 2-tuple representing a Wheel-Version (Major, Minor)
    name: name of wheel or package to raise exception about

    :raises UnsupportedWheel: when an incompatible Wheel-Version is given
    rzB{}'s Wheel-Version ({}) is not compatible with this version of piprLz*Installing from a newer Wheel-Version (%s)N)�VERSION_COMPATIBLErr6rDrOr#�loggerZwarning)r>rrrrr=�s���r=)$r"ZloggingZ
email.messagerZemail.parserr�typingrr�zipfilerrZpip._vendor.packaging.utilsrZpip._vendor.pkg_resourcesr	r
Zpip._internal.exceptionsrZ!pip._internal.utils.pkg_resourcesrrRZ	getLoggerrrSrr#r9r2r:r$r5r;rPr<r=rrrr�<module>s*
�!