î
½1kd˜  ã               @   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 m	 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 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, m- Z- d d	 l m. Z. d d
 l/ m0 Z0 d d l1 m2 Z2 d d l3 m4 Z4 e j5 d ƒ Z6 e j5 d e j7 ƒ Z8 e j5 d ƒ Z9 e j5 d e j7 ƒ j: Z; d j< ƒ  Z= d d d d g Z> d Z? d d „  Z@ d d „  ZA d d d „ ZB d d d „ ZC d d d „ ZD d e d d d „ ZE d d  d! „ ZF d" d# „  ZG e j5 d$ e j7 ƒ ZH eG d% d& „  ƒ ZI d' e jJ d d( … e d) ƒ d jJ f ZK Gd* d+ „  d+ eL ƒ ZM Gd, d- „  d- eM ƒ ZN Gd. d „  d e ƒ ZO e j5 d/ ƒ jP ZQ d0 d1 „  ZR d2 d3 „  ZS d4 d5 „  ZT d d6 d7 „ ZU d8 d9 „  ZV Gd: d; „  d; eL ƒ ZW Gd< d= „  d= e- j- ƒ ZX e jY d> d? „ ZZ eU e? ƒ eZ ƒ ZZ d@ dA „  Z[ dB dC „  Z\ d S)Dz#PyPI and direct package downloadingé    N)Úwraps)ÚCHECKOUT_DISTÚDistributionÚBINARY_DISTÚnormalize_pathÚSOURCE_DISTÚrequireÚEnvironmentÚfind_distributionsÚ	safe_nameÚsafe_versionÚto_filenameÚRequirementÚDEVELOP_DIST)Ússl_support)Úlog)ÚDistutilsError)Úurllib2ÚhttplibÚStringIOÚ	HTTPErrorÚurlparseÚ
urlunparseÚunquoteÚ	splituserÚurl2pathnameÚname2codepointÚunichrÚurljoinÚurlsplitÚ
urlunsplitÚConfigParser)Úfilterfalse)Ú	translate)Ústrip_fragment)Úget_all_headersz^egg=([-A-Za-z0-9_.]+)$zhref\s*=\s*['"]?([^'"> ]+)z�<a href="([^"#]+)">([^<]+)</a>
\s+\(<a (?:title="MD5 hash"
\s+)href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\)z([-+.a-z0-9]{2,}):z.tar.gz .tar.bz2 .tar .zip .tgzÚPackageIndexÚdistros_for_urlÚparse_bdist_wininstÚinterpret_distro_nameé   c             C   s   |  j  ƒ  } d \ } } } | j d ƒ ró | j d ƒ rR |  d d … } d } qó | j d d ƒ r� |  d d … } |  d d … } d } qó | j d
 ƒ rµ |  d d … } d } qó | j d d ƒ ró |  d d … } |  d d … } d } qó n  | | | f S)z=Return (base,pyversion) or (None,None) for possible .exe nameNz.exez
.win32.exeé
   Úwin32z	.win32-pyé   é   é   z.win-amd64.exeé   z	win-amd64z.win-amd64-pyé   )NNNiöÿÿÿiðÿÿÿiùÿÿÿéüÿÿÿiðÿÿÿiòÿÿÿiìÿÿÿiùÿÿÿr2   iìÿÿÿ)ÚlowerÚendswithÚ
startswith)Únamer3   ÚbaseÚpy_verÚplat© r:   úN/var/www/pythonscrapper/code/venv/build/setuptools/setuptools/package_index.pyr(   .   s$    			c             C   sœ   t  |  ƒ \ } } } } } } t | j d ƒ d ƒ } | d k rk | d k rk t | j d ƒ d ƒ } n  d | k r’ | j d d ƒ \ } } n  | | f S)	Nú/é   zsourceforge.netÚdownloadé   ú#éÿÿÿÿéþÿÿÿ)r   r   Úsplit)ÚurlÚschemeÚserverÚpathÚ
parametersÚqueryÚfragmentr7   r:   r:   r;   Úegg_info_for_urlF   s     rK   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)zEYield egg or source distribution objects that might be found at a URLr=   Ú
precedenceN)rK   Údistros_for_locationÚEGG_FRAGMENTÚmatchr)   Úgroupr   )rD   Úmetadatar7   rJ   ÚdistrO   r:   r:   r;   r'   N   s     	"c             C   sê   | j  d ƒ r" | d d … } n  | j  d ƒ rS d | k rS t j |  | | ƒ g S| j  d ƒ rŸ t | ƒ \ } } } | d k	 rŸ t |  | | | t | ƒ Sn  xD t D]< } | j  | ƒ r¦ | d t | ƒ … } t |  | | ƒ Sq¦ Wg  S)z:Yield egg or source distribution objects based on basenamez.egg.zipNr/   z.eggú-z.exer2   )r4   r   Úfrom_locationr(   r)   r   Ú
EXTENSIONSÚlen)ÚlocationÚbasenamerQ   Zwin_baser8   ÚplatformÚextr:   r:   r;   rM   Z   s    rM   c             C   s"   t  t |  ƒ t j j |  ƒ | ƒ S)zEYield possible egg or source distribution objects based on a filename)rM   r   ÚosrG   rX   )ÚfilenamerQ   r:   r:   r;   Údistros_for_filenameo   s    r]   c       	      c   sØ   | j  d ƒ } | sd xL t | d d … ƒ D]1 \ } } t | ƒ d k r, | j d ƒ r, d Sq, Wn  xm t d t | ƒ d ƒ D]R } t |  | d j | d | … ƒ d j | | d … ƒ d | d | d	 | ƒVq~ Wd S)
zØ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!
    rS   r?   Né   zpy2.r=   Ú
