U
    +|j’  ã                   @   sÒ   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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.
é    N)ÚMessage)ÚParser)ÚDictÚTuple)Ú
BadZipFileÚZipFile)Úcanonicalize_name)ÚDistInfoDistributionÚDistribution)ÚUnsupportedWheel)ÚDictMetadata)é   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 ƒ  |¡ || _d S )N)ÚsuperÚ__init__Ú_wheel_name)ÚselfÚmetadataÚ
wheel_name©Ú	__class__© úaC:\Users\snmko\Desktop\web_content\django_cbt\venv\Lib\site-packages\pip/_internal/utils/wheel.pyr      s    zWheelMetadata.__init__c              
      sL   zt ƒ  |¡W S  tk
rF } ztd| j› d|› �ƒ‚W 5 d }~X Y nX d S )NzError decoding metadata for ú: )r   Úget_metadataÚUnicodeDecodeErrorr   r   )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 ]^}| dd¡\}}zt| |ƒ||< W q, tk
rˆ } ztd |t|ƒ¡ƒ‚W 5 d}~X Y q,X 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>3   s      z8pkg_resources_distribution_for_wheel.<locals>.<listcomp>r#   r   ú{} has an invalid wheel, {}N)Úlocationr   Úproject_name)	Úparse_wheelÚnamelistÚsplitÚread_wheel_metadata_filer   ÚformatÚstrr   r	   )
Ú	wheel_zipr   r,   Ú_Úmetadata_filesÚmetadata_textÚpathÚmetadata_namer   r   r   r(   r   Ú$pkg_resources_distribution_for_wheel+   s    (
r:   c              
   C   sj   z t | |ƒ}t| |ƒ}t|ƒ}W n6 tk
rV } ztd |t|ƒ¡ƒ‚W 5 d}~X Y nX 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.
    r+   N)Úwheel_dist_info_dirÚwheel_metadataÚwheel_versionr   r2   r3   Úcheck_compatibility)r4   r   r)   r   Úversionr   r   r   r   r.   C   s    

&
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 )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   )r0   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})r/   r   Úlenr2   Újoinr   r$   )Úsourcer   ÚsubdirsÚ	info_dirsr)   Úinfo_dir_nameÚcanonical_namer   r   r   r;   V   s&    ÿ
 ÿÿr;   c              
   C   sN   z|   |¡W S  tttfk
rH } ztd|›d|›�ƒ‚W 5 d }~X Y nX d S )Nzcould not read z file: )Úreadr   ÚKeyErrorÚRuntimeErrorr   )rE   r8   r   r   r   r   r1   x   s    r1   c              
   C   sd   |› d�}t | |ƒ}z| ¡ }W n6 tk
rV } ztd|›d|›�ƒ‚W 5 d}~X Y nX tƒ  |¡S )ziReturn the WHEEL metadata of an extracted wheel, if possible.
    Otherwise, raise UnsupportedWheel.
    z/WHEELzerror decoding r   N)r1   Údecoder   r   r   Úparsestr)rE   Údist_info_dirr8   Úwheel_contentsÚ
wheel_textr   r   r   r   r<   ‚   s    

&r<   c                 C   s^   | d }|dkrt dƒ‚| ¡ }zttt| d¡ƒƒW S  tk
rX   t d|›�ƒ‚Y nX 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Úintr0   Ú
ValueError)Ú
wheel_dataÚversion_textr?   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 piprR   z*Installing from a newer Wheel-Version (%s)N)ÚVERSION_COMPATIBLEr   r2   rD   rU   r3   Ú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   Ú!pip._internal.utils.pkg_resourcesr   rZ   Ú	getLoggerr   r[   r   r:   r.   r;   r1   r<   r=   r>   r   r   r   r   Ú<module>   s&   
"
