a
    4Da                     @   s0  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eeeedddZeeeeef dddZeeedddZeeedddZeeedddZ eee!df ddd Z"ee!df edd!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                       sF   e Zd ZdZeeef edd fddZeed fddZ  Z	S )	WheelMetadatazaMetadata provider that maps metadata decoding exceptions to our
    internal exception type.
    N)metadata
wheel_namereturnc                    s   t  | || _d S )N)super__init___wheel_name)selfr   r   	__class__ i/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/pip/_internal/utils/wheel.pyr      s    zWheelMetadata.__init__)namer   c              
      sN   zt  |W S  tyH } z"td| j d| W Y d }~n
d }~0 0 d S )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|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 )/)
startswith.0pinfo_dirr   r   
<listcomp>2       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'   _metadata_filesmetadata_textpathmetadata_namer   r   r   r-   r   $pkg_resources_distribution_for_wheel)   s    ,
r=   )r&   r   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 )zExtract information from the provided wheel, ensuring it meets basic
    standards.

    Returns the name of the .dist-info directory and the parsed WHEEL metadata.
    r1   N)wheel_dist_info_dirwheel_metadatawheel_versionr   r7   r#   check_compatibility)r&   r   r.   r   versionr   r   r   r   r3   B   s    

*
r3   )sourcer   r   c                 C   s   dd |   D }dd |D }|s,tdt|dkrLtdd||d	 }t|}t|}||s~td
|||S )zReturns 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   )r5   r*   r   r   r   	<setcomp>[   r0   z&wheel_dist_info_dir.<locals>.<setcomp>c                 S   s   g | ]}| d r|qS )z
.dist-info)endswith)r+   sr   r   r   r/   ]   r0   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})r4   r   lenr7   joinr   r)   )rC   r   subdirs	info_dirsr.   info_dir_namecanonical_namer   r   r   r>   T   s$    
r>   )rC   r;   r   c              
   C   sP   z|  |W S  tttfyJ } z td|d|W Y d }~n
d }~0 0 d S )Nzcould not read z file: )readr   KeyErrorRuntimeErrorr   )rC   r;   r   r   r   r   r6   u   s    r6   )rC   dist_info_dirr   c              
   C   sf   | d}t | |}z| }W n8 tyX } z td|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   N)r6   decoder   r   r   parsestr)rC   rP   r;   wheel_contents
wheel_textr   r   r   r   r?   ~   s    

*r?   .)
wheel_datar   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   striptuplemapintr5   
ValueError)rU   version_textrB   r   r   r   r@      s    r@   )rB   r   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 piprV   z*Installing from a newer Wheel-Version (%s)N)VERSION_COMPATIBLEr   r7   rH   rY   r#   loggerwarning)rB   r   r   r   r   rA      s    rA   )$r"   loggingemail.messager   email.parserr   typingr   r   zipfiler   r   Zpip._vendor.packaging.utilsr   Zpip._vendor.pkg_resourcesr	   r
   pip._internal.exceptionsr   !pip._internal.utils.pkg_resourcesr   r]   	getLoggerr   r^   r   r#   r=   r3   r>   r$   r6   r?   rZ   r@   rA   r   r   r   r   <module>   s*   
!	