3
g                 @   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j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   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  j| || _d S )N)super__init___wheel_name)selfr   r   )	__class__ W/var/www/tester-filtro-web/env/lib/python3.6/site-packages/pip/_internal/utils/wheel.pyr      s    zWheelMetadata.__init__)namer   c                sJ   yt  j|S  tk
rD } ztd| j d| W Y d d }~X nX d S )NzError decoding metadata for z: )r   get_metadataUnicodeDecodeErrorr   r   )r   r   e)r   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| j D }i }xf|D ]^}|jdd\}}yt| |||< W q. tk
r } ztdj|t|W Y dd}~X q.X q.W t||}	t||	|dS )zaGet a pkg_resources distribution given a wheel.

    :raises UnsupportedWheel: on any errors
    c                s    g | ]}|j   d r|qS )/)
startswith).0p)info_dirr   r   
<listcomp>2   s    z8pkg_resources_distribution_for_wheel.<locals>.<listcomp>r&   r   z{} 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    
*
r5   )r$   r   r   c             C   sj   y t | |}t| |}t|}W n6 tk
rV } ztdj|t|W Y dd}~X nX 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.
    z{} has an invalid wheel, {}N)wheel_dist_info_dirwheel_metadatawheel_versionr   r1   r!   check_compatibility)r$   r   r*   r   versionr   r   r   r   r-   B   s    

&
r-   )sourcer   r   c             C   s   dd | j  D }dd |D }|s,tdt|dkrLtdjdj||d	 }t|}t|}|j|s~td
j|||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 | ]}|j d dd qS )r&   r   r   )r/   )r(   r)   r   r   r   	<setcomp>[   s    z&wheel_dist_info_dir.<locals>.<setcomp>c             S   s   g | ]}|j 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   lenr1   joinr   r'   )r;   r   ZsubdirsZ	info_dirsr*   Zinfo_dir_namecanonical_namer   r   r   r6   T   s    

r6   )r;   r3   r   c             C   sL   y
| j |S  tttfk
rF } ztd|d|W Y d d }~X nX d S )Nzcould not read z file: )readr   KeyErrorRuntimeErrorr   )r;   r3   r   r   r   r   r0   u   s    
r0   )r;   dist_info_dirr   c             C   sd   | d}t | |}y|j }W n6 tk
rV } ztd|d|W Y dd}~X nX t j|S )ziReturn the WHEEL metadata of an extracted wheel, if possible.
    Otherwise, raise UnsupportedWheel.
    z/WHEELzerror decoding z: N)r0   decoder   r   r   parsestr)r;   rE   r3   Zwheel_contentsZ
wheel_textr   r   r   r   r7   ~   s    

&r7   .)
wheel_datar   c             C   s\   | d }|dkrt d|j }yttt|jdS  tk
rV   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intr/   
ValueError)rH   Zversion_textr:   r   r   r   r8      s    r8   )r:   r   r   c             C   sR   | d t d kr.tdj|djtt| n | t krNtjddj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 piprI   z*Installing from a newer Wheel-Version (%s)N)VERSION_COMPATIBLEr   r1   r@   rL   r!   loggerwarning)r:   r   r   r   r   r9      s    r9   )r   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   rO   	getLoggerr   rP   r   r!   r5   r-   r6   r"   r0   r7   rM   r8   r9   r   r   r   r   <module>   s(   
!	