ó
"j]c           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z e j d ƒ Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d S(   s2   
Tools for converting old- to new-style metadata.
iÿÿÿÿNi   (   t   read_pkg_infosF   ^(?P<package>.*?)(;\s*(?P<condition>.*?)(extra == '(?P<extra>.*?)')?)$c         C   so   t  |  d d ƒ r d |  j Sg  } x( |  j D] \ } } | j | | ƒ q- W| sX d Sd d j t | ƒ ƒ S(   sF   Return the version specifier for a requirement in PEP 345/566 fashion.t   urls    @ t    s    (%s)t   ,N(   t   getattrt   NoneR   t   specst   appendt   joint   sorted(   t   requirementt   requires_distt   opt   ver(    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   requires_to_requires_dist   s    c         c   sn   xg |  D]_ } t  j j | ƒ } t | ƒ } d j t | j ƒ ƒ } | rV d | } n  | j | | Vq Wd S(   s=   Yield Requires-Dist: strings for parsed requirements strings.R   s   [%s]N(   t   pkg_resourcest   Requirementt   parseR   R   R	   t   extrast   project_name(   t   requirementst   reqt   parsed_requirementt   specR   (    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   convert_requirements    s    c         c   sÛ   xÔ |  j  ƒ  D]Æ \ } } d } | p( d } d | k rR | j d d ƒ \ } } n  t j | ƒ } | rš d | f V| r‰ d | d } n  | d | 7} n  | r­ d | } n  x# t | ƒ D] } d	 | | f Vqº Wq Wd
 S(   s,  
    Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
    and ('Provides-Extra', 'extra') tuples.

    extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
    using the empty extra {'': [requirements]} to hold install_requires.
    R   t   :i   s   Provides-Extrat   (s   ) and s   extra == '%s's    ; s   Requires-DistN(   t   itemst   splitR   t
   safe_extraR   (   t   extras_requiret   extrat   dependst	   conditiont   new_req(    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   generate_requirements+   s    c         C   s$  t  | ƒ } | j d d ƒ | d =| d =t j j |  d ƒ } t j j | ƒ ró t | ƒ  } | j ƒ  } Wd QXt t	 j
 | ƒ d d „  ƒ} x` | D]U \ } } xF t i | | 6ƒ D]1 \ }	 }
 |	 |
 f | j ƒ  k r· |
 | |	 <q· q· Wq— Wn  | d	 } | r | j t | ƒ ƒ | d	 =n  | S(
   sN   
    Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
    s   Metadata-Versions   2.1s   Provides-Extras   Requires-Dists   requires.txtNt   keyc         S   s   |  d p d S(   Ni    R   (    (   t   x(    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   <lambda>V   s    t   Description(   R    t   replace_headert   ost   pathR   t   existst   opent   readR	   R   t   split_sectionsR#   R   t   set_payloadt   dedent_description(   t   egg_info_patht   pkginfo_patht   pkg_infot   requires_patht   requires_filet   requirest   parsed_requirementsR   t   reqsR$   t   valuet   description(    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   pkginfo_to_metadataG   s&     

c         C   s•   |  | } | j  ƒ  } t | t ƒ s‘ t |  d ƒ s> t | ƒ SxP |  j ƒ  D]? } | d j  ƒ  | k rK | d j d d ƒ j d ƒ } PqK qK Wn  | S(   s<   Hack to coax Unicode out of an email Message() - Python 3.3+t	   raw_itemsi    i   t   asciit   surrogateescapes   utf-8(   t   lowert
   isinstancet   strt   hasattrR<   t   encodet   decode(   R3   t   fieldt   textt   item(    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   pkginfo_unicoded   s    

	c         C   s£   |  d } t  } t | t ƒ s7 t } t |  d ƒ } n  | j ƒ  } d j | d j ƒ  t j	 d j | d ƒ ƒ d f ƒ } | rŸ | j
 d ƒ j d d ƒ } n  | S(   s@   
    Dedent and convert pkg_info['Description'] to Unicode.
    R'   s   
i    i   t   utf8R=   R>   (   t   FalseR@   RA   t   TrueRH   t
   splitlinesR   t   lstript   textwrapt   dedentRC   RD   (   R3   R:   t
   surrogatest   description_linest   description_dedent(    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyR0   t   s    
	(   t   __doc__t   os.pathR)   t   reRN   R   t   pkginfoR    t   compilet   EXTRA_RER   R   R#   R;   RH   R0   (    (    (    s/   /tmp/pip-install-MqWfHP/wheel/wheel/metadata.pyt   <module>   s   						