ó
.¿”Wc           @   sÓ  d  Z  d d l m Z d d l m Z d d l m Z y d d l m Z Wn e k
 rc e	 Z n Xd 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
   namedtuplei   (   t   read_pkg_info(   t   OrderedDefaultDict(   t   OrderedDictNs   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-Q3rTTP/wheel/wheel/metadata.pyt   unique,   s
    	c         C   s¬  t  t ƒ } x­ t | j | ƒ ƒ D]– } t j | ƒ } | r† | j ƒ  } | d } | d } | d }	 | j d ƒ r˜ | d  } q˜ n d \ } } | }	 t	 | | ƒ } | | j
 |	 ƒ q" W| r¨g  |  d <d „  }
 x~ t | j ƒ  d |
 ƒD]d \ } } t d	 | f f ƒ } | j r(| j | d <n  | j rA| j | d
 <n  |  d j
 | ƒ qî Wd |  k rog  |  d <n  |  d j g  | j ƒ  D] } | j r†| j ^ q†ƒ n  d S(   sE   
    Place the runtime requirements from pkg_info into metadata.
    R   R   t   packages    and iûÿÿÿt   run_requiresc         S   s&   |  \ } } | j  d  k r d S| j  S(   Nt    (   R   t   None(   t   itemt   keyR   (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyt   sort_keyM   s    R!   t   requirest   environmentR   N(   NN(   R   t   listt   sortedt   get_allt   EXTRA_REt   searcht	   groupdictt   endswithR   R   t   appendt   itemsR   R   R   t   extendt   keys(   t   metadatat   pkg_infoR!   t   may_requiresR   t   extra_matchR*   R   R   R   R"   t   may_requirement(    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyt   handle_requires7   s6    



	%		c         C   s9  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  xbt t d „  | j ƒ  Dƒ ƒ ƒ D]>} | j d d ƒ } | t k req;n  | t k rŒ| j | ƒ d k rŒq;n  | t t ƒ k r¸| j | ƒ | t | <q;| d k r×t | | | ƒ q;| d k rd | k rüg  | d <n  | d j | j | ƒ ƒ q;| d k rEi | | d 6| d d d <q;| d k rkt j | | ƒ | d <q;| | | | <q;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  } x~ t& D]v \ } } t' ƒ  } x> t | ƒ D]0 } | | | k r^| j( | | ƒ | | <q^q^W| r<| | d <| j) | ƒ q<q<W| rÑ| | d d d <n  yë t
 t* j+ j, t* j+ j- |  ƒ d ƒ d ƒ  } t. j/ j0 | j ƒ  ƒ } Wd  QXt' ƒ  } xy t | j1 ƒ  ƒ D]e \ } } t' ƒ  | | <xI t t2 t3 | j4 ƒ  ƒ ƒ D], } | j d! d" ƒ \ } } | | | | <qpWq;W| r»| | d d# <n  Wn t5 k
 rÏn Xd# | d k r5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   R   (    (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyt   <lambda>l   s    (   R   (    (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyR6   l   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-Q3rTTP/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(   RJ   RK   (   (   RJ   RK   (   s   console_scriptsRP   (   s   gui_scriptsRR   (6   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   R/   t   replacet   SKIP_FIELDSt   UNKNOWN_FIELDSt   gett   PLURAL_FIELDSR'   R5   R.   t   KEYWORDS_REt   splitt   METADATA_VERSIONR   t   getattrR%   t   convert_requirementst   AttributeErrort   CONTACT_FIELDSR   t   popR,   t   ost   patht   joint   dirnamet   pkg_resourcest
   EntryPointt	   parse_mapR-   t   mapt   strt   valuest   IOError(   Rp   t   distributionR0   R1   R=   t   payloadR!   t   low_keyR#   t   attrt   requirementst   new_requirementsRM   t   contact_typeRL   t   contactt   ep_filet   ep_mapt   exportst   groupR-   R    R   t   exportt	   ep_scriptt   wrap_script(    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyt   pkginfo_to_dicta   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.R   s    (%s)t   ,(   t   specsR,   Rq   (   t   requirementRD   t   opt   ver(    (    s-   /tmp/pip-build-Q3rTTP/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(   Rs   t   Requirementt   parseR   Rq   R   t   project_name(   R~   t   reqt   parsed_requirementt   specR   (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyRk   ä   s    c   
      C   sc  t  | ƒ } | j d d ƒ t j j |  d ƒ } t j j | ƒ r2t | ƒ j ƒ  } xÚ t t	 j
 | ƒ d d „  ƒ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 t | ƒ ƒ D] } | | | d <qWqt Wn  | d }	 |	 r_| 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!   c         S   s   |  d p d S(   Ni    R   (    (   t   x(    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyR6   ù   s    R   t   :i   s   Provides-Extras    and s   extra == %ss   ; s   Requires-DistR<   (   R   t   replace_headerRo   Rp   Rq   t   existsRZ   R[   R&   Rs   t   split_sectionsRh   t   reprRk   t   set_payloadR^   (
   t   egg_info_patht   pkginfo_pathR1   t   requires_pathR#   R   t   reqsR   t   new_reqR=   (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyt   pkginfo_to_metadataî   s0    


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`   Rw   t   hasattrR£   t   encodeR\   (   R1   t   fieldt   textR    (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyR]     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`   Rw   t   TrueR]   t
   splitlinesRq   t   lstript   textwrapt   dedentR§   R\   (   R1   R=   t
   surrogatest   description_linest   description_dedent(    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyR^     s    
	t   __main__(   s   authors   author_emails   platforms	   home_pages   license(   s	   conditions   extra()   t   __doc__t   collectionsR    t   pkginfoR   t   utilR   R   t   ImportErrort   dictt   ret   os.pathRo   R¯   Rs   t   email.parserR   RS   Ri   Rf   R   Rc   Rm   Rd   t   compileR(   Rg   R   R   R5   R   R‰   R   Rk   R¢   R]   R^   t   __name__t   syst   pprintt   argv(    (    (    s-   /tmp/pip-build-Q3rTTP/wheel/wheel/metadata.pyt   <module>   sL   


				*z			
	!		