py_versionrL   rY   )rC   Ú	enumeraterV   r5   Úranger   Újoin)	rW   rX   rQ   r_   rL   rY   ÚpartsÚiÚpr:   r:   r;   r)   v   s    #! 5c             c   sŒ   t  ƒ  } | j } | d k rM xg t | j |  ƒ D] } | | ƒ | Vq1 Wn; x8 |  D]0 } | | ƒ } | | k rT | | ƒ | VqT qT Wd S)zHList unique elements, preserving order. Remember all elements ever seen.N)ÚsetÚaddr"   Ú__contains__)ÚiterableÚkeyÚseenZseen_addÚelementÚkr:   r:   r;   Úunique_everseenš   s    		

rn   c                s"   t  ˆ  ƒ ‡  f d d †  ƒ } | S)zs
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    c                 s   t  ˆ  |  | Ž  ƒ S)N)rn   )ÚargsÚkwargs)Úfuncr:   r;   Úwrapper°   s    zunique_values.<locals>.wrapper)r   )rq   rr   r:   )rq   r;   Úunique_values«   s    rs   z(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>c             c   s  x¢ t  j | ƒ D]‘ } | j ƒ  \ } } t t t j | j ƒ  j d ƒ ƒ ƒ } d | k sg d | k r x7 t	 j | ƒ D]# } t
 |  t | j d ƒ ƒ ƒ Vqw Wq q Wxd d D]\ } | j | ƒ } | d	 k r¬ t	 j | | ƒ } | rt
 |  t | j d ƒ ƒ ƒ Vqq¬ q¬ Wd S)
