ó
j·Ã^c           @@  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 n  e r d d l m Z n d d l m Z d Z e j e ƒ Z  d e f d „  ƒ  YZ! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d S(   s0   Support functions for working with wheel files.
i    (   t   absolute_importN(   t   Parser(   t   ZipFile(   t   canonicalize_name(   t   DistInfoDistribution(   t   PY2t
   ensure_str(   t   UnsupportedWheel(   t   DictMetadata(   t   MYPY_CHECK_RUNNING(   t   Message(   t   Dictt   Tuple(   t   Distribution(   t
   BadZipfile(   t
   BadZipFilei   t   WheelMetadatac           B@  s    e  Z d  Z d „  Z d „  Z RS(   sa   Metadata provider that maps metadata decoding exceptions to our
    internal exception type.
    c         C@  s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   t   superR   t   __init__t   _wheel_name(   t   selft   metadatat
   wheel_name(    (    s*   site-packages/pip/_internal/utils/wheel.pyR   (   s    c         C@  sO   y t  t |  ƒ j | ƒ SWn. t k
 rJ } t d j |  j | ƒ ƒ ‚ n Xd  S(   Ns"   Error decoding metadata for {}: {}(   R   R   t   get_metadatat   UnicodeDecodeErrorR   t   formatR   (   R   t   namet   e(    (    s*   site-packages/pip/_internal/utils/wheel.pyR   -   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s*   site-packages/pip/_internal/utils/wheel.pyR   $   s   	c         C@  sú   t  |  | ƒ \ } } g  |  j ƒ  D]$ } | j d j | ƒ ƒ r" | ^ q" } i  } x} | D]u } t | ƒ }	 |	 j d d ƒ \ } }
 y t |  |	 ƒ | |
 <WqY t k
 rÍ } t d j | t | ƒ ƒ ƒ ‚ qY XqY Wt	 | | ƒ } t
 d | d | d | ƒ S(   sa   Get a pkg_resources distribution given a wheel.

    :raises UnsupportedWheel: on any errors
    s   {}/t   /i   s   {} has an invalid wheel, {}t   locationR   t   project_name(   t   parse_wheelt   namelistt
   startswithR   R   t   splitt   read_wheel_metadata_fileR   t   strR   R   (   t	   wheel_zipR   R    t   info_dirt   _t   pt   metadata_filest   metadata_textt   patht	   full_patht   metadata_nameR   R   (    (    s*   site-packages/pip/_internal/utils/wheel.pyt$   pkg_resources_distribution_for_wheel:   s    7#c         C@  sy   y. t  |  | ƒ } t |  | ƒ } t | ƒ } Wn1 t k
 ra } t d j | t | ƒ ƒ ƒ ‚ n Xt | | ƒ | | f S(   s©   Extract information from the provided wheel, ensuring it meets basic
    standards.

    Returns the name of the .dist-info directory and the parsed WHEEL metadata.
    s   {} has an invalid wheel, {}(   t   wheel_dist_info_dirt   wheel_metadatat   wheel_versionR   R   R'   t   check_compatibility(   R(   R   R)   R   t   versionR   (    (    s*   site-packages/pip/_internal/utils/wheel.pyR"   _   s    c         C@  sè   t  t d „  |  j ƒ  Dƒ ƒ ƒ } g  | D] } | j d ƒ r) | ^ q) } | s_ t d ƒ ‚ n  t | ƒ d k r’ t d j d j | ƒ ƒ ƒ ‚ n  | d } t | ƒ } t | ƒ } | j	 | ƒ sÞ t d j | | ƒ ƒ ‚ n  t
 | ƒ S(	   s®   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"   |  ] } | j  d  ƒ d Vq d S(   R   i    N(   R%   (   t   .0R+   (    (    s*   site-packages/pip/_internal/utils/wheel.pys	   <genexpr>|   s    s
   .dist-infos   .dist-info directory not foundi   s)   multiple .dist-info directories found: {}s   , i    s2   .dist-info directory {!r} does not start with {!r}(   t   listt   setR#   t   endswithR   t   lenR   t   joinR   R$   R   (   t   sourceR   t   subdirst   st	   info_dirsR)   t   info_dir_namet   canonical_name(    (    s*   site-packages/pip/_internal/utils/wheel.pyR2   t   s     "(
c         C@  sL   y |  j  | ƒ SWn4 t t t f k
 rG } t d j | | ƒ ƒ ‚ n Xd  S(   Ns   could not read {!r} file: {!r}(   t   readR   t   KeyErrort   RuntimeErrorR   R   (   R=   R.   R   (    (    s*   site-packages/pip/_internal/utils/wheel.pyR&   š   s
    c         C@  sl   d j  | ƒ } t |  | ƒ } y t | ƒ } Wn+ t k
 r[ } t d j  | | ƒ ƒ ‚ n Xt ƒ  j | ƒ S(   si   Return the WHEEL metadata of an extracted wheel, if possible.
    Otherwise, raise UnsupportedWheel.
    s   {}/WHEELs   error decoding {!r}: {!r}(   R   R&   R   R   R   R   t   parsestr(   R=   t   dist_info_dirR.   t   wheel_contentst
   wheel_textR   (    (    s*   site-packages/pip/_internal/utils/wheel.pyR3   ¦   s    c         C@  s~   |  d } | d k r% t d ƒ ‚ n  | j ƒ  } y  t t t | j d ƒ ƒ ƒ SWn& t k
 ry t d j | ƒ ƒ ‚ n Xd S(   sb   Given WHEEL metadata, return the parsed Wheel-Version.
    Otherwise, raise UnsupportedWheel.
    s   Wheel-Versions   WHEEL is missing Wheel-Versiont   .s   invalid Wheel-Version: {!r}N(	   t   NoneR   t   stript   tuplet   mapt   intR%   t
   ValueErrorR   (   t
   wheel_datat   version_textR6   (    (    s*   site-packages/pip/_internal/utils/wheel.pyR4   º   s    
 c         C@  sv   |  d t  d k rA t d j | d j t t |  ƒ ƒ ƒ ƒ ‚ n1 |  t  k rr t j d d j t t |  ƒ ƒ ƒ n  d S(   så  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
    i    sB   {}'s Wheel-Version ({}) is not compatible with this version of pipRJ   s*   Installing from a newer Wheel-Version (%s)N(   t   VERSION_COMPATIBLER   R   R<   RN   R'   t   loggert   warning(   R6   R   (    (    s*   site-packages/pip/_internal/utils/wheel.pyR5   Ë   s    $(   i   i    ()   R   t
   __future__R    t   loggingt   email.parserR   t   zipfileR   t   pip._vendor.packaging.utilsR   t   pip._vendor.pkg_resourcesR   t   pip._vendor.sixR   R   t   pip._internal.exceptionsR   t!   pip._internal.utils.pkg_resourcesR   t   pip._internal.utils.typingR	   t   email.messageR
   t   typingR   R   R   R   R   RS   t	   getLoggerR   RT   R   R1   R"   R2   R&   R3   R4   R5   (    (    (    s*   site-packages/pip/_internal/utils/wheel.pyt   <module>   s6   	%		&			