a
    ûõ§e‡  ã                   @   s   d Z ddlmZ ddlZddl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 er¨ddlmZ ddlmZmZ ddl
mZ erºddlmZ nddlmZ dZe e¡Z G dd„ deƒZ!dd„ Z"dd„ Z#dd„ Z$dd„ Z%dd„ Z&dd„ Z'd d!„ Z(dS )"z0Support functions for working with wheel files.
é    )Úabsolute_importN)ÚParser)ÚZipFile)Úcanonicalize_name)ÚDistInfoDistribution)ÚPY2Ú
ensure_str)ÚUnsupportedWheel)ÚDictMetadata)ÚMYPY_CHECK_RUNNING)ÚMessage)ÚDictÚTuple)ÚDistribution)Ú
BadZipfile)Ú
BadZipFile)é   r   c                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚWheelMetadatazaMetadata provider that maps metadata decoding exceptions to our
    internal exception type.
    c                    s   t t| ƒ |¡ || _d S )N)Úsuperr   Ú__init__Ú_wheel_name)ÚselfÚmetadataÚ
wheel_name©Ú	__class__© úM/var/www/sunrise/env/lib/python3.9/site-packages/pip/_internal/utils/wheel.pyr   (   s    zWheelMetadata.__init__c              
      sN   zt t| ƒ |¡W S  tyH } ztd | j|¡ƒ‚W Y d }~n
d }~0 0 d S )Nz"Error decoding metadata for {}: {})r   r   Úget_metadataÚUnicodeDecodeErrorr	   Úformatr   )r   ÚnameÚer   r   r   r   -   s    ÿÿzWheelMetadata.get_metadata)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__r   r   r   r   r   $   s   r   c                    s®   t | |ƒ\‰ }‡ fdd„|  ¡ D ƒ}i }|D ]h}t|ƒ}| dd¡\}}zt| |ƒ||< W q, ty’ }	 z td |t|	ƒ¡ƒ‚W Y d}	~	q,d}	~	0 0 q,t||ƒ}
t	||
|dS )zaGet a pkg_resources distribution given a wheel.

    :raises UnsupportedWheel: on any errors
    c                    s    g | ]}|  d  ˆ ¡¡r|‘qS )z{}/)Ú
startswithr    ©Ú.0Úp©Úinfo_dirr   r   Ú
<listcomp>B   s   z8pkg_resources_distribution_for_wheel.<locals>.<listcomp>ú/r   ú{} has an invalid wheel, {}N)Úlocationr   Úproject_name)
Úparse_wheelÚnamelistr   ÚsplitÚread_wheel_metadata_filer	   r    Ústrr   r   )Ú	wheel_zipr!   r1   Ú_Zmetadata_filesZmetadata_textÚpathÚ	full_pathÚmetadata_namer"   r   r   r,   r   Ú$pkg_resources_distribution_for_wheel:   s(    
ÿÿÿ
ÿr=   c              
   C   sl   z t | |ƒ}t| |ƒ}t|ƒ}W n8 tyX } z td |t|ƒ¡ƒ‚W Y d}~n
d}~0 0 t||ƒ ||fS )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.
    r0   N)Úwheel_dist_info_dirÚwheel_metadataÚwheel_versionr	   r    r7   Úcheck_compatibility)r8   r!   r-   r   Úversionr"   r   r   r   r3   _   s    

ÿ
r3   c                 C   sŠ   t dd„ |  ¡ D ƒƒ}dd„ |D ƒ}|s0tdƒ‚t|ƒdkrPtd d |¡¡ƒ‚|d	 }t|ƒ}t|ƒ}| |¡s‚td
 ||¡ƒ‚t|ƒ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.
    c                 s   s   | ]}|  d d¡d V  qdS )r/   r   r   N)r5   r)   r   r   r   Ú	<genexpr>|   ó    z&wheel_dist_info_dir.<locals>.<genexpr>c                 S   s   g | ]}|  d ¡r|‘qS )z
.dist-info)Úendswith)r*   Úsr   r   r   r.   ~   rD   z'wheel_dist_info_dir.<locals>.<listcomp>z.dist-info directory not foundr   z)multiple .dist-info directories found: {}z, r   z2.dist-info directory {!r} does not start with {!r})	Úsetr4   r	   Úlenr    Újoinr   r(   r   )Úsourcer!   ZsubdirsZ	info_dirsr-   Zinfo_dir_nameÚcanonical_namer   r   r   r>   t   s(    ÿÿ
ÿÿr>   c              
   C   sL   z|   |¡W S  tttfyF } ztd ||¡ƒ‚W Y d }~n
d }~0 0 d S )Nzcould not read {!r} file: {!r})Úreadr   ÚKeyErrorÚRuntimeErrorr	   r    )rJ   r:   r"   r   r   r   r6   š   s    
ÿr6   c              
   C   sb   d  |¡}t| |ƒ}zt|ƒ}W n4 tyT } ztd  ||¡ƒ‚W Y d}~n
d}~0 0 tƒ  |¡S )ziReturn the WHEEL metadata of an extracted wheel, if possible.
    Otherwise, raise UnsupportedWheel.
    z{}/WHEELzerror decoding {!r}: {!r}N)r    r6   r   r   r	   r   Úparsestr)rJ   Zdist_info_dirr:   Zwheel_contentsZ
wheel_textr"   r   r   r   r?   ¦   s    

&r?   c                 C   s\   | d }|du rt dƒ‚| ¡ }zttt| d¡ƒƒW S  tyV   t d |¡ƒ‚Y n0 dS )zbGiven WHEEL metadata, return the parsed Wheel-Version.
    Otherwise, raise UnsupportedWheel.
    zWheel-VersionNzWHEEL is missing Wheel-VersionÚ.zinvalid Wheel-Version: {!r})r	   ÚstripÚtupleÚmapÚintr5   Ú
ValueErrorr    )Z
wheel_dataZversion_textrB   r   r   r   r@   º   s    r@   c              	   C   sR   | d t d kr.td |d tt| ƒ¡¡ƒ‚n | t krNt dd tt| ƒ¡¡ dS )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
    r   zB{}'s Wheel-Version ({}) is not compatible with this version of piprP   z*Installing from a newer Wheel-Version (%s)N)ÚVERSION_COMPATIBLEr	   r    rI   rS   r7   ÚloggerÚwarning)rB   r!   r   r   r   rA   Ë   s    ÿÿþrA   ))r&   Ú
__future__r   ÚloggingÚemail.parserr   Úzipfiler   Úpip._vendor.packaging.utilsr   Úpip._vendor.pkg_resourcesr   Úpip._vendor.sixr   r   Úpip._internal.exceptionsr	   Z!pip._internal.utils.pkg_resourcesr
   Úpip._internal.utils.typingr   Úemail.messager   Útypingr   r   r   r   r   rV   Ú	getLoggerr#   rW   r   r=   r3   r>   r6   r?   r@   rA   r   r   r   r   Ú<module>   s6   
%&