zEFind rel="homepage" and rel="download" links in `page`, yielding URLsú,Úhomepager>   r=   ú<th>Home Pageú<th>Download URLN)rv   rw   rA   )ÚRELÚfinditerÚgroupsrf   ÚmapÚstrÚstripr3   rC   ÚHREFr   Ú
htmldecoderP   ÚfindÚsearch)rD   ÚpagerO   ÚtagÚrelÚrelsÚposr:   r:   r;   Úfind_external_links¸   s    '(r‡   zPython-urllib/%s setuptools/%sé   Ú
setuptoolsc               @   s:   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d S)	ÚContentCheckerzP
    A null content checker that defines the interface for checking content
    c             C   s   d S)z3
        Feed a block of data to the hash.
        Nr:   )ÚselfÚblockr:   r:   r;   ÚfeedÒ   s    zContentChecker.feedc             C   s   d S)zC
        Check the hash. Return False if validation fails.
        Tr:   )r‹   r:   r:   r;   Úis_validØ   s    zContentChecker.is_validc             C   s   d S)zu
        Call reporter with information about the checker (hash name)
        substituted into the template.
        Nr:   )r‹   ÚreporterÚtemplater:   r:   r;   ÚreportÞ   s    zContentChecker.reportN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r�   rŽ   r‘   r:   r:   r:   r;   rŠ   Î   s   rŠ   c               @   sa   e  Z d  Z e j d ƒ Z d d „  Z e d d „  ƒ Z d d „  Z	 d d	 „  Z
 d
 d „  Z d S)ÚHashCheckerzK(?P<hash_name>sha1|sha224|sha384|sha256|sha512|md5)=(?P<expected>[a-f0-9]+)c             C   s(   | |  _  t j | ƒ |  _ | |  _ d  S)N)Ú	hash_nameÚhashlibÚnewÚhashÚexpected)r‹   r—   r›   r:   r:   r;   Ú__init__ë   s    	zHashChecker.__init__c             C   sL   t  | ƒ d } | s t ƒ  S|  j j | ƒ } | s< t ƒ  S|  | j ƒ  �  S)z5Construct a (possibly null) ContentChecker from a URLr=   rA   )r   rŠ   Úpatternr�   Ú	groupdict)ÚclsrD   rJ   rO   r:   r:   r;   Úfrom_urlð   s    zHashChecker.from_urlc             C   s   |  j  j | ƒ d  S)N)rš   Úupdate)r‹   rŒ   r:   r:   r;   r�   û   s    zHashChecker.feedc             C   s   |  j  j ƒ  |  j k S)N)rš   Ú	hexdigestr›   )r‹   r:   r:   r;   rŽ   þ   s    zHashChecker.is_validc             C   s   | |  j  } | | ƒ S)N)r—   )r‹   r�   r�   Úmsgr:   r:   r;   r‘     s    zHashChecker.reportN)r’   r“   r”   ÚreÚcompiler�   rœ   Úclassmethodr    r�   rŽ   r‘   r:   r:   r:   r;   r–   å   s   	r–   c                   sç  e  Z d  Z d Z d dJ d d d d „ Z d d	 d
 „ Z d d d „ Z d d d „ Z d d „  Z d d „  Z	 d d „  Z
 d d „  Z d d d „ Z d d „  Z d ‡  f d d † Z d d „  Z d d  „  Z d! d" „  Z d# d$ „  Z d% d& „  Z d d d d d' d( „ Z d d d) d* „ Z d+ d, „  Z d- Z d. d/ „  Z d0 d1 „  Z d d2 d3 „ Z d4 d5 „  Z d6 d7 „  Z d8 d9 „  Z d: d; „  Z d< d= „  Z e  d d> d? „ ƒ Z! d@ dA „  Z" dB dC „  Z# dD dE „  Z$ dF dG „  Z% dH dI „  Z& ‡  S)Kr&   z;A distribution index that scans web pages for download URLszhttps://pypi.python.org/simpleÚ*NTc             O   sÅ   t  j |  | | Ž | d d  | j d ƒ … |  _ i  |  _ i  |  _ i  |  _ t j d j	 t
 t | ƒ ƒ ƒ j |  _ g  |  _ | rµ t j rµ | s  t j ƒ  rµ t j | ƒ |  _ n t j |  _ d  S)Nr<   ú|)r	   rœ   r4   Ú	index_urlÚscanned_urlsÚfetched_urlsÚpackage_pagesr¤   r¥   rb   r{   r#   rO   ÚallowsÚto_scanr   Zis_availableZfind_ca_bundleZ
opener_forÚopenerr   Úurlopen)r‹   r©   ZhostsZ	ca_bundleZ
verify_sslro   Úkwr:   r:   r;   rœ   	  s    !			'	!zPackageIndex.__init__Fc       
      C   sU  | |  j  k r | r d Sd |  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Ø d |  j | <d S|  j
 d | ƒ d |  j | <|  j | d | ƒ } | d k rd Sd |  j | j <d | j j d d ƒ j ƒ  k rZ| j ƒ  d S| j } | j ƒ  } t | t ƒ sÃt | t ƒ r–d	 } n | j j d
 ƒ p«d	 } | j | d ƒ } n  | j ƒ  xB t j | ƒ D]1 } t | t | j d ƒ ƒ ƒ }	 |  j |	 ƒ qÝW| j |  j ƒ rQt | d d ƒ d k rQ|  j  | | ƒ } n  d S)z<Evaluate a URL as a possible download, and maybe retrieve itNTzFound link: %sz
Reading %sz<Download error on %s: %%s -- Some packages may not be found!Úhtmlzcontent-typeÚ zlatin-1ÚcharsetÚignorer=   Úcodei”  )!rª   Ú
URL_SCHEMEÚprocess_filenameÚlistr'   Úurl_okÚdebugr«   r{   rg   ÚinfoÚopen_urlrD   ÚheadersÚgetr3   ÚcloseÚreadÚ
isinstancer|   r   Ú	get_paramÚdecoder~   ry   r   r   rP   Úprocess_urlr5   r©   ÚgetattrÚprocess_index)
r‹   rD   ÚretrieveÚdistsÚfr7   r‚   r´   rO   Úlinkr:   r:   r;   rÅ     sN     !
		
*zPackageIndex.process_urlc             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 | | ƒ d ƒ qa Wn  t	 | ƒ } | rÈ |  j
 d | ƒ t t |  j | ƒ ƒ n  d  S)NzNot found: %sTz	Found: %s)r[   rG   ÚexistsÚwarnÚisdirÚrealpathÚlistdirr¸   rb   r]   r»   r¹   r{   rg   )r‹   ÚfnÚnestedrG   ÚitemrÉ   r:   r:   r;   r¸   H  s    &zPackageIndex.process_filenamec             C   s}   t  | ƒ } | r- | j d ƒ j ƒ  d k sF |  j t | ƒ d ƒ rJ d Sd } | ri t | | ƒ ‚ n |  j | | ƒ d  S)Nr=   ÚfileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/1dg9ijs for details).
)r·   rP   r3   r­   r   r   rÍ   )r‹   rD   ÚfatalÚsr£   r:   r:   r;   rº   X  s    :zPackageIndex.url_okc             C   sf   x_ | D]W } t  j j | ƒ r x< t  j | ƒ D]( } | j d ƒ r/ |  j | | ƒ q/ q/ Wq q Wd  S)Nz	.egg-link)r[   rG   rÎ   rÐ   r4   Úscan_egg_link)r‹   Úsearch_pathrÓ   Úentryr:   r:   r;   Úscan_egg_linksc  s
    zPackageIndex.scan_egg_linksc             C   s¥   d d „  t  t j t t j j | | ƒ ƒ ƒ Dƒ } t | ƒ d k r¡ xX t t j j | | d ƒ ƒ D]4 } t j j | | Œ | _	 t
 | _ |  j | ƒ qf Wn  d  S)Nc             S   s   g  |  ] } | r | ‘ q Sr:   r:   )Ú.0Z_fr:   r:   r;   ú
