ó
Ð²Ebc           @   s˜  d  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 d l Z d d l Z d d l	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z m Z d d l Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! 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* d d l+ m, Z, d d l- m. Z. e/ Z0 e j1 d ƒ Z2 e j1 d e j3 ƒ Z4 e j1 d ƒ Z5 e j1 d e j3 ƒ j6 Z7 d j8 ƒ  Z9 d d d d g Z: d Z; d Z< e< j= d d j= e j> Œ  d e ƒ Z? d „  Z@ d „  ZA d „  ZB eC d „ ZD eC d  „ ZE eC d! „ ZF eC e eC d" „ ZG eC d# „ ZH d$ „  ZI e j1 d% e j3 ƒ ZJ eI d& „  ƒ ZK d' f  d( „  ƒ  YZL d) eL f d* „  ƒ  YZM d e f d+ „  ƒ  YZN e j1 d, ƒ jO ZP d- „  ZQ d. „  ZR d d/ „ ZS d0 „  ZT d1 f  d2 „  ƒ  YZU d3 e jV f d4 „  ƒ  YZW e jX jY d5 „ ZZ d6 „  Z[ eS e; ƒ eZ ƒ ZZ d7 „  Z\ d8 „  Z] d S(9   s#   PyPI and direct package downloadingiÿÿÿÿN(   t   wraps(   t   six(   t   urllibt   http_clientt   configparsert   map(   t   CHECKOUT_DISTt   Distributiont   BINARY_DISTt   normalize_patht   SOURCE_DISTt   Environmentt   find_distributionst	   safe_namet   safe_versiont   to_filenamet   Requirementt   DEVELOP_DISTt   EGG_DIST(   t   ssl_support(   t   log(   t   DistutilsError(   t	   translate(   t   get_all_headers(   t   unescape(   t   Wheels   ^egg=([-A-Za-z0-9_.+!]+)$s   href\s*=\s*['"]?([^'"> ]+)sƒ   <a href="([^"#]+)">([^<]+)</a>\n\s+\(<a (?:title="MD5 hash"\n\s+)href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\)s   ([-+.a-z0-9]{2,}):s   .tar.gz .tar.bz2 .tar .zip .tgzt   PackageIndext   distros_for_urlt   parse_bdist_wininstt   interpret_distro_namei   s<   setuptools/{setuptools.__version__} Python-urllib/{py_major}t   py_majors   {}.{}t
   setuptoolsc         C   s<   y t  j |  ƒ SWn$ t k
 r7 t d |  f ƒ ‚ n Xd  S(   Ns1   Not a URL, existing file, or requirement spec: %r(   R   t   parset
   ValueErrorR   (   t   spec(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   parse_requirement_arg4   s
    c         C   sâ   |  j  ƒ  } d \ } } } | j d ƒ rÕ | j d ƒ rL |  d  } d } qÕ | j d d ƒ r~ |  d d !} |  d  } d } qÕ | j d	 ƒ r  |  d
  } d } qÕ | j d d ƒ rÕ |  d d !} |  d  } d } qÕ n  | | | f S(   s=   Return (base,pyversion) or (None,None) for possible .exe names   .exes
   .win32.exeiöÿÿÿt   win32s	   .win32-pyiðÿÿÿiùÿÿÿiüÿÿÿs   .win-amd64.exeiòÿÿÿs	   win-amd64s   .win-amd64-pyiìÿÿÿN(   NNN(   t   lowert   Nonet   endswitht
   startswith(   t   nameR%   t   baset   py_vert   plat(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   =   s$    
	
	
	
c   	      C   s´   t  j j |  ƒ } | \ } } } } } } t  j j | j d ƒ d ƒ } | d k rƒ | d k rƒ t  j j | j d ƒ d ƒ } n  d | k rª | j d d ƒ \ } } n  | | f S(   Nt   /iÿÿÿÿs   sourceforge.nett   downloadiþÿÿÿt   #i   (   R   R    t   urlparset   unquotet   split(	   t   urlt   partst   schemet   servert   patht
   parameterst   queryt   fragmentR*   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   egg_info_for_urlU   s    "c         c   sŠ   t  |  ƒ \ } } x t |  | | ƒ D] } | Vq% W| r† t j | ƒ } | r† x1 t |  | j d ƒ | d t ƒD] } | Vqq Wq† n  d S(   sE   Yield egg or source distribution objects that might be found at a URLi   t
   precedenceN(   R;   t   distros_for_locationt   EGG_FRAGMENTt   matchR   t   groupR   (   R3   t   metadataR*   R:   t   distR?   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   `   s    	"c      
   C   sA  | j  d ƒ r | d  } n  | j  d ƒ rM d | k rM t j |  | | ƒ g S| j  d ƒ r° d | k r° t | ƒ } | j ƒ  s„ g  St d |  d | j d | j d	 t d
 ƒ g S| j  d ƒ rü t | ƒ \ } } } | d k	 rü t
 |  | | | t | ƒ Sn  x> t D]6 } | j  | ƒ r| t | ƒ  } t
 |  | | ƒ SqWg  S(   s:   Yield egg or source distribution objects based on basenames   .egg.zipiüÿÿÿs   .eggt   -s   .whlt   locationt   project_namet   versionR<   i   s   .exeN(   R'   R   t   from_locationR   t   is_compatibleRE   RF   R   R   R&   R   R   t
   EXTENSIONSt   len(   RD   t   basenameRA   t   wheelt   win_baseR+   t   platformt   ext(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR=   n   s.    		c         C   s"   t  t |  ƒ t j j |  ƒ | ƒ S(   sE   Yield possible egg or source distribution objects based on a filename(   R=   R	   t   osR7   RK   (   t   filenameRA   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   distros_for_filename   s    c         c   sœ   | j  d ƒ } | r4 t d „  | d Dƒ ƒ r4 d Sxa t d t | ƒ d ƒ D]F } t |  | d j | |  ƒ d j | | ƒ d | d | d | ƒVqN Wd S(	   sØ   Generate alternative interpretations of a source distro name

    Note: if `location` is a filesystem filename, you should call
    ``pkg_resources.normalize_path()`` on it before passing it to this
    routine!
    RC   c         s   s!   |  ] } t  j d  | ƒ Vq d S(   s	   py\d\.\d$N(   t   reR?   (   t   .0t   p(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pys	   <genexpr>­   s    i   Ni   t
   py_versionR<   RN   (   R2   t   anyt   rangeRJ   R   t   join(   RD   RK   RA   RV   R<   RN   R4   RU   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   –   s    ! )c         c   s’   t  ƒ  } | j } | d k rS xm t j j | j |  ƒ D] } | | ƒ | Vq7 Wn; x8 |  D]0 } | | ƒ } | | k rZ | | ƒ | VqZ qZ Wd S(   sH   List unique elements, preserving order. Remember all elements ever seen.N(   t   sett   addR&   R   t   movest   filterfalset   __contains__(   t   iterablet   keyt   seent   seen_addt   elementt   k(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   unique_everseenº   s    		

c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   ss   
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    c             s   t  ˆ  |  | Ž  ƒ S(   N(   Re   (   t   argst   kwargs(   t   func(    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   wrapperÒ   s    (   R    (   Rh   Ri   (    (   Rh   s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   unique_valuesÌ   s    s(   <([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>c         c   s  x¨ t  j | ƒ D]— } | j ƒ  \ } } t t t j | j ƒ  j d ƒ ƒ ƒ } d | k sg d | k r x= t	 j | ƒ D]) } t
 j j |  t | j d ƒ ƒ ƒ Vqw Wq q Wxj d	 D]b } | j | ƒ } | d k r² t	 j | | ƒ } | rt
 j j |  t | j d ƒ ƒ ƒ Vqq² q² Wd S(
   sE   Find rel="homepage" and rel="download" links in `page`, yielding URLst   ,t   homepageR.   i   s   <th>Home Pages   <th>Download URLiÿÿÿÿN(   s   <th>Home Pages   <th>Download URL(   t   RELt   finditert   groupsRZ   R   t   strt   stripR%   R2   t   HREFR   R    t   urljoint
   htmldecodeR@   t   findt   search(   R3   t   pageR?   t   tagt   relt   relst   pos(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   find_external_linksÝ   s    '.t   ContentCheckerc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sP   
    A null content checker that defines the interface for checking content
    c         C   s   d S(   s3   
        Feed a block of data to the hash.
        N(    (   t   selft   block(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   feedõ   s    c         C   s   t  S(   sC   
        Check the hash. Return False if validation fails.
        (   t   True(   R~   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   is_validû   s    c         C   s   d S(   su   
        Call reporter with information about the checker (hash name)
        substituted into the template.
        N(    (   R~   t   reportert   template(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   report  s    (   t   __name__t
   __module__t   __doc__R€   R‚   R…   (    (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR}   ð   s   		t   HashCheckerc           B   sJ   e  Z e j d  ƒ Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 RS(   sK   (?P<hash_name>sha1|sha224|sha384|sha256|sha512|md5)=(?P<expected>[a-f0-9]+)c         C   s(   | |  _  t j | ƒ |  _ | |  _ d  S(   N(   t	   hash_namet   hashlibt   newt   hasht   expected(   R~   RŠ   RŽ   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   __init__  s    	c         C   sR   t  j j | ƒ d } | s# t ƒ  S|  j j | ƒ } | sB t ƒ  S|  | j ƒ    S(   s5   Construct a (possibly null) ContentChecker from a URLiÿÿÿÿ(   R   R    R0   R}   t   patternRv   t	   groupdict(   t   clsR3   R:   R?   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   from_url  s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   update(   R~   R   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR€     s    c         C   s   |  j  j ƒ  |  j k S(   N(   R   t	   hexdigestRŽ   (   R~   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR‚   "  s    c         C   s   | |  j  } | | ƒ S(   N(   RŠ   (   R~   Rƒ   R„   t   msg(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR…   %  s    (   R†   R‡   RS   t   compileR   R   t   classmethodR“   R€   R‚   R…   (    (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR‰   	  s   				c           B   sv  e  Z d  Z d d% d& e d „ Z e d „ Z e d „ Z e d „ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d& d „ Z d „  Z d& d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e e e d& d „ Z e e d „ Z d „  Z d Z d „  Z d „  Z d& d „ Z d „  Z d „  Z d „  Z d „  Z  d „  Z! e" e d „ ƒ Z# d  „  Z$ d! „  Z% d" „  Z& d# „  Z' d$ „  Z( RS('   s;   A distribution index that scans web pages for download URLss   https://pypi.org/simple/t   *c         O   sÈ   t  j |  | | Ž | d | j d ƒ  |  _ i  |  _ i  |  _ i  |  _ t j d j	 t
 t | ƒ ƒ ƒ j |  _ g  |  _ | o— t j o— | p— t j ƒ  } | rµ t j | ƒ |  _ n t j j |  _ d  S(   NR-   t   |(   R   R   R'   t	   index_urlt   scanned_urlst   fetched_urlst   package_pagesRS   R—   RY   R   R   R?   t   allowst   to_scanR   t   is_availablet   find_ca_bundlet
   opener_fort   openerR   t   requestt   urlopen(   R~   R›   t   hostst	   ca_bundlet
   verify_sslRf   t   kwt   use_ssl(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   -  s    			'		c         C   sg  | |  j  k r | r d St |  j  | <t | ƒ sD |  j | ƒ d St t | ƒ ƒ } | r‚ |  j | ƒ so d S|  j d | ƒ n  | sž | sž | |  j k r¸ t t	 |  j
 | ƒ ƒ d S|  j | ƒ sØ t |  j | <d S|  j d | ƒ t |  j | <d } |  j | | | ƒ } | d k r!d St |  j | j <d | j j d d ƒ j ƒ  k r`| j ƒ  d S| j } | j ƒ  } t | t ƒ sÏt | t j j ƒ r¢d } n | j j d	 ƒ p·d } | j | d
 ƒ } n  | j ƒ  xH t j | ƒ D]7 }	 t j j | t |	 j  d ƒ ƒ ƒ }
 |  j! |
 ƒ qéW| j" |  j# ƒ rct$ | d d ƒ d k rc|  j% | | ƒ } n  d S(   s<   Evaluate a URL as a possible download, and maybe retrieve itNs   Found link: %ss
   Reading %ss<   Download error on %s: %%s -- Some packages may not be found!t   htmls   content-typet    s   latin-1t   charsett   ignorei   t   codei”  (&   Rœ   R   t
   URL_SCHEMEt   process_filenamet   listR   t   url_okt   debugR   R   R[   t   infot   open_urlR&   R3   t   headerst   getR%   t   closet   readt
   isinstanceRp   R   t   errort	   HTTPErrort	   get_paramt   decodeRr   Rn   R    Rs   Rt   R@   t   process_urlR(   R›   t   getattrt   process_index(   R~   R3   t   retrievet   distst   tmplt   fR*   Rw   R®   R?   t   link(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRÁ   B  sP    !
		
$*c         C   sÌ   t  j j | ƒ s& |  j d | ƒ d  St  j j | ƒ r | r t  j j | ƒ } x9 t  j | ƒ D]% } |  j t  j j | | ƒ t	 ƒ qa Wn  t
 | ƒ } | rÈ |  j d | ƒ t t |  j | ƒ ƒ n  d  S(   Ns   Not found: %ss	   Found: %s(   RP   R7   t   existst   warnt   isdirt   realpatht   listdirR²   RY   R   RR   Rµ   R³   R   R[   (   R~   t   fnt   nestedR7   t   itemRÅ   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR²   u  s    &c         C   s‰   t  | ƒ } | o* | j d ƒ j ƒ  d k } | sR |  j t j j | ƒ d ƒ rV t Sd } | ru t | | ƒ ‚ n |  j	 | | ƒ d  S(   Ni   t   filesN   
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
(
   R±   R@   R%   RŸ   R   R    R0   R   R   RÊ   (   R~   R3   t   fatalt   st   is_fileR–   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR´   …  s    !%c         C   sB   t  t j j | ƒ } d „  | Dƒ } t t j |  j | ƒ ƒ d  S(   Nc         s   s@   |  ]6 } t  j | ƒ D]  } | j d  ƒ r | | f Vq q d S(   s	   .egg-linkN(   RP   RÍ   R'   (   RT   R7   t   entry(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pys	   <genexpr>•  s   (   t   filterRP   R7   RË   R³   t	   itertoolst   starmapt   scan_egg_link(   R~   t   search_patht   dirst	   egg_links(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   scan_egg_links’  s    
c      
   C   s¿   t  t j j | | ƒ ƒ ( } t t d  t t j	 | ƒ ƒ ƒ } Wd  QXt
 | ƒ d k r[ d  S| \ } } xQ t t j j | | ƒ ƒ D]4 } t j j | | Œ | _ t | _ |  j | ƒ qƒ Wd  S(   Ni   (   t   openRP   R7   RY   R³   RÖ   R&   R   Rp   Rq   RJ   R   RD   R
   R<   R[   (   R~   R7   RÕ   t	   raw_linest   linest   egg_patht
   setup_pathRB   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRÙ   œ  s    '"	c   
         s  ‡  f d †  } xW t  j | ƒ D]F } y, | t j j | t | j d ƒ ƒ ƒ ƒ Wq t k
 rd q Xq W| | ƒ \ } } | rxy t | | ƒ D]h } t	 | ƒ \ } }	 | j
 d ƒ rì |	 rì | rÜ | d | | f 7} qì ˆ  j | ƒ n  ˆ  j | ƒ q‘ Wt j d „  | ƒ Sd Sd S(   s#   Process the contents of a PyPI pagec            sÁ   |  j  ˆ  j ƒ r½ t t t j j |  t ˆ  j ƒ j d ƒ ƒ ƒ } t | ƒ d k r½ d | d k r½ t	 | d ƒ } t
 | d ƒ } t ˆ  j j | j ƒ  i  ƒ |  <t | ƒ t | ƒ f Sn  d S(   NR-   i   R/   i   i    (   NN(   R(   R›   R³   R   R   R    R1   RJ   R2   R   R   R   Rž   t
   setdefaultR%   R   R&   (   RÈ   R4   t   pkgt   ver(   R~   (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   scan¯  s    +"i   s   .pys
   #egg=%s-%sc         S   s   d |  j  d d d ƒ S(   Ns   <a href="%s#md5=%s">%s</a>i   i   i   (   R@   (   t   m(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   <lambda>Ò  R­   R­   N(   Rr   Rn   R   R    Rs   Rt   R@   R!   R|   R;   R'   t   need_version_infot   scan_urlt   PYPI_MD5t   sub(
   R~   R3   Rw   Ræ   R?   Rä   Rå   t   new_urlR*   t   frag(    (   R~   s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRÃ   ¬  s$    ,c         C   s   |  j  d | ƒ d  S(   NsP   Page at %s links to .py file(s) without version info; an index scan is required.(   t   scan_all(   R~   R3   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRé   ×  s    c         G   sO   |  j  |  j k r; | r+ |  j | | Œ n  |  j d ƒ n  |  j |  j  ƒ d  S(   Ns6   Scanning index of all packages (this may take a while)(   R›   R   RÊ   R¶   Rê   (   R~   R–   Rf   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRï   Ý  s    
c         C   s­   |  j  |  j | j d ƒ |  j j | j ƒ sN |  j  |  j | j d ƒ n  |  j j | j ƒ ss |  j | ƒ n  x3 t |  j j | j d ƒ ƒ D] } |  j  | ƒ q’ Wd  S(   NR-   (    (	   Rê   R›   t   unsafe_nameRž   R¹   R`   RE   t   not_found_in_indexR³   (   R~   t   requirementR3   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   find_packagesæ  s    %c         C   sk   |  j  ƒ  |  j | ƒ x8 |  | j D]) } | | k r; | S|  j d | | ƒ q% Wt t |  ƒ j | | ƒ S(   Ns   %s does not match %s(   t   prescanRó   R`   Rµ   t   superR   t   obtain(   R~   Rò   t	   installerRB   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRö   õ  s    
c         C   si   | j  |  j d | ƒ | j ƒ  se | j ƒ  t j | ƒ t d | j j t j	 j
 | ƒ f ƒ ‚ n  d S(   s-   
        checker is a ContentChecker
        s   Validating %%s checksum for %ss7   %s validation failed for %s; possible download problem?N(   R…   Rµ   R‚   Rº   RP   t   unlinkR   R   R)   R7   RK   (   R~   t   checkerRQ   t   tfp(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt
   check_hashþ  s    
c         C   sr   xk | D]c } |  j  d k sJ t | ƒ sJ | j d ƒ sJ t t | ƒ ƒ rZ |  j | ƒ q |  j  j | ƒ q Wd S(   s;   Add `urls` to the list that will be prescanned for searchess   file:N(   R    R&   R±   R(   R³   R   Rê   t   append(   R~   t   urlsR3   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   add_find_links  s    c         C   s2   |  j  r% t t |  j |  j  ƒ ƒ n  d |  _  d S(   s7   Scan urls scheduled for prescanning (e.g. --find-links)N(   R    R³   R   Rê   R&   (   R~   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRô     s    	c         C   sN   |  | j  r  |  j d } } n |  j d } } | | | j ƒ |  j ƒ  d  S(   Ns#   Couldn't retrieve index page for %rs3   Couldn't find index page for %r (maybe misspelled?)(   R`   R¶   RÊ   Rð   Rï   (   R~   Rò   t   methR–   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRñ   #  s    
c         C   s½   t  | t ƒ s¡ t | ƒ } | r| |  j | j d ƒ | | ƒ } t | ƒ \ } } | j d ƒ rx |  j | | | ƒ } n  | St j	 j
 | ƒ r’ | St | ƒ } n  t |  j | | ƒ d d ƒ S(   s  Locate and/or download `spec` to `tmpdir`, returning a local path

        `spec` may be a ``Requirement`` object, or a string containing a URL,
        an existing local filename, or a project/version requirement spec
        (i.e. the string form of a ``Requirement`` object).  If it is the URL
        of a .py file with an unambiguous ``#egg=name-version`` tag (i.e., one
        that escapes ``-`` as ``_`` throughout), a trivial ``setup.py`` is
        automatically created alongside the downloaded file.

        If `spec` is a ``Requirement`` object or a string containing a
        project/version requirement spec, this method returns the location of
        a matching distribution (possibly after downloading it to `tmpdir`).
        If `spec` is a locally existing file or directory name, it is simply
        returned unchanged.  If `spec` is a URL, it is downloaded to a subpath
        of `tmpdir`, and the local filename is returned.  Various errors may be
        raised if a problem occurs during downloading.
        i   s   .pyRD   N(   R¼   R   R±   t   _download_urlR@   R;   R'   t	   gen_setupRP   R7   RÉ   R#   RÂ   t   fetch_distributionR&   (   R~   R"   t   tmpdirR5   t   foundR*   R:   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR.   -  s    c   	         sF  ˆ j  d | ƒ i  ‰ d } d ‡  ‡ ‡ ‡ ‡ f d † } | rf ˆ j ƒ  ˆ j | ƒ | | ƒ } n  | r‹ | d k	 r‹ | | | ƒ } n  | d k rÂ ˆ j d k	 r³ ˆ j ƒ  n  | | ƒ } n  | d k rñ | rñ ˆ j | ƒ | | ƒ } n  | d k rˆ j d ˆ rd pd | ƒ n# ˆ j  d | ƒ | j d | j ƒ Sd S(	   s|  Obtain a distribution suitable for fulfilling `requirement`

        `requirement` must be a ``pkg_resources.Requirement`` instance.
        If necessary, or if the `force_scan` flag is set, the requirement is
        searched for in the (online) package index as well as the locally
        installed packages.  If a distribution matching `requirement` is found,
        the returned distribution's ``location`` is the value you would have
        gotten from calling the ``download()`` method with the matching
        distribution's URL or filename.  If no matching distribution is found,
        ``None`` is returned.

        If the `source` flag is set, only source distributions and source
        checkout links will be considered.  Unless the `develop_ok` flag is
        set, development and system eggs (i.e., those using the ``.egg-info``
        format) will be ignored.
        s   Searching for %sc            sØ   | d  k r ˆ } n  x¼ | |  j D]­ } | j t k rn ˆ  rn | ˆ k r# ˆ j d | ƒ d ˆ | <q# q# n  | |  k o | j t k p ˆ } | r# ˆ j | j ˆ ƒ } | | _ t	 j
 j | j ƒ rÐ | Sq# q# Wd  S(   Ns&   Skipping development or system egg: %si   (   R&   R`   R<   R   RÊ   R
   R.   RD   t   download_locationRP   R7   RÉ   (   t   reqt   envRB   t   testt   loc(   t
   develop_okR~   t   skippedt   sourceR  (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRu   g  s     	
	s:   No local packages or working download links found for %s%ss   a source distribution of R­   s   Best match: %sRD   N(   R¶   R&   Rô   Ró   R    RÊ   t   cloneR  (	   R~   Rò   R  t
   force_scanR  R
  t   local_indexRB   Ru   (    (   R
  R~   R  R  R  s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR  O  s0    

c         C   s/   |  j  | | | | ƒ } | d k	 r+ | j Sd S(   s3  Obtain a file suitable for fulfilling `requirement`

        DEPRECATED; use the ``fetch_distribution()`` method now instead.  For
        backward compatibility, this routine is identical but returns the
        ``location`` of the downloaded distribution instead of a distribution
        object.
        N(   R  R&   RD   (   R~   Rò   R  R  R  RB   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   fetch›  s    c      
   C   sp  t  j | ƒ } | rL g  t | | j d ƒ d  ƒ D] } | j r1 | ^ q1 pO g  } t | ƒ d k rAt j j	 | ƒ } t j j
 | ƒ | k rÞ t j j | | ƒ } d d l m }	 |	 | | ƒ sÞ t j | | ƒ | } qÞ n  t t j j | d ƒ d ƒ ? }
 |
 j d | d j | d j t j j | ƒ d f ƒ Wd  QX| S| r`t d | | f ƒ ‚ n t d	 ƒ ‚ d  S(
   Ni   iÿÿÿÿ(   t   samefiles   setup.pyt   wsI   from setuptools import setup
setup(name=%r, version=%r, py_modules=[%r])
i    s†   Can't unambiguously interpret project/version identifier %r; any dashes in the name or version should be escaped using underscores. %rsp   Can't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.(   R>   R?   R   R@   R&   RF   RJ   RP   R7   RK   t   dirnameRY   t   setuptools.command.easy_installR  t   shutilt   copy2RÞ   t   writeRE   t   splitextR   (   R~   RQ   R:   R  R?   t   dRÅ   RK   t   dstR  RÑ   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR  ¨  s2    4!!i    c      
   C   s‰  |  j  d | ƒ d  } zXt j | ƒ } |  j | ƒ } t | t j j ƒ rn t	 d | | j
 | j f ƒ ‚ n  | j  ƒ  } d } |  j } d } d | k rÛ t | d ƒ }	 t t t |	 ƒ ƒ } |  j | | | | | ƒ n  t | d ƒ } }
 x` t rO| j | ƒ } | rK| j | ƒ |
 j | ƒ | d 7} |  j | | | | | ƒ qð Pqð W|  j | | |
 ƒ Wd  QX| SWd  | r„| j ƒ  n  Xd  S(	   Ns   Downloading %ss   Can't download %s: %s %si    iÿÿÿÿs   content-lengths   Content-Lengtht   wbi   (   R¶   R&   R‰   R“   R·   R¼   R   R½   R¾   R   R°   R–   t   dl_blocksizeR   t   maxR   t   intt
   reporthookRÞ   R   R»   R€   R  Rû   Rº   (   R~   R3   RQ   t   fpRù   R¸   t   blocknumt   bst   sizet   sizesRú   R   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   _download_toÓ  s:    		
c         C   s   d  S(   N(    (   R~   R3   RQ   R!  t   blksizeR#  (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR  ÷  s    c         C   s§  | j  d ƒ r t | ƒ Sy t | |  j ƒ SWnst t j f k
 r¥ } d j g  | j D] } t	 | ƒ ^ qX ƒ } | rŒ |  j
 | | ƒ q£t d | | f ƒ ‚ nþ t j j k
 r¾ } | St j j k
 r} | rï |  j
 | | j ƒ q£t d | | j f ƒ ‚ n˜ t j k
 rU} | r9|  j
 | | j ƒ q£t d | | j f ƒ ‚ nN t j t j f k
 r¢} | r‰|  j
 | | ƒ q£t d | | f ƒ ‚ n Xd  S(   Ns   file:t    s   %s %ss   Download error for %s: %ss;   %s returned a bad status line. The server might be down, %s(   R(   t
   local_opent   open_with_authR¤   R!   R   t
   InvalidURLRY   Rf   Rp   RÊ   R   R   R½   R¾   t   URLErrort   reasont   BadStatusLinet   linet   HTTPExceptiont   socket(   R~   R3   t   warningt   vt   argR–   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR·   ú  s6    
+c         C   sH  t  | ƒ \ } } | rL x7 d | k rH | j d d ƒ j d d ƒ } q Wn d } | j d ƒ rn | d  } n  t j j | | ƒ } | d k sž | j d	 ƒ r® |  j | | ƒ S| d
 k sÉ | j d ƒ rÙ |  j | | ƒ S| j d ƒ rø |  j	 | | ƒ S| d k r$t
 j j t
 j j | ƒ d ƒ S|  j | t ƒ |  j | | ƒ Sd  S(   Ns   ..t   .s   \t   _t   __downloaded__s   .egg.zipiüÿÿÿt   svns   svn+t   gits   git+s   hg+RÑ   i   (   R;   t   replaceR'   RP   R7   RY   R(   t   _download_svnt   _download_gitt   _download_hgR   R¥   t   url2pathnameR    R0   R´   R   t   _attempt_download(   R~   R5   R3   R  R)   R:   RQ   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR     s$    % c         C   s   |  j  | t ƒ d  S(   N(   RÁ   R   (   R~   R3   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRê   :  s    c         C   sK   |  j  | | ƒ } d | j d d ƒ j ƒ  k rC |  j | | | ƒ S| Sd  S(   NR¬   s   content-typeR­   (   R%  R¹   R%   t   _download_html(   R~   R3   RQ   R¸   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR>  =  s    c         C   s‘   t  | ƒ } xW | D]O } | j ƒ  r t j d | ƒ r^ | j ƒ  t j | ƒ |  j | | ƒ SPq q W| j ƒ  t j | ƒ t d | ƒ ‚ d  S(   Ns    <title>([^- ]+ - )?Revision \d+:s   Unexpected HTML page found at (	   RÞ   Rq   RS   Rv   Rº   RP   Rø   R:  R   (   R~   R3   R¸   RQ   RÑ   R.  (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR?  D  s    

c         C   sv  t  j d t ƒ | j d d ƒ d } d } | j ƒ  j d ƒ rEd | k rEt j j | ƒ \ } } } } } }	 | rE| j d ƒ rEd	 | d
 k rE| d
 j d	 d ƒ \ } } t	 | ƒ \ }
 } |
 rBd |
 k r|
 j d d ƒ \ } } d | | f } n
 d |
 } | } | | | | | |	 f } t j j
 | ƒ } qBqEn  |  j d | | ƒ t j d | | | f ƒ | S(   Ns"   SVN download support is deprecatedR/   i   i    R­   s   svn:t   @s   //R-   i   t   :s    --username=%s --password=%ss    --username=s'   Doing subversion checkout from %s to %ss   svn checkout%s -q %s %s(   t   warningsRÊ   t   UserWarningR2   R%   R(   R   R    R0   t
   _splitusert
   urlunparseR¶   RP   t   system(   R~   R3   RQ   t   credsR5   t   netlocR7   RU   t   qRÇ   t   autht   hostt   usert   pwR4   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR:  S  s&    !$&
c         C   s¥   t  j j |  ƒ \ } } } } } | j d d ƒ d } | j d d ƒ d } d  } d | k rz | j d d ƒ \ } } n  t  j j | | | | d f ƒ }  |  | f S(   Nt   +i   iÿÿÿÿR/   i    R@  R­   (   R   R    t   urlsplitR2   R&   t   rsplitt
   urlunsplit(   R3   t
   pop_prefixR5   RH  R7   R9   Rî   t   rev(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   _vcs_split_rev_from_urli  s    !!c         C   s•   | j  d d ƒ d } |  j | d t ƒ\ } } |  j d | | ƒ t j d | | f ƒ | d  k	 r‘ |  j d | ƒ t j d | | f ƒ n  | S(	   NR/   i   i    RR  s   Doing git clone from %s to %ss   git clone --quiet %s %ss   Checking out %ss   git -C %s checkout --quiet %s(   R2   RT  R   R¶   RP   RF  R&   (   R~   R3   RQ   RS  (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR;  {  s    	c         C   s•   | j  d d ƒ d } |  j | d t ƒ\ } } |  j d | | ƒ t j d | | f ƒ | d  k	 r‘ |  j d | ƒ t j d | | f ƒ n  | S(	   NR/   i   i    RR  s   Doing hg clone from %s to %ss   hg clone --quiet %s %ss   Updating to %ss   hg --cwd %s up -C -r %s -q(   R2   RT  R   R¶   RP   RF  R&   (   R~   R3   RQ   RS  (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR<  ‹  s    	c         G   s   t  j | | Œ d  S(   N(   R   Rµ   (   R~   R–   Rf   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRµ   ›  s    c         G   s   t  j | | Œ d  S(   N(   R   R¶   (   R~   R–   Rf   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR¶   ž  s    c         G   s   t  j | | Œ d  S(   N(   R   RÊ   (   R~   R–   Rf   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRÊ   ¡  s    (   R™   N()   R†   R‡   Rˆ   R&   R   R   t   FalseRÁ   R²   R´   RÝ   RÙ   RÃ   Ré   Rï   Ró   Rö   Rû   Rþ   Rô   Rñ   R.   R  R  R  R  R%  R  R·   R   Rê   R>  R?  R:  t   staticmethodRT  R;  R<  Rµ   R¶   RÊ   (    (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   *  sL   3	
		+								
	#J	)	$	#									s!   &(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c         C   s   |  j  d ƒ } t | ƒ S(   Ni    (   R@   R   (   R?   t   what(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   decode_entityª  s    c         C   s   t  t |  ƒ S(   s  
    Decode HTML entities in the given text.

    >>> htmldecode(
    ...     'https://../package_name-0.1.2.tar.gz'
    ...     '?tokena=A&amp;tokenb=B">package_name-0.1.2.tar.gz')
    'https://../package_name-0.1.2.tar.gz?tokena=A&tokenb=B">package_name-0.1.2.tar.gz'
    (   t
   entity_subRX  (   t   text(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRt   ¯  s    	c            s   ‡  f d †  } | S(   Nc            s   ‡  ‡ f d †  } | S(   Nc             s?   t  j ƒ  } t  j ˆ ƒ z ˆ  |  | Ž  SWd  t  j | ƒ Xd  S(   N(   R0  t   getdefaulttimeoutt   setdefaulttimeout(   Rf   Rg   t   old_timeout(   Rh   t   timeout(    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   _socket_timeout½  s
    (    (   Rh   R_  (   R^  (   Rh   s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR_  ¼  s    (    (   R^  R_  (    (   R^  s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   socket_timeout»  s    c         C   sI   t  j j |  ƒ } | j ƒ  } t j | ƒ } | j ƒ  } | j d d ƒ S(   sq  
    A function compatible with Python 2.3-3.3 that will encode
    auth from a URL suitable for an HTTP header.
    >>> str(_encode_auth('username%3Apassword'))
    'dXNlcm5hbWU6cGFzc3dvcmQ='

    Long auth strings should not cause a newline to be inserted.
    >>> long_auth = 'username:' + 'password'*10
    >>> chr(10) in str(_encode_auth(long_auth))
    False
    s   
R­   (   R   R    R1   t   encodet   base64t	   b64encodeRÀ   R9  (   RJ  t   auth_st
   auth_bytest   encoded_bytest   encoded(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   _encode_authÊ  s
    t
   Credentialc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s:   
    A username/password pair. Use like a namedtuple.
    c         C   s   | |  _  | |  _ d  S(   N(   t   usernamet   password(   R~   Rj  Rk  (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   å  s    	c         c   s   |  j  V|  j Vd  S(   N(   Rj  Rk  (   R~   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   __iter__é  s    c         C   s   d t  |  ƒ S(   Ns   %(username)s:%(password)s(   t   vars(   R~   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   __str__í  s    (   R†   R‡   Rˆ   R   Rl  Rn  (    (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRi  à  s   		t
   PyPIConfigc           B   s2   e  Z d  „  Z e d „  ƒ Z d „  Z d „  Z RS(   c         C   su   t  j d d d g d ƒ } t j j |  | ƒ t j j t j j d ƒ d ƒ } t j j	 | ƒ rq |  j
 | ƒ n  d S(   s%   
        Load from ~/.pypirc
        Rj  Rk  t
   repositoryR­   t   ~s   .pypircN(   t   dictt   fromkeysR   t   RawConfigParserR   RP   R7   RY   t
   expanduserRÉ   R»   (   R~   t   defaultst   rc(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR   ò  s
    !c         C   sM   g  |  j  ƒ  D]$ } |  j | d ƒ j ƒ  r | ^ q } t t |  j | ƒ ƒ S(   NRp  (   t   sectionsR¹   Rq   Rr  R   t   _get_repo_cred(   R~   t   sectiont   sections_with_repositories(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   creds_by_repositoryý  s    $c         C   sO   |  j  | d ƒ j ƒ  } | t |  j  | d ƒ j ƒ  |  j  | d ƒ j ƒ  ƒ f S(   NRp  Rj  Rk  (   R¹   Rq   Ri  (   R~   Rz  t   repo(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRy    s    c         C   s7   x0 |  j  j ƒ  D] \ } } | j | ƒ r | Sq Wd S(   sŒ   
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N(   R|  t   itemsR(   (   R~   R3   Rp  t   cred(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   find_credential  s    (   R†   R‡   R   t   propertyR|  Ry  R€  (    (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRo  ñ  s   			c         C   sÐ  t  j j |  ƒ } | \ } } } } } } | j d ƒ rK t j d ƒ ‚ n  | d	 k rl t | ƒ \ }	 }
 n d
 }	 |	 sÁ t ƒ  j	 |  ƒ } | rÁ t
 | ƒ }	 | j |  f } t j d | Œ qÁ n  |	 r&d t |	 ƒ }	 | |
 | | | | f } t  j j | ƒ } t  j j | ƒ } | j d |	 ƒ n t  j j |  ƒ } | j d t ƒ | | ƒ } |	 rÌt  j j | j ƒ \ } } } } } } | | k rÌ| |
 k rÌ| | | | | | f } t  j j | ƒ | _ qÌn  | S(   s4   Open a urllib2 request, handling HTTP authenticationRA  s   nonnumeric port: ''t   httpt   httpss*   Authenticating as %s for %s (from .pypirc)s   Basic t   Authorizations
   User-Agent(   R‚  Rƒ  N(   R   R    R0   R'   R   R*  RD  R&   Ro  R€  Rp   Rj  R   R¶   Rh  RE  R¥   t   Requestt
   add_headert
   user_agentR3   (   R3   R¤   t   parsedR5   RH  R7   t   paramsR9   Rî   RJ  t   addressR  R¶   R4   Rí   R¥   R   t   s2t   h2t   path2t   param2t   query2t   frag2(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR)    s8    'c         C   s.   |  j  d ƒ \ } } }  | r$ | n d |  f S(   sJ   splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.R@  N(   t
   rpartitionR&   (   RK  RL  t   delim(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyRD  F  s    c         C   s   |  S(   N(    (   R3   (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt
   fix_sf_urlP  s    c         C   s—  t  j j |  ƒ \ } } } } } } t  j j | ƒ } t j j | ƒ rX t  j j |  ƒ S| j	 d ƒ rPt j j
 | ƒ rPg  } x¿ t j | ƒ D]‡ }	 t j j | |	 ƒ }
 |	 d k rÞ t |
 d ƒ  } | j ƒ  } Wd QXPn t j j
 |
 ƒ rý |	 d 7}	 n  | j d j d |	 ƒ ƒ q Wd } | j d |  d	 d
 j | ƒ ƒ } d \ } } n d \ } } } i d d 6} t j | ƒ } t  j j |  | | | | ƒ S(   s7   Read a local path, with special support for directoriesR-   s
   index.htmlt   rNs   <a href="{name}">{name}</a>R)   sB   <html><head><title>{url}</title></head><body>{files}</body></html>R3   t   filess   
iÈ   t   OKi”  s   Path not founds	   Not founds	   text/htmls   content-type(   iÈ   R–  (   i”  s   Path not founds	   Not found(   R   R    R0   R¥   R=  RP   R7   t   isfileR¦   R'   RË   RÍ   RY   RÞ   R»   Rü   t   formatR   t   StringIOR½   R¾   (   R3   R5   R6   R7   t   paramR9   Rî   RQ   R•  RÇ   t   filepathR   t   bodyRÆ   t   statust   messageR¸   t   body_stream(    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyR(  T  s,    $!!(^   Rˆ   t   sysRP   RS   R  R0  Rb  R‹   R×   RB  t	   functoolsR    t   setuptools.externR   t   setuptools.extern.six.movesR   R   R   R   R   t   pkg_resourcesR   R   R   R	   R
   R   R   R   R   R   R   R   R   R   t	   distutilsR   t   distutils.errorsR   t   fnmatchR   t   setuptools.py27compatR   t   setuptools.py33compatR   t   setuptools.wheelR   t   typet   __metaclass__R—   R>   t   IRr   Rë   R?   R±   R2   RI   t   __all__t   _SOCKET_TIMEOUTt   _tmplR˜  t   version_infoR‡  R#   R   R;   R&   R   R=   RR   R   Re   Rj   Rm   R|   R}   R‰   R   Rì   RY  RX  Rt   R`  Rh  Ri  Rt  Ro  R¥   R¦   R)  RD  R“  R(  (    (    (    s<   /tmp/pip-build-UPPWic/setuptools/setuptools/package_index.pyt   <module>   s|   "X			$				!"	!ÿ ÿ 			&/		