ó
©9Vc           @   s›  d  Z  d d l m Z m Z d d l m Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d Z i d d 6d	 d
 6d d 6Z e ƒ  Z i d d 6d d 6d f i d d 6d d 6d f f Z e d$ ƒ Z e j d ƒ Z e j d ƒ Z e d d% ƒ Z d „  Z d „  Z d d „ Z d „  Z d „  Z d  „  Z d! „  Z d" „  Z  e! d# k r—d d l" Z" d d l# Z# e# j# e e" j$ d ƒ ƒ n  d S(&   s2   
Tools for converting old- to new-style metadata.
iÿÿÿÿ(   t   defaultdictt
   namedtuplei   (   t   read_pkg_infoNs   2.0t   classifierst
   classifiert   providest   provides_distt   extrast   provides_extrat   author_emailt   emailt   authort   namet   maintainer_emailt
   maintainert   platformt	   home_paget   licensesF   ^(?P<package>.*?)(;\s*(?P<condition>.*?)(extra == '(?P<extra>.*?)')?)$s   [ -,]+t   MayRequiresKeyt	   conditiont   extrac         c   s?   t  ƒ  } x/ |  D]' } | | k r | j | ƒ | Vq q Wd S(   s<   
    Yield unique values in iterable, preserving order.
    N(   t   sett   add(   t   iterablet   seent   value(    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   unique'   s
    	c         C   s‰  t  t ƒ } x§ | j | ƒ D]– } t j | ƒ } | r€ | j ƒ  } | d } | d } | d }	 | j d ƒ r’ | d  } q’ n d \ } } | }	 t | | ƒ } | | j	 |	 ƒ q W| r…g  |  d <xj | j
 ƒ  D]\ \ } } i | d 6}
 | j r| j |
 d <n  | j r| j |
 d <n  |  d j	 |
 ƒ qÓ Wd	 |  k rLg  |  d	 <n  |  d	 j g  | j ƒ  D] } | j rc| j ^ qcƒ n  d
 S(   sE   
    Place the runtime requirements from pkg_info into metadata.
    R   R   t   packages    and iûÿÿÿt   run_requirest   requirest   environmentR   N(   NN(   R    t   listt   get_allt   EXTRA_REt   searcht	   groupdictt   endswitht   NoneR   t   appendt   itemsR   R   t   extendt   keys(   t   metadatat   pkg_infot   keyt   may_requiresR   t   extra_matchR#   R   R   R   t   may_requirement(    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   handle_requires2   s4    



		c         C   s  t  d „  ƒ } d t j d | d <y t t |  ƒ } WnA t k
 r{ t j j ƒ  j	 t
 |  d ƒ j ƒ  j d ƒ ƒ } n Xd  } | d r© t | d ƒ | d <| d =n  | d	 rÉ t | ƒ } | d	 =n< | j ƒ  } t | t ƒ rö | j d ƒ } n  | r| } n  | r| | d
 <n  xVt d „  | j ƒ  Dƒ ƒ D]8} | j d d ƒ } | t k r_q5n  | t k r†| j | ƒ d k r†q5n  | t k r¬| j | ƒ | t | <q5| d k rËt | | | ƒ q5| d k rd | k rðg  | d <n  | d j | j | ƒ ƒ q5| d k r9i | | d 6| d d d <q5| d k r_t j | | ƒ | d <q5| | | | <q5Wt | d <d | k r¤t  t! | d ƒ ƒ | d <n  | r#xv d* D]k \ } }	 yK t" | |	 ƒ }
 t |
 t# ƒ rt# t$ |
 ƒ ƒ } i | d 6g | | <n  Wq±t% k
 rq±Xq±Wn  g  } xu t& D]m \ } } i  } x8 | D]0 } | | | k rI| j' | | ƒ | | <qIqIW| r0| | d <| j( | ƒ q0q0W| r¼| | d d d <n  yÖ t
 t) j* j+ t) j* j, |  ƒ d ƒ d ƒ  } t- j. j/ | j ƒ  ƒ } Wd  QXi  } xg | j0 ƒ  D]Y \ } } i  | | <x@ | j1 ƒ  D]2 } t2 | ƒ j d! d" ƒ \ } } | | | | <q@WqW| r‘| | d d# <n  Wn t3 k
 r¥n Xd# | d k rxR d+ d, f D]A \ } } | | d d# k rÃ| d d# | | d d( | <qÃqÃWn  | S(-   s  
    Convert PKG-INFO to a prototype Metadata 2.0 (PEP 426) dict.

    The description is included under the key ['description'] rather than
    being written to a separate file.

    path: path to PKG-INFO file
    distribution: optional distutils Distribution()
    c           S   s   t  d „  ƒ S(   Nc           S   s
   t  t ƒ S(   N(   R    t   dict(    (    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   <lambda>`   s    (   R    (    (    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyR2   `   s    s   bdist_wheel (t   )t	   generatort   rbs   utf-8t   Summaryt   summaryt   Descriptiont   descriptionc         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   lower(   t   .0t   k(    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pys	   <genexpr>|   s    t   -t   _t   UNKNOWNt   requires_distR   R   R   t   Homet
   extensionss   python.detailst   project_urlst   keywordst   metadata_versiont   test_requirest   tests_requireR   t   rolet   contactss   entry_points.txtt   rNs    = i   s   python.exportst   console_scriptst   wrap_consolet   gui_scriptst   wrap_guis   python.commands(   RF   RG   (   (   RF   RG   (   s   console_scriptsRL   (   s   gui_scriptsRN   (4   R    t   wheelt   __version__t   unicodeR   t	   NameErrorR
   t   parsert   Parsert   parsestrt   opent   readt   decodeR%   t   pkginfo_unicodet   dedent_descriptiont   get_payloadt
   isinstancet   bytesR   R)   t   replacet   SKIP_FIELDSt   UNKNOWN_FIELDSt   gett   PLURAL_FIELDSR    R0   R(   t   KEYWORDS_REt   splitt   METADATA_VERSIONt   sortedR   t   getattrR   t   convert_requirementst   AttributeErrort   CONTACT_FIELDSt   popR&   t   ost   patht   joint   dirnamet   pkg_resourcest
   EntryPointt	   parse_mapR'   t   valuest   strt   IOError(   Rm   t   distributionR*   R+   R9   t   payloadR,   t   low_keyR   t   attrt   requirementst   new_requirementsRI   t   contact_typeRH   t   contactt   ep_filet   ep_mapt   exportst   groupR'   t   itemR   t   exportt	   ep_scriptt   wrap_script(    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   pkginfo_to_dictU   s¤    4



	#! 

-
(c         C   sL   g  } x( |  j  D] \ } } | j | | ƒ q W| s; d Sd d j | ƒ S(   sB   Compose the version predicates for requirement in PEP 345 fashion.t    s    (%s)t   ,(   t   specsR&   Rn   (   t   requirementR@   t   opt   ver(    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   requires_to_requires_distÏ   s    c         c   sh   xa |  D]Y } t  j j | ƒ } t | ƒ } d j | j ƒ } | rP d | } n  | j | | Vq Wd S(   s=   Yield Requires-Dist: strings for parsed requirements strings.Rˆ   s   [%s]N(   Rp   t   Requirementt   parseR   Rn   R   t   project_name(   Rz   t   reqt   parsed_requirementt   specR   (    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyRh   Ø   s    c   
      C   sN  t  | ƒ } | j d d ƒ t j j |  d ƒ } t j j | ƒ rt | ƒ j ƒ  } xÅ t j	 | ƒ D]± \ } } d } | r¤ d | k r¤ | j
 d d ƒ \ } } n  | rÞ | | d <| rÇ | d 7} n  | d	 t | ƒ 7} n  | rñ d
 | } n  x" t | ƒ D] } | | | d <qþ Wqe Wn  | d }	 |	 rJ| j t | ƒ ƒ | d =n  | S(   sn   
    Convert .egg-info directory with PKG-INFO to the Metadata 1.3 aka
    old-draft Metadata 2.0 format.
    s   Metadata-Versions   2.0s   requires.txtR‡   t   :i   s   Provides-Extras    and s   extra == %ss   ; s   Requires-DistR8   (   R   t   replace_headerRl   Rm   Rn   t   existsRV   RW   Rp   t   split_sectionsRd   t   reprRh   t   set_payloadRZ   (
   t   egg_info_patht   pkginfo_pathR+   t   requires_pathR   R   t   reqsR   t   new_reqR9   (    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   pkginfo_to_metadataâ   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(   R:   R\   Rt   t   hasattrR    t   encodeRX   (   R+   t   fieldt   textR‚   (    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyRY     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.
    R8   s   
i    i   t   utf8R¡   R¢   (   t   FalseR\   Rt   t   TrueRY   t
   splitlinesRn   t   lstript   textwrapt   dedentR¤   RX   (   R+   R9   t
   surrogatest   description_linest   description_dedent(    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyRZ     s    
	t   __main__(   s   authors   author_emails   platforms	   home_pages   license(   s	   conditions   extra(%   t   __doc__t   collectionsR    R   t   pkginfoR   t   ret   os.pathRl   R¬   Rp   t   email.parserR
   RO   Re   Rb   R   R_   Rj   R`   t   compileR!   Rc   R   R   R0   R%   R†   R   Rh   RŸ   RY   RZ   t   __name__t   syst   pprintt   argv(    (    (    s-   /tmp/pip-build-5Z5nTX/wheel/wheel/metadata.pyt   <module>   sB   

				#z			
	 		