<listcomp>k  s   	 z.PackageIndex.scan_egg_link.<locals>.<listcomp>r?   r   )r{   r|   r}   Úopenr[   rG   rb   rV   r
   rW   r   rL   rg   )r‹   rG   rÙ   ÚlinesrR   r:   r:   r;   r×   j  s    "&	zPackageIndex.scan_egg_linkc       
         s  ‡  f d d †  } xR t  j | ƒ D]A } y& | t | t | j d ƒ ƒ ƒ ƒ Wq" t k
 rb Yq" Xq" W| | ƒ \ } } | rxy t | | ƒ D]h } t | ƒ \ } }	 | j d ƒ rê |	 rê | rÚ | d | | f 7} qê ˆ  j	 | ƒ n  ˆ  j
 | ƒ q� Wt j d d „  | ƒ Sd Sd	 S)
z#Process the contents of a PyPI pagec                sÁ   |  j  ˆ  j ƒ r½ t t t |  t ˆ  j ƒ d  … j d ƒ ƒ ƒ } t | ƒ d k r½ d | d k r½ t | d ƒ } t | d ƒ } d ˆ  j	 j
 | j ƒ  i  ƒ |  <t | ƒ t | ƒ f Sn  d S)Nr<   r?   r@   r=   r   T)NN)r5   r©   r¹   r{   r   rV   rC   r   r   r¬   Ú
setdefaultr3   r   )rË   rc   ÚpkgÚver)r‹   r:   r;   Úscanu  s    +"z(PackageIndex.process_index.<locals>.scanr=   z.pyz
#egg=%s-%sc             S   s   d |  j  d d d ƒ S)Nz<a href="%s#md5=%s">%s</a>r=   rˆ   r?   )rP   )Úmr:   r:   r;   Ú<lambda>˜  s    z,PackageIndex.process_index.<locals>.<lambda>r³   N)r~   ry   r   r   rP   Ú
ValueErrorr‡   rK   r4   Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)
r‹   rD   r‚   râ   rO   rà   rá   Únew_urlr7   Úfragr:   )r‹   r;   rÇ   s  s$    &	zPackageIndex.process_indexc             C   s   |  j  d | ƒ d  S)NzPPage at %s links to .py file(s) without version info; an index scan is required.)Úscan_all)r‹   rD   r:   r:   r;   ræ   �  s    zPackageIndex.need_version_infoc             G   sO   |  j  |  j k r; | r+ |  j | | Œ n  |  j d ƒ n  |  j |  j  ƒ d  S)Nz6Scanning index of all packages (this may take a while))r©   r«   rÍ   r¼   rç   )r‹   r£   ro   r:   r:   r;   rì   £  s     
zPackageIndex.scan_allc             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 f  ƒ ƒ D] } |  j  | ƒ q’ Wd  S)Nr<   )	rç   r©   Úunsafe_namer¬   r¿   rj   Úproject_nameÚnot_found_in_indexr¹   )r‹   ÚrequirementrD   r:   r:   r;   Úfind_packages«  s    %zPackageIndex.find_packagesc                sk   |  j  ƒ  |  j | ƒ x8 |  | j D]) } | | k r; | S|  j d | | ƒ q% Wt t |  ƒ j | | ƒ S)Nz%s does not match %s)Úprescanrñ   rj   r»   Úsuperr&   Úobtain)r‹   rð   Ú	installerrR   )Ú	__class__r:   r;   rô   º  s    
zPackageIndex.obtainc             C   si   | j  |  j d | ƒ | j ƒ  se | j ƒ  t j | ƒ t d | j j t j	 j
 | ƒ f ƒ ‚ n  d S)z-
        checker is a ContentChecker
        zValidating %%s checksum for %sz7%s validation failed for %s; possible download problem?N)r‘   r»   rŽ   rÀ   r[   Úunlinkr   rš   r6   rG   rX   )r‹   Úcheckerr\   Útfpr:   r:   r;   Ú
