o
    f}”e  ã                   @   sL  d Z ddl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 ddlmZ ddlmZmZ dd	lmZ dd
lmZ dZe e¡ZG dd„ deƒZdedededefdd„Zdededeeef fdd„Zdededefdd„Zdededefdd„Zdededefdd„Z dedee!d f fd!d"„Z"d#ee!d f deddfd$d%„Z#dS )&z0Support functions for working with wheel files.
é    N)ÚMessage)ÚParser)ÚDictÚTuple)Ú
BadZipFileÚZipFile)Úcanonicalize_name)ÚDistInfoDistributionÚDistribution)ÚUnsupportedWheel)ÚDictMetadata)é   r   c                       sL   e Zd ZdZdeeef deddf‡ fdd„Zdedef‡ fd	d
„Z‡  Z	S )ÚWheelMetadatazaMetadata provider that maps metadata decoding exceptions to our
    internal exception type.
    ÚmetadataÚ
wheel_nameÚreturnNc                    s   t ƒ  |¡ || _d S )N)ÚsuperÚ__init__Ú_wheel_name)Úselfr   r   ©Ú	__class__© úb/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/pip/_internal/utils/wheel.pyr      s   
zWheelMetadata.__init__Únamec              
      s>   zt ƒ  |¡W S  ty } ztd| j› d|› �ƒ‚d }~ww )NzError decoding metadata for ú: )r   Úget_metadataÚUnicodeDecodeErrorr   r   )r   r   Úer   r   r   r      s   ÿ€þzWheelMetadata.get_metadata)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚbytesr   r   Ú__classcell__r   r   r   r   r      s    "r   Ú	wheel_zipr   Úlocationr   c           
         s˜   t | |ƒ\‰ }‡ fdd„|  ¡ D ƒ}i }|D ])}| dd¡\}}z	t| |ƒ||< W q ty? } z
td |t|ƒ¡ƒ‚d}~ww t||ƒ}	t||	|d�S )zaGet a pkg_resources distribution given a wheel.

    :raises UnsupportedWheel: on any errors
    c                    s    g | ]}|  ˆ › d �¡r|‘qS )ú/)Ú
startswith©Ú.0Úp©Úinfo_dirr   r   Ú
<listcomp>2   s     z8pkg_resources_distribution_for_wheel.<locals>.<listcomp>r(   r   ú{} has an invalid wheel, {}N)r'   r   Úproject_name)	Úparse_wheelÚnamelistÚsplitÚread_wheel_metadata_filer   Úformatr#   r   r	   )
r&   r   r'   Ú_Zmetadata_filesZmetadata_textÚpathÚmetadata_namer   r   r   r-   r   Ú$pkg_resources_distribution_for_wheel)   s   €ÿ
r:   c              
   C   s`   zt | |ƒ}t| |ƒ}t|ƒ}W n ty& } z
td |t|ƒ¡ƒ‚d}~ww 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   r6   r#   Úcheck_compatibility)r&   r   r.   r   Úversionr   r   r   r   r2   B   s   

€ÿ
r2   Úsourcec                 C   s‚   dd„ |   ¡ D ƒ}dd„ |D ƒ}|stdƒ‚t|ƒdkr&td d |¡¡ƒ‚|d	 }t|ƒ}t|ƒ}| |¡s?td
 ||¡ƒ‚|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   h | ]
}|  d d¡d ’qS )r(   r   r   )r4   r*   r   r   r   Ú	<setcomp>[   s    z&wheel_dist_info_dir.<locals>.<setcomp>c                 S   s   g | ]	}|  d ¡r|‘qS )z
.dist-info)Úendswith)r+   Úsr   r   r   r/   ]   s    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})r3   r   Úlenr6   Újoinr   r)   )r@   r   ÚsubdirsZ	info_dirsr.   Zinfo_dir_nameÚcanonical_namer   r   r   r;   T   s$   ÿ
ÿÿr;   r8   c              
   C   s@   z|   |¡W S  tttfy } z
td|›d|›�ƒ‚d }~ww )Nzcould not read z file: )Úreadr   ÚKeyErrorÚRuntimeErrorr   )r@   r8   r   r   r   r   r5   u   s   €ÿr5   Údist_info_dirc              
   C   sZ   |› d�}t | |ƒ}z| ¡ }W n ty& } z
td|›d|›�ƒ‚d}~ww tƒ  |¡S )ziReturn the WHEEL metadata of an extracted wheel, if possible.
    Otherwise, raise UnsupportedWheel.
    z/WHEELzerror decoding r   N)r5   Údecoder   r   r   Úparsestr)r@   rK   r8   Zwheel_contentsZ
wheel_textr   r   r   r   r<   ~   s   

€ÿr<   Ú
wheel_data.c                 C   sT   | d }|du rt dƒ‚| ¡ }zttt| d¡ƒƒW S  ty)   t d|›�ƒ‚w )zbGiven WHEEL metadata, return the parsed Wheel-Version.
    Otherwise, raise UnsupportedWheel.
    zWheel-VersionNzWHEEL is missing Wheel-VersionÚ.zinvalid Wheel-Version: )r   ÚstripÚtupleÚmapÚintr4   Ú
ValueError)rN   Zversion_textr?   r   r   r   r=   ‘   s   ÿr=   r?   c              	   C   sT   | d t d krtd |d tt| ƒ¡¡ƒ‚| t kr(t dd tt| ƒ¡¡ dS 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 piprO   z*Installing from a newer Wheel-Version (%s)N)ÚVERSION_COMPATIBLEr   r6   rE   rR   r#   ÚloggerÚwarning)r?   r   r   r   r   r>   ¡   s   þþÿr>   )$r"   ÚloggingÚemail.messager   Úemail.parserr   Útypingr   r   Úzipfiler   r   Úpip._vendor.packaging.utilsr   Úpip._vendor.pkg_resourcesr	   r
   Úpip._internal.exceptionsr   Z!pip._internal.utils.pkg_resourcesr   rU   Ú	getLoggerr   rV   r   r#   r:   r2   r;   r$   r5   r<   rS   r=   r>   r   r   r   r   Ú<module>   s8    
ÿÿÿ
þ!	"