check_hashÃ  s    
zPackageIndex.check_hashc             C   sr   xk | D]c } |  j  d k sJ t | ƒ sJ | j d ƒ sJ t t | ƒ ƒ rZ |  j | ƒ q |  j  j | ƒ q Wd S)z;Add `urls` to the list that will be prescanned for searchesNzfile:)r®   r·   r5   r¹   r'   rç   Úappend)r‹   ÚurlsrD   r:   r:   r;   Úadd_find_linksÒ  s    zPackageIndex.add_find_linksc             C   s2   |  j  r% t t |  j |  j  ƒ ƒ n  d |  _  d S)z7Scan urls scheduled for prescanning (e.g. --find-links)N)r®   r¹   r{   rç   )r‹   r:   r:   r;   rò   á  s    	zPackageIndex.prescanc             C   sN   |  | j  r  |  j d } } n |  j d } } | | | j ƒ |  j ƒ  d  S)Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))rj   r¼   rÍ   rí   rì   )r‹   rð   Úmethr£   r:   r:   r;   rï   ç  s    
zPackageIndex.not_found_in_indexc             C   sì   t  | t ƒ sÐ t | ƒ } | r| |  j | j d ƒ | | ƒ } t | ƒ \ } } | j d ƒ rx |  j | | | ƒ } n  | St j	 j
 | ƒ r’ | Sy t j | ƒ } WqÐ t k
 rÌ t d | f ƒ ‚ YqÐ Xn  t |  j | | ƒ d d ƒ S)a  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.
        r=   z.pyz1Not a URL, existing file, or requirement spec: %rrW   N)rÂ   r   r·   Ú_download_urlrP   rK   r4   Ú	gen_setupr[   rG   rÌ   Úparserå   r   rÆ   Úfetch_distribution)r‹   ÚspecÚtmpdirrE   Úfoundr7   rJ   r:   r:   r;   r>   ð  s"    zPackageIndex.downloadc       	         sQ  ˆ j  d | ƒ i  ‰ d } d ‡  ‡ ‡ ‡ f d d † } | rf ˆ j ƒ  ˆ j | ƒ | | ƒ } n  | d k	 rŠ | p„ | | | ƒ } 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 | j | ƒ ƒ Sd S)
a|  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.
        zSearching for %sNc                sœ   | d  k r ˆ } n  x€ | |  j  D]q } | j t k rn ˆ  rn | ˆ k r# ˆ j d | ƒ d ˆ | <q# q# n  | |  k r# | j t k s� ˆ r# | Sq# Wd  S)Nz&Skipping development or system egg: %sr=   )rj   rL   r   rÍ   r   )ÚreqÚenvrR   )Ú
develop_okr‹   ÚskippedÚsourcer:   r;   r€   1  s    	"z-PackageIndex.fetch_distribution.<locals>.findz2No local packages or download links found for %s%sza source distribution of r³   zBest match: %srW   )r¼   rò   rñ   r®   rÍ   Úcloner>   rW   )	r‹   rð   r  Ú
force_scanr
  r  Zlocal_indexrR   r€   r:   )r  r‹   r	  r
  r;   r    s0    

zPackageIndex.fetch_distributionc             C   s/   |  j  | | | | ƒ } | d k	 r+ | j Sd S)a3  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  rW   )r‹   rð   r  r  r
  rR   r:   r:   r;   Úfetch\  s    zPackageIndex.fetchc       
      C   sb  t  j | ƒ } | r= d d „  t | | j d ƒ d  ƒ Dƒ p@ g  } t | ƒ d k r3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 ƒ |	 j ƒ  | S| rRt d	 | | f ƒ ‚ n t d
 ƒ ‚ d  S)Nc             S   s   g  |  ] } | j  r | ‘ q Sr:   )Úversion)rÛ   Údr:   r:   r;   rÜ   l  s   	 z*PackageIndex.gen_setup.<locals>.<listcomp>r=   r   )Úsamefilezsetup.pyÚwzIfrom setuptools import setup
setup(name=%r, version=%r, py_modules=[%r])
z†Can't unambiguously interpret project/version identifier %r; any dashes in the name or version should be escaped using underscores. %rzpCan't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.)rN   rO   r)   rP   rV   r[   rG   rX   Údirnamerb   Zsetuptools.command.easy_installr  ÚshutilÚcopy2rÝ   Úwriterî   r  ÚsplitextrÀ   r   )
r‹   r\   rJ   r  rO   rÉ   rX   Údstr  rÔ   r:   r:   r;   r   i  s4    	
zPackageIndex.gen_setupi    c             C   s–  |  j  d | ƒ d \ } } } zIt j | ƒ } |  j t | ƒ ƒ } t | t ƒ rw t d | | j | j	 f ƒ ‚ n  | j  ƒ  } d } |  j
 }	 d	 }
 d | k rä t | d ƒ } t t t | ƒ ƒ }
 |  j | | | |	 |
 ƒ n  t | d ƒ } xZ | j |	 ƒ } | rK| j | ƒ | j | ƒ | d 7} |  j | | | |	 |
 ƒ qö Pqö W|  j | | | ƒ | SWd  | r~| j ƒ  n  | r‘| j ƒ  n  Xd  S)
NzDownloading %szCan't download %s: %s %sr   r=   zcontent-lengthzContent-LengthÚwb)NNNrA   )r¼   r–   r    r½   r$   rÂ   r   r   r¶   r£   Údl_blocksizer%   Úmaxr{   ÚintÚ
reporthookrÝ   rÁ   r�   r  rú   rÀ   )r‹   rD   r\   Úfprù   r¼   rø   r¾   ÚblocknumÚbsÚsizeZsizesrŒ   r:   r:   r;   Ú_download_to”  s>    	
  zPackageIndex._download_toc             C   s   d  S)Nr:   )r‹   rD   r\   r  Zblksizer   r:   r:   r;   r  ¸  s    zPackageIndex.reporthookc             C   sÚ  | j  d ƒ r t | ƒ Sy t | |  j ƒ SWn¦t t j f k
 r¨ t j ƒ  d } d j	 d d „  | j
 Dƒ ƒ } | rŽ |  j | | ƒ n t d | | f ƒ ‚ Yn.t j k
 rÐ t j ƒ  d } | SYnt j k
 r)t j ƒ  d } | r|  j | | j ƒ n t d | | j f ƒ ‚ Yn­ t j k
 r‚t j ƒ  d } | re|  j | | j ƒ n t d | | j f ƒ ‚ YnT t j k
 rÕt j ƒ  d } | r»|  j | | ƒ n t d | | f ƒ ‚ Yn Xd  S)	Nzfile:r=   ú c             S   s   g  |  ] } t  | ƒ ‘ q Sr:   )r|   )rÛ   Úargr:   r:   r;   rÜ   Â  s   	 z)PackageIndex.open_url.<locals>.<listcomp>z%s %szDownload error for %s: %sz;%s returned a bad status line. The server might be down, %s)r5   Ú
local_openÚopen_with_authr¯   rå   r   Ú
InvalidURLÚsysÚexc_inforb   ro   rÍ   r   r   r   ÚURLErrorÚreasonÚBadStatusLineÚlineÚHTTPException)r‹   rD   ÚwarningÚvr£   r:   r:   r;   r½   »  s@    
zPackageIndex.open_urlc             C   sB  t  | ƒ \ } } | rL x7 d | k rH | j d d ƒ j d d ƒ } q Wn d } | j d ƒ rt | d  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
 t | ƒ d ƒ S|  j | d ƒ |  j | | ƒ Sd  S)Nz..Ú.ú\Ú_Z__downloaded__z.egg.zipr/   Úsvnzsvn+Úgitzgit+zhg+rÔ   r?   Tr2   )rK   Úreplacer4   r[   rG   rb   r5   Ú_download_svnÚ_download_gitÚ_download_hgr   r   rº   Ú_attempt_download)r‹   rE   rD   r  r6   rJ   r\   r:   r:   r;   rÿ   ã  s$    %zPackageIndex._download_urlc             C   s   |  j  | d ƒ d  S)NT)rÅ   )r‹   rD   r:   r:   r;   rç      s    zPackageIndex.scan_urlc             C   sK   |  j  | | ƒ } d | j d d ƒ j ƒ  k rC |  j | | | ƒ S| Sd  S)Nr²   zcontent-typer³   )r!  r¿   r3   Ú_download_html)r‹   rD   r\   r¾   r:   r:   r;   r9    s    zPackageIndex._attempt_downloadc             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)Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	rÝ   r}   r¤   r�   rÀ   r[   r÷   r6  r   )r‹   rD   r¾   r\   rÔ   r,  r:   r:   r;   r:  
  s    

zPackageIndex._download_htmlc             C   s`  | j  d d ƒ d } d } | j ƒ  j d ƒ r/d | k r/t | ƒ \ } } } } } }	 | r/| j d ƒ r/d | d	 d  … k r/| d	 d  … j  d d ƒ \ } } t | ƒ \ }
 } |
 r,d
 |
 k rø |
 j  d
 d ƒ \ } } d | | f } n
 d |
 } | } t | | | | | |	 f ƒ } q,q/n  |  j d | | ƒ t j d | | | f ƒ | S)Nr@   r=   r   r³   zsvn:ú@z//r<   r?   ú:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s)	rC   r3   r5   r   r   r   r¼   r[   Úsystem)r‹   rD   r\   ÚcredsrE   ÚnetlocrG   re   ÚqrÊ   ÚauthÚhostÚuserÚpwr:   r:   r;   r6    s"    !,"
'zPackageIndex._download_svnc             C   s™   t  |  ƒ \ } } } } } | j d d ƒ d } | j d d ƒ d } d  } d | k rt | j d d ƒ \ } } n  t | | | | d f ƒ }  |  | f S)Nú+r=   r@   r   r;  r³   rA   )r   rC   Úrsplitr    )rD   Ú
pop_prefixrE   r?  rG   rI   rë   Úrevr:   r:   r;   Ú_vcs_split_rev_from_url-  s    z$PackageIndex._vcs_split_rev_from_urlc             C   s•   | j  d d ƒ d } |  j | d d ƒ\ } } |  j d | | ƒ t j d | | f ƒ | d  k	 r‘ |  j d | ƒ t j d	 | | f ƒ n  | S)
Nr@   r=   r   rG  TzDoing git clone from %s to %szgit clone --quiet %s %szChecking out %sz"(cd %s && git checkout --quiet %s))rC   rI  r¼   r[   r=  )r‹   rD   r\   rH  r:   r:   r;   r7  ?  s    	zPackageIndex._download_gitc             C   s•   | j  d d ƒ d } |  j | d d ƒ\ } } |  j d | | ƒ t j d | | f ƒ | d  k	 r‘ |  j d | ƒ t j d	 | | f ƒ n  | S)
Nr@   r=   r   rG  TzDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %sz(cd %s && hg up -C -r %s >&-))rC   rI  r¼   r[   r=  )r‹   rD   r\   rH  r:   r:   r;   r8  O  s    	zPackageIndex._download_hgc             G   s   t  j | | Œ d  S)N)r   r»   )r‹   r£   ro   r:   r:   r;   r»   _  s    zPackageIndex.debugc             G   s   t  j | | Œ d  S)N)r   r¼   )r‹   r£   ro   r:   r:   r;   r¼   b  s    zPackageIndex.infoc             G   s   t  j | | Œ d  S)N)r   rÍ   )r‹   r£   ro   r:   r:   r;   rÍ   e  s    zPackageIndex.warn)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!  r  r½   rÿ   rç   r9  r:  r6  ÚstaticmethodrI  r7  r8  r»   r¼   rÍ   r:   r:   )rö   r;   r&     sL   0	*		)B*$(z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c             C   s3   t  |  t ƒ s |  S|  d k r) t |  ƒ St |  ƒ S)Néÿ   )rÂ   r  r   Úchr)Úcr:   r:   r;   Úuchrl  s
     
rN  c             C   s‡   |  j  d ƒ } | j d ƒ r: t | d d  … d ƒ } nC | j d ƒ rb t | d d  … ƒ } n t j | |  j  d ƒ ƒ } t | ƒ S)Nr=   z#xr?   r-   r@   r   )rP   r5   r  r   r¿   rN  )rO   Úwhatr:   r:   r;   Údecode_entityr  s    rP  c             C   s   t  t |  ƒ S)z'Decode HTML entities in the given text.)Ú
entity_subrP  )Útextr:   r:   r;   r   |  s    r   c                s   ‡  f d d †  } | S)Nc                s   ‡  ‡ f d d †  } | S)Nc                 s?   t  j ƒ  } t  j ˆ ƒ z ˆ  |  | Ž  SWd  t  j | ƒ Xd  S)N)ÚsocketÚgetdefaulttimeoutÚsetdefaulttimeout)ro   rp   Zold_timeout)rq   Útimeoutr:   r;   Ú_socket_timeout‚  s
    z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr:   )rq   rW  )rV  )rq   r;   rW  �  s    z'socket_timeout.<locals>._socket_timeoutr:   )rV  rW  r:   )rV  r;   Úsocket_timeout€  s    	rX  c             C   sC   t  |  ƒ } | j ƒ  } t j | ƒ } | j ƒ  } | j d d ƒ S)aq  
    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
    Ú
r³   )r   ÚencodeÚbase64ÚencodestringrÄ   r5  )rA  Zauth_sZ
auth_bytesZencoded_bytesÚencodedr:   r:   r;   Ú_encode_authŒ  s
    r^  c               @   s:   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d S)	Ú
Credentialz:
    A username/password pair. Use like a namedtuple.
    c             C   s   | |  _  | |  _ d  S)N)ÚusernameÚpassword)r‹   r`  ra  r:   r:   r;   rœ   ¦  s    	zCredential.__init__c             c   s   |  j  V|  j Vd  S)N)r`  ra  )r‹   r:   r:   r;   Ú__iter__ª  s    zCredential.__iter__c             C   s   d t  |  ƒ S)Nz%(username)s:%(password)s)Úvars)r‹   r:   r:   r;   Ú__str__®  s    zCredential.__str__N)r’   r“   r”   r•   rœ   rb  rd  r:   r:   r:   r;   r_  ¢  s   r_  c               @   sF   e  Z d  Z d d „  Z e d d „  ƒ Z d d „  Z d d „  Z d	 S)
Ú
PyPIConfigc             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)z%
        Load from ~/.pypirc
        r`  ra  Ú
repositoryr³   ú~z.pypircN)
ÚdictÚfromkeysr!   rœ   r[   rG   rb   Ú
expanduserrÌ   rÁ   )r‹   ÚdefaultsÚrcr:   r:   r;   rœ   ³  s
    !zPyPIConfig.__init__c                s5   ‡  f d d †  ˆ  j  ƒ  Dƒ } t t ˆ  j | ƒ ƒ S)Nc                s.   g  |  ]$ } ˆ  j  | d  ƒ j ƒ  r | ‘ q S)rf  )r¿   r}   )rÛ   Úsection)r‹   r:   r;   rÜ   Á  s   	 z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)Úsectionsrh  r{   Ú_get_repo_cred)r‹   Zsections_with_repositoriesr:   )r‹   r;   Úcreds_by_repository¾  s    zPyPIConfig.creds_by_repositoryc             C   sO   |  j  | d ƒ j ƒ  } | t |  j  | d ƒ j ƒ  |  j  | d ƒ j ƒ  ƒ f S)Nrf  r`  ra  )r¿   r}   r_  )r‹   rm  Úrepor:   r:   r;   ro  Ç  s    zPyPIConfig._get_repo_credc             C   s7   x0 |  j  j ƒ  D] \ } } | j | ƒ r | Sq Wd S)zŒ
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)rp  Úitemsr5   )r‹   rD   rf  Úcredr:   r:   r;   Úfind_credentialÎ  s    zPyPIConfig.find_credentialN)r’   r“   r”   rœ   Úpropertyrp  ro  rt  r:   r:   r:   r;   re  ±  s   	re  c             C   s¡  t  |  ƒ \ } } } } } } | j d ƒ r? t j d ƒ ‚ n  | d
 k r` t | ƒ \ } }	 n d } | s¶ t ƒ  j |  ƒ }
 |
 r¶ t |
 ƒ } |
 j |  f } t	 j
 d | ƒ q¶ n  | rd t | ƒ } t | |	 | | | | f ƒ } t j | ƒ } | j d | ƒ n t j |  ƒ } | j d	 t ƒ | | ƒ } | r�t  | j ƒ \ } } } } } } | | k r�| |	 k r�t | | | | | | f ƒ | _ q�n  | S)z4Open a urllib2 request, handling HTTP authenticationr<  znonnumeric port: ''ÚhttpÚhttpsNz*Authenticating as %s for %s (from .pypirc)zBasic ÚAuthorizationz
User-Agent)zhttpzhttps)r   r4   r   r&  r   re  rt  r|   r`  r   r¼   r^  r   r   ÚRequestÚ
add_headerÚ
user_agentrD   )rD   r¯   rE   r?  rG   ÚparamsrI   rë   rA  rB  rs  r¼   rê   Úrequestr  Ús2Úh2Zpath2Zparam2Zquery2Zfrag2r:   r:   r;   r%  Ø  s2    !'r%  c             C   s   |  S)Nr:   )rD   r:   r:   r;   Ú
fix_sf_url  s    r€  c             C   su  t  |  ƒ \ } } } } } } t | ƒ } t j j | ƒ rI t j |  ƒ S| j d ƒ r=t j j | ƒ r=g  } x» t j	 | ƒ D]� }	 |	 d k rÊ t
 t j j | |	 ƒ d ƒ }
 |
 j ƒ  } |
 j ƒ  Pn. t j j t j j | |	 ƒ ƒ rø |	 d 7}	 n  | j d |	 |	 f ƒ q€ Wd |  d d j | ƒ } d \ } } n d \ } } } i d d 6} t |  | | | t | ƒ ƒ S)z7Read a local path, with special support for directoriesr<   z
index.htmlÚrz<a href=%r>%s</a>z<html><head><title>%s</title>z</head><body>%s</body></html>rY  éÈ   ÚOKé”  úPath not foundú	Not foundz	text/htmlzcontent-type)r‚  zOK)r„  r…  r†  )r   r   r[   rG   Úisfiler   r°   r4   rÎ   rÐ   rÝ   rb   rÁ   rÀ   rû   r   r   )rD   rE   rF   rG   ÚparamrI   rë   r\   ÚfilesrÊ   r  ÚbodyÚstatusÚmessager¾   r:   r:   r;   r$  	  s*    !
!r$  )]r•   r'  r[   r¤   r  rS  r[  r˜   Ú	functoolsr   Úpkg_resourcesr   r   r   r   r   r   r	   r
   r   r   r   r   r   r‰   r   Ú	distutilsr   Zdistutils.errorsr   Zsetuptools.compatr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   Úfnmatchr#   Zsetuptools.py26compatr$   Zsetuptools.py27compatr%   r¥   rN   ÚIr~   rè   rO   r·   rC   rU   Ú__all__Z_SOCKET_TIMEOUTr(   rK   r'   rM   r]   r)   rn   rs   rx   r‡   r  r{  ÚobjectrŠ   r–   r&   ré   rQ  rN  rP  r   rX  r^  r_  re  r°   r%  r€  r$  r:   r:   r:   r;   Ú<module>   sp   Xd			"
'!ÿ ÿ f
'+