509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
Ävh€�  ã               @   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j/dƒZ0ej/dej1ƒZ2ej/dƒZ3ej/dej1ƒj4Z5dj6ƒ Z7ddddgZ8dZ9dZ:e:j;ej<dd… ed�Z=dd„ Z>dd„ Z?dd„ Z@dEd d„ZAdFd!d"„ZBdGd#d$„ZCdedfd%d„ZDdHd&d'„ZEd(d)„ ZFej/d*ej1ƒZGeFd+d,„ ƒZHG d-d.„ d.eIƒZJG d/d0„ d0eJƒZKG d1d„ deƒZLej/d2ƒjMZNd3d4„ ZOd5d6„ ZPdId7d8„ZQd9d:„ ZRG d;d<„ d<eIƒZSG d=d>„ d>ejTƒZUejVjWfd?d@„ZXeQe9ƒeXƒZXdAdB„ ZYdCdD„ ZZdS )Jz#PyPI and direct package downloadingé    N)Úwraps)Úsix)ÚurllibÚhttp_clientÚconfigparserÚmap)ÚCHECKOUT_DISTÚDistributionÚBINARY_DISTÚnormalize_pathÚSOURCE_DISTÚEnvironmentÚfind_distributionsÚ	safe_nameÚsafe_versionÚto_filenameÚRequirementÚDEVELOP_DISTÚEGG_DIST)Ússl_support)Úlog)ÚDistutilsError)Ú	translate)Úget_all_headers)Úunescape)ÚWheelz^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é   z<setuptools/{setuptools.__version__} Python-urllib/{py_major}é   )Zpy_majorÚ
setuptoolsc             C   s2   y
t j| ƒS  tk
r,   td| f ƒ‚Y nX d S )Nz1Not a URL, existing file, or requirement spec: %r)r   ÚparseÚ
ValueErrorr   )Úspec© r&   ú#/usr/lib/python3.6/package_index.pyÚparse_requirement_arg3   s
    
r(   c             C   s°   | j ƒ }d\}}}|jdƒr¦|jdƒr8| dd… }d}nn|jddƒrb| dd… }| dd… }d}nD|jd
ƒr~| dd… }d}n(|jddƒr¦| dd… }| dd… }d}|||fS )z=Return (base,pyversion) or (None,None) for possible .exe nameNz.exez
.win32.exeé
   Zwin32z	.win32-pyé   é   é   z.win-amd64.exeé   z	win-amd64z.win-amd64-pyé   )NNNiöÿÿÿiðÿÿÿiùÿÿÿéüÿÿÿiðÿÿÿiòÿÿÿiìÿÿÿiùÿÿÿr/   iìÿÿÿ)ÚlowerÚendswithÚ
startswith)Únamer0   ÚbaseÚpy_verZplatr&   r&   r'   r   <   s$    



c       	      C   sx   t jj| ƒ}|\}}}}}}t jj|jdƒd ƒ}|dkrX|dkrXt jj|jdƒd ƒ}d|krp|jddƒ\}}||fS )	Nú/é   zsourceforge.netÚdownloadé   ú#éÿÿÿÿéþÿÿÿ)r   r#   ÚurlparseÚunquoteÚsplit)	ÚurlÚpartsÚschemeÚserverÚpathZ
parametersÚqueryÚfragmentr4   r&   r&   r'   Úegg_info_for_urlT   s    rG   c             c   sd   t | ƒ\}}xt| ||ƒD ]
}|V  qW |r`tj|ƒ}|r`x$t| |jdƒ|td�D ]
}|V  qRW dS )zEYield egg or source distribution objects that might be found at a URLr7   )Ú
precedenceN)rG   Údistros_for_locationÚEGG_FRAGMENTÚmatchr   Úgroupr   )r@   Úmetadatar4   rF   ÚdistrK   r&   r&   r'   r   _   s    

c             C   sä   |j dƒr|dd
… }|j dƒr8d|kr8tj| ||ƒgS |j dƒrxd|krxt|ƒ}|jƒ s^g S t| |j|jtd d�gS |j d	ƒrªt|ƒ\}}}|dk	rªt	| |||t
|ƒS x4tD ],}|j |ƒr°|dt|ƒ … }t	| ||ƒS q°W g S )z:Yield egg or source distribution objects based on basenamez.egg.zipNr,   z.eggú-z.whlr7   )ÚlocationÚproject_nameÚversionrH   z.exer/   )r1   r	   Zfrom_locationr   Zis_compatiblerQ   rR   r   r   r   r
   Ú
EXTENSIONSÚlen)rP   ÚbasenamerM   ZwheelZwin_baser5   ÚplatformZextr&   r&   r'   rI   m   s.    



rI   c             C   s   t t| ƒtjj| ƒ|ƒS )zEYield possible egg or source distribution objects based on a filename)rI   r   ÚosrD   rU   )ÚfilenamerM   r&   r&   r'   Údistros_for_filenameŽ   s    rY   c          
   c   s‚   |j dƒ}| r.tdd„ |dd… D ƒƒr.dS xNtdt|ƒd ƒD ]8}t| |dj|d|… ƒdj||d… ƒ|||d�V  qBW d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!
    rO   c             s   s   | ]}t jd |ƒV  qdS )z	py\d\.\d$N)ÚrerK   )Ú.0Úpr&   r&   r'   ú	<genexpr>¬   s    z(interpret_distro_name.<locals>.<genexpr>r9   Nr7   )Ú
py_versionrH   rV   )r?   ÚanyÚrangerT   r	   Újoin)rP   rU   rM   r^   rH   rV   rA   r\   r&   r&   r'   r   •   s    
 $c             c   sn   t ƒ }|j}|dkr>xTtjj|j| ƒD ]}||ƒ |V  q&W n,x*| D ]"}||ƒ}||krD||ƒ |V  qDW dS )zHList unique elements, preserving order. Remember all elements ever seen.N)ÚsetÚaddr   ZmovesÚfilterfalseÚ__contains__)ÚiterableÚkeyÚseenZseen_addÚelementÚkr&   r&   r'   Úunique_everseen¹   s    
rk   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)rk   )ÚargsÚkwargs)Úfuncr&   r'   ÚwrapperÑ   s    zunique_values.<locals>.wrapper)r   )rn   ro   r&   )rn   r'   Úunique_valuesË   s    rp   z3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>c             c   sÆ   xvt j|ƒD ]h}|jƒ \}}tttj|jƒ jdƒƒƒ}d|ksFd|krx,t	j|ƒD ]}t
jj| t|jdƒƒƒV  qRW qW xHdD ]@}|j|ƒ}|d	kr~t	j||ƒ}|r~t
jj| t|jdƒƒƒV  q~W dS )
zEFind rel="homepage" and rel="download" links in `page`, yielding URLsú,Zhomepager8   r7   ú<th>Home Pageú<th>Download URLN)rr   rs   r;   )ÚRELÚfinditerÚgroupsrb   r   ÚstrÚstripr0   r?   ÚHREFr   r#   ÚurljoinÚ
htmldecoderL   ÚfindÚsearch)r@   ÚpagerK   ÚtagZrelZrelsÚposr&   r&   r'   Úfind_external_linksÜ   s    "

r�   c               @   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               @   sB   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   s>   t jj|ƒd }|stƒ S | jj|ƒ}|s0tƒ S | f |jƒ ŽS )z5Construct a (possibly null) ContentChecker from a URLr7   r;   )r   r#   r=   r‚   Úpatternr}   Ú	groupdict)Úclsr@   rF   rK   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’   Z	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Œ   rZ   Úcompiler•   r”   Úclassmethodr˜   r…   r†   r‰   r&   r&   r&   r'   rŽ     s   rŽ   c                   s<  e Zd ZdZdKdd„ZdLd	d
„ZdMdd„ZdNdd„Zdd„ Zdd„ Z	dd„ Z
dd„ ZdOdd„Zdd„ ZdP‡ fdd„	Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ ZdQd'd(„ZdRd)d*„Zd+d,„ Zd-Zd.d/„ Zd0d1„ ZdSd2d3„Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Ze dTd>d?„ƒZ!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&‡  Z'S )Ur   z;A distribution index that scans web pages for download URLsúhttps://pypi.org/simple/Ú*NTc             O   s”   t j| f|ž|Ž |dd |jdƒ …  | _i | _i | _i | _tjdj	t
t|ƒƒƒj| _g | _|ortjor|prtjƒ }|r†tj|ƒ| _n
tjj| _d S )Nr6   ú|)r   r”   r1   Ú	index_urlÚscanned_urlsÚfetched_urlsÚpackage_pagesrZ   r›   ra   r   r   rK   ÚallowsÚto_scanr   Zis_availableZfind_ca_bundleZ
opener_forÚopenerr   ÚrequestÚurlopen)rƒ   r    ZhostsZ	ca_bundleZ
verify_sslrl   ÚkwZuse_sslr&   r&   r'   r”   ,  s    zPackageIndex.__init__Fc             C   sÂ  || j kr| rdS d| j |< t|ƒs4| j|ƒ dS tt|ƒƒ}|r^| j|ƒsRdS | jd|ƒ |sr| sr|| jkr†tt| j	|ƒƒ dS | j|ƒsžd| j|< dS | j
d|ƒ d| j|< d}| j||| ƒ}|dkrÔdS d| j|j< d|jjddƒjƒ k�r|jƒ  dS |j}|jƒ }t|tƒ�sRt|tjjƒ�r4d	}n|jjd
ƒ�pDd	}|j|dƒ}|jƒ  x6tj|ƒD ](}	tjj|t|	jdƒƒƒ}
| j|
ƒ �qfW |j | j!ƒ�r¾t"|ddƒdk�r¾| j#||ƒ}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Úignorer7   Úcodei”  )$r¡   Ú
URL_SCHEMEÚprocess_filenameÚlistr   Úurl_okÚdebugr¢   r   rc   ÚinfoÚopen_urlr@   ÚheadersÚgetr0   ÚcloseÚreadÚ
isinstancerw   r   ÚerrorÚ	HTTPErrorZ	get_paramÚdecodery   ru   r#   rz   r{   rL   Úprocess_urlr2   r    ÚgetattrÚprocess_index)rƒ   r@   ZretrieveÚdistsÚtmplÚfr4   r~   r¬   rK   Úlinkr&   r&   r'   r¾   A  sP    





 zPackageIndex.process_urlc             C   s�   t jj|ƒs| jd|ƒ d S t jj|ƒrd| rdt jj|ƒ}x(t j|ƒD ]}| jt jj||ƒdƒ qFW t	|ƒ}|rŒ| j
d|ƒ tt| j|ƒƒ d S )NzNot found: %sTz	Found: %s)rW   rD   ÚexistsÚwarnÚisdirÚrealpathÚlistdirr°   ra   rY   r³   r±   r   rc   )rƒ   ÚfnÚnestedrD   ÚitemrÁ   r&   r&   r'   r°   t  s    zPackageIndex.process_filenamec             C   sb   t |ƒ}|o|jdƒjƒ dk}|s8| jtjj|ƒd ƒr<dS d}|rRt|| ƒ‚n| j||ƒ d S )Nr7   ÚfileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r¯   rL   r0   r¤   r   r#   r=   r   rÆ   )rƒ   r@   ZfatalÚsÚis_filerš   r&   r&   r'   r²   „  s    zPackageIndex.url_okc             C   s2   t tjj|ƒ}dd„ |D ƒ}ttj| j|ƒƒ d S )Nc             s   s0   | ](}t j|ƒD ]}|jd ƒr||fV  qqdS )z	.egg-linkN)rW   rÉ   r1   )r[   rD   Úentryr&   r&   r'   r]   ”  s   z.PackageIndex.scan_egg_links.<locals>.<genexpr>)ÚfilterrW   rD   rÇ   r±   Ú	itertoolsÚstarmapÚscan_egg_link)rƒ   Zsearch_pathÚdirsZ	egg_linksr&   r&   r'   Úscan_egg_links‘  s    zPackageIndex.scan_egg_linksc             C   s�   t tjj||ƒƒ�}ttd ttj|ƒƒƒ}W d Q R X t	|ƒdkrDd S |\}}x>t
tjj||ƒƒD ](}tjj|f|žŽ |_t|_| j|ƒ q`W d S )Nr9   )ÚopenrW   rD   ra   r±   rÑ   r   rw   rx   rT   r   rP   r   rH   rc   )rƒ   rD   rÐ   Z	raw_linesÚlinesZegg_pathZ
setup_pathrN   r&   r&   r'   rÔ   ›  s     zPackageIndex.scan_egg_linkc       
         sØ   ‡ fdd„}xHt j|ƒD ]:}y |tjj|t|jdƒƒƒƒ W q tk
rP   Y qX qW ||ƒ\}}|rÐxXt||ƒD ]J}t	|ƒ\}}	|j
dƒr²|	 r²|r¨|d||f 7 }n
ˆ j|ƒ ˆ j|ƒ qrW tjdd„ |ƒS dS d	S )
z#Process the contents of a PyPI pagec                sŒ   | j ˆ jƒrˆtttjj| 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S dS )Nr6   r9   r:   r7   r   T)NN)r2   r    r±   r   r   r#   r>   rT   r?   r   r   r£   Ú
setdefaultr0   r   )rÄ   rA   ÚpkgÚver)rƒ   r&   r'   Úscan®  s    "z(PackageIndex.process_index.<locals>.scanr7   z.pyz
#egg=%s-%sc             S   s   d| j dddƒ S )Nz<a href="%s#md5=%s">%s</a>r7   r!   r9   )rL   )Úmr&   r&   r'   Ú<lambda>Ñ  s    z,PackageIndex.process_index.<locals>.<lambda>r«   N)ry   ru   r   r#   rz   r{   rL   r$   r�   rG   r1   Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)
rƒ   r@   r~   rÜ   rK   rÚ   rÛ   Únew_urlr4   Úfragr&   )rƒ   r'   rÀ   «  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ƒ   r@   r&   r&   r'   rß   Ö  s    zPackageIndex.need_version_infoc             G   s:   | j | jkr*|r | j|f|žŽ  | jdƒ | j| j ƒ d S )Nz6Scanning index of all packages (this may take a while))r    r¢   rÆ   r´   rà   )rƒ   rš   rl   r&   r&   r'   rå   Ü  s    zPackageIndex.scan_allc             C   s~   | j | j|j d ƒ | jj|jƒs:| j | j|j d ƒ | jj|jƒsR| j|ƒ x&t| jj|jf ƒƒD ]}| j |ƒ qhW d S )Nr6   )	rà   r    Úunsafe_namer£   r·   rg   rQ   Únot_found_in_indexr±   )rƒ   Úrequirementr@   r&   r&   r'   Úfind_packageså  s    
zPackageIndex.find_packagesc                sR   | j ƒ  | j|ƒ x,| |j D ]}||kr.|S | jd||ƒ qW tt| ƒj||ƒS )Nz%s does not match %s)Úprescanré   rg   r³   Úsuperr   Úobtain)rƒ   rè   Z	installerrN   )Ú	__class__r&   r'   rì   ô  s    
zPackageIndex.obtainc             C   sL   |j | jd| ƒ |jƒ sH|jƒ  tj|ƒ td|jjtj	j
|ƒf ƒ‚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¸   rW   Úunlinkr   r’   r3   rD   rU   )rƒ   ÚcheckerrX   Útfpr&   r&   r'   Ú
check_hashý  s    

zPackageIndex.check_hashc             C   sT   xN|D ]F}| j dks4t|ƒ s4|jdƒs4tt|ƒƒr@| j|ƒ q| j j|ƒ qW dS )z;Add `urls` to the list that will be prescanned for searchesNzfile:)r¥   r¯   r2   r±   r   rà   Úappend)rƒ   Zurlsr@   r&   r&   r'   Úadd_find_links  s    



zPackageIndex.add_find_linksc             C   s"   | j rtt| j| j ƒƒ 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   s<   | |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?))rg   r´   rÆ   ræ   rå   )rƒ   rè   Úmethrš   r&   r&   r'   rç   "  s    
zPackageIndex.not_found_in_indexc             C   s~   t |tƒsjt|ƒ}|rR| j|jdƒ||ƒ}t|ƒ\}}|jdƒrN| j|||ƒ}|S tj	j
|ƒrb|S t|ƒ}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.
        r7   z.pyrP   N)rº   r   r¯   Ú_download_urlrL   rG   r1   Ú	gen_setuprW   rD   rÅ   r(   r¿   Úfetch_distribution)rƒ   r%   ÚtmpdirrB   Úfoundr4   rF   r&   r&   r'   r8   ,  s    

zPackageIndex.downloadc       	         sà   ˆj d|ƒ i ‰d}d
‡ ‡‡‡‡fdd„	}|rHˆjƒ  ˆj|ƒ ||ƒ}| r`|dk	r`|||ƒ}|dkr‚ˆjdk	rzˆjƒ  ||ƒ}|dkr¢| r¢ˆj|ƒ ||ƒ}|dkrÂˆjdˆr¸dpºd|ƒ nˆj d|ƒ |j|jd	�S d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ˆ}x‚|| j  D ]t}|jtkrJˆ  rJ|ˆkrˆjd|ƒ dˆ|< q|| ko`|jtkp`ˆ }|rˆj|jˆƒ}||_tj	j
|jƒr|S qW d S )Nz&Skipping development or system egg: %sr7   )rg   rH   r   rÆ   r   r8   rP   Údownload_locationrW   rD   rÅ   )ZreqÚenvrN   ZtestÚloc)Ú
develop_okrƒ   ÚskippedÚsourcerø   r&   r'   r|   f  s     z-PackageIndex.fetch_distribution.<locals>.findz:No local packages or working download links found for %s%sza source distribution of r«   zBest match: %s)rP   )N)r´   rê   ré   r¥   rÆ   Úclonerú   )	rƒ   rè   rø   Ú
force_scanrÿ   rý   Zlocal_indexrN   r|   r&   )rý   rƒ   rþ   rÿ   rø   r'   r÷   N  s0    




zPackageIndex.fetch_distributionc             C   s"   | j ||||ƒ}|dk	r|jS d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÷   rP   )rƒ   rè   rø   r  rÿ   rN   r&   r&   r'   Úfetchš  s    zPackageIndex.fetchc       
      C   sü   t j|ƒ}|r*dd„ t||jdƒd ƒD ƒp,g }t|ƒdkrÚtjj|ƒ}tjj|ƒ|krŠtjj	||ƒ}ddl
m} |||ƒsŠtj||ƒ |}ttjj	|dƒdƒ�2}	|	jd|d j|d jtjj|ƒd f ƒ W d Q R X |S |rðtd	||f ƒ‚ntd
ƒ‚d S )Nc             S   s   g | ]}|j r|‘qS r&   )rR   )r[   Údr&   r&   r'   ú
<listcomp>ª  s    z*PackageIndex.gen_setup.<locals>.<listcomp>r7   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.)rJ   rK   r   rL   rT   rW   rD   rU   Údirnamera   Zsetuptools.command.easy_installr  ÚshutilZcopy2r×   ÚwriterQ   rR   Úsplitextr   )
rƒ   rX   rF   rø   rK   rÁ   rU   Údstr  rÍ   r&   r&   r'   rö   §  s2    

 zPackageIndex.gen_setupi    c             C   s  | j d|ƒ d }zîtj|ƒ}| j|ƒ}t|tjjƒrJtd||j	|j
f ƒ‚|j ƒ }d}| j}d}d|kr’t|dƒ}	ttt|	ƒƒ}| j|||||ƒ t|dƒ�Z}
xD|j|ƒ}|rÞ|j|ƒ |
j|ƒ |d7 }| j|||||ƒ q P q W | j|||
ƒ W d Q R X |S |�r|jƒ  X d S )	NzDownloading %szCan't download %s: %s %sr   r7   zcontent-lengthzContent-LengthÚwbr;   )r´   rŽ   r˜   rµ   rº   r   r»   r¼   r   r®   rš   Údl_blocksizer   Úmaxr   ÚintÚ
reporthookr×   r¹   r…   r	  rñ   r¸   )rƒ   r@   rX   Úfprï   r¶   ÚblocknumZbsÚsizeZsizesrð   r„   r&   r&   r'   Ú_download_toÒ  s:    





zPackageIndex._download_toc             C   s   d S )Nr&   )rƒ   r@   rX   r  Zblksizer  r&   r&   r'   r  ö  s    zPackageIndex.reporthookc             C   sŒ  |j dƒrt|ƒS yt|| jƒS  ttjfk
r€ } z>djdd„ |jD ƒƒ}|r^| j	||ƒ nt
d||f ƒ‚W Y d d }~X �n tjjk
r¢ } z|S d }~X næ tjjk
rì } z,|rÊ| j	||jƒ nt
d||jf ƒ‚W Y d d }~X nœ tjk
�r8 } z.|�r| j	||jƒ nt
d||jf ƒ‚W Y d d }~X nP tjtjfk
�r† } z*|�rf| j	||ƒ nt
d||f ƒ‚W Y d d }~X nX d S )Nzfile:ú c             S   s   g | ]}t |ƒ‘qS r&   )rw   )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)r2   Ú
local_openÚopen_with_authr¦   r$   r   Ú
InvalidURLra   rl   rÆ   r   r   r»   r¼   ZURLErrorÚreasonZBadStatusLineÚlineZHTTPExceptionÚsocket)rƒ   r@   ZwarningÚvrš   r&   r&   r'   rµ   ù  s6    
"zPackageIndex.open_urlc             C   s  t |ƒ\}}|r4x&d|kr0|jddƒjddƒ}qW nd}|jdƒrN|d d… }tjj||ƒ}|jt|ƒƒsztdj	|d	�ƒ‚|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|dƒ | j||ƒS d S )Nz..Ú.ú\Ú_Z__downloaded__z.egg.zipr,   zInvalid filename {filename})rX   Úsvnzsvn+Úgitzgit+zhg+rÍ   r9   Tr/   )rG   Úreplacer1   rW   rD   ra   r2   rw   r$   ÚformatÚ_download_svnÚ_download_gitÚ_download_hgr   r§   Úurl2pathnamer#   r=   r²   Ú_attempt_download)rƒ   rB   r@   rø   r3   rF   rX   r&   r&   r'   rõ     s(    


zPackageIndex._download_urlc             C   s   | j |dƒ d S )NT)r¾   )rƒ   r@   r&   r&   r'   rà   =  s    zPackageIndex.scan_urlc             C   s6   | j ||ƒ}d|jddƒjƒ kr.| j|||ƒS |S d S )Nrª   zcontent-typer«   )r  r·   r0   Ú_download_html)rƒ   r@   rX   r¶   r&   r&   r'   r)  @  s    zPackageIndex._attempt_downloadc             C   sl   t |ƒ}x@|D ]8}|jƒ rtjd|ƒrD|jƒ  tj|ƒ | j||ƒS P qW |jƒ  tj|ƒ td| ƒ‚d S )Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	r×   rx   rZ   r}   r¸   rW   rî   r%  r   )rƒ   r@   r¶   rX   rÍ   r  r&   r&   r'   r*  G  s    


zPackageIndex._download_htmlc             C   s  |j ddƒd }g }|jƒ jdƒrâd|krâtjj|ƒ\}}}}}}	| râ|jdƒrâd|dd … krâ|dd … j ddƒ\}}tjj|ƒ\}
}|
râd	|
kr¸|
j d	dƒ\}}d
| d| g}n
d
|
 g}|}||||||	f}tjj|ƒ}| jd||ƒ t	j
ddg| d||g ƒ |S )Nr:   r7   r   zsvn:ú@z//r6   r9   ú:z--username=z--password=z'Doing subversion checkout from %s to %sr!  Úcheckoutz-q)r?   r0   r2   r   r#   r=   Ú	splituserÚ
urlunparser´   Ú
subprocessÚ
check_call)rƒ   r@   rX   ZcredsrB   ÚnetlocrD   r\   ÚqrÃ   ÚauthÚhostÚuserZpwrA   r&   r&   r'   r%  V  s$     
zPackageIndex._download_svnc             C   sp   t jj| ƒ\}}}}}|jddƒd }|jddƒd }d }d|krR|jddƒ\}}t jj||||dfƒ} | |fS )Nú+r7   r:   r   r+  r«   r;   )r   r#   Zurlsplitr?   ÚrsplitZ
urlunsplit)r@   Ú
pop_prefixrB   r2  rD   rE   rä   Úrevr&   r&   r'   Ú_vcs_split_rev_from_urlk  s    z$PackageIndex._vcs_split_rev_from_urlc             C   sr   |j ddƒd }| j|dd�\}}| jd||ƒ tjddd	||gƒ |d k	rn| jd
|ƒ tjdd|dd	|gƒ |S )Nr:   r7   r   T)r9  zDoing git clone from %s to %sr"  r   z--quietzChecking out %sz-Cr-  )r?   r;  r´   r0  r1  )rƒ   r@   rX   r:  r&   r&   r'   r&  }  s    zPackageIndex._download_gitc          	   C   sv   |j ddƒd }| j|dd�\}}| jd||ƒ tjddd	||gƒ |d k	rr| jd
|ƒ tjdd|ddd|dgƒ |S )Nr:   r7   r   T)r9  zDoing hg clone from %s to %sZhgr   z--quietzUpdating to %sz--cwdZupz-Cz-rz-q)r?   r;  r´   r0  r1  )rƒ   r@   rX   r:  r&   r&   r'   r'  Š  s    zPackageIndex._download_hgc             G   s   t j|f|žŽ  d S )N)r   r³   )rƒ   rš   rl   r&   r&   r'   r³   —  s    zPackageIndex.debugc             G   s   t j|f|žŽ  d S )N)r   r´   )rƒ   rš   rl   r&   r&   r'   r´   š  s    zPackageIndex.infoc             G   s   t j|f|žŽ  d S )N)r   rÆ   )rƒ   rš   rl   r&   r&   r'   rÆ   �  s    zPackageIndex.warn©rž   )r�   r<  NT)F)F)F)N)N)FFFN)FF)N)F)(rŠ   r‹   rŒ   r�   r”   r¾   r°   r²   rÖ   rÔ   rÀ   rß   rå   ré   rì   rñ   ró   rê   rç   r8   r÷   r  rö   r  r  r  rµ   rõ   rà   r)  r*  r%  Ústaticmethodr;  r&  r'  r³   r´   rÆ   Ú__classcell__r&   r&   )rí   r'   r   )  sL    

3


+
		
# 
J
)$
#!z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c             C   s   | j dƒ}t|ƒS )Nr7   )rL   r   )rK   Zwhatr&   r&   r'   Údecode_entity¦  s    
r?  c             C   s
   t t| ƒS )z'Decode HTML entities in the given text.)Ú
entity_subr?  )Ú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
ˆ | |ŽS t j|ƒ X d S )N)r  ZgetdefaulttimeoutZsetdefaulttimeout)rl   rm   Zold_timeout)rn   Útimeoutr&   r'   Ú_socket_timeout²  s
    

z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr&   )rn   rC  )rB  )rn   r'   rC  ±  s    z'socket_timeout.<locals>._socket_timeoutr&   )rB  rC  r&   )rB  r'   Úsocket_timeout°  s    rD  c             C   s2   t jj| ƒ}|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   r#   r>   ÚencodeÚbase64Zencodestringr½   r#  )r4  Zauth_sZ
auth_bytesZencoded_bytesZencodedr&   r&   r'   Ú_encode_auth¿  s
    
rH  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ƒ   rJ  rK  r&   r&   r'   r”   Û  s    zCredential.__init__c             c   s   | j V  | jV  d S )N)rJ  rK  )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”   rL  rN  r&   r&   r&   r'   rI  Ö  s   rI  c               @   s0   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	S )
Ú
PyPIConfigc             C   sP   t jdddgdƒ}tjj| |ƒ tjjtjjdƒdƒ}tjj	|ƒrL| j
|ƒ dS )z%
        Load from ~/.pypirc
        rJ  rK  Ú
repositoryr«   ú~z.pypircN)ÚdictÚfromkeysr   ÚRawConfigParserr”   rW   rD   ra   Ú
expanduserrÅ   r¹   )rƒ   ZdefaultsZrcr&   r&   r'   r”   è  s
    zPyPIConfig.__init__c                s&   ‡ fdd„ˆ j ƒ D ƒ}ttˆ j|ƒƒS )Nc                s    g | ]}ˆ j |d ƒjƒ r|‘qS )rP  )r·   rx   )r[   Úsection)rƒ   r&   r'   r  ö  s    z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)ZsectionsrR  r   Ú_get_repo_cred)rƒ   Zsections_with_repositoriesr&   )rƒ   r'   Úcreds_by_repositoryó  s    zPyPIConfig.creds_by_repositoryc             C   s6   | j |dƒjƒ }|t| j |dƒjƒ | j |dƒjƒ ƒfS )NrP  rJ  rK  )r·   rx   rI  )rƒ   rV  Zrepor&   r&   r'   rW  ü  s    zPyPIConfig._get_repo_credc             C   s*   x$| j jƒ D ]\}}|j|ƒr|S qW dS )zŒ
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)rX  Úitemsr2   )rƒ   r@   rP  Úcredr&   r&   r'   Úfind_credential  s    
zPyPIConfig.find_credentialN)rŠ   r‹   rŒ   r”   ÚpropertyrX  rW  r[  r&   r&   r&   r'   rO  ç  s   	rO  c             C   s:  t jj| ƒ\}}}}}}|jdƒr,tjdƒ‚|d
krFt jj|ƒ\}}	nd}|s~tƒ j| ƒ}
|
r~t	|
ƒ}|
j
| f}tjd|žŽ  |rÄdt|ƒ }||	||||f}t jj|ƒ}t jj|ƒ}|jd|ƒ nt jj| ƒ}|jd	tƒ ||ƒ}|�r6t jj|jƒ\}}}}}}||k�r6||	k�r6||||||f}t jj|ƒ|_|S )z4Open a urllib2 request, handling HTTP authenticationr,  znonnumeric port: ''ÚhttpÚhttpsNú*Authenticating as %s for %s (from .pypirc)zBasic ZAuthorizationz
User-Agent)r]  r^  )r_  )r   r#   r=   r1   r   r  r.  rO  r[  rw   rJ  r   r´   rH  r/  r§   ZRequestZ
add_headerÚ
user_agentr@   )r@   r¦   rB   r2  rD   ZparamsrE   rä   r4  r5  rZ  r´   rA   rã   r§   r  Ús2Zh2Zpath2Zparam2Zquery2Zfrag2r&   r&   r'   r    s6    


r  c             C   s   | S )Nr&   )r@   r&   r&   r'   Ú
fix_sf_url>  s    rb  c             C   s  t jj| ƒ\}}}}}}t jj|ƒ}tjj|ƒr<t jj| ƒS |j	dƒrêtjj
|ƒrêg }xˆtj|ƒD ]b}	tjj||	ƒ}
|	dkržt|
dƒ�}|jƒ }W dQ R X P ntjj
|
ƒr²|	d7 }	|jdj|	d�ƒ qbW d}|j| dj|ƒd	�}d\}}n
d\}}}ddi}tj|ƒ}t jj| ||||ƒS )z7Read a local path, with special support for directoriesr6   z
index.htmlÚrNz<a href="{name}">{name}</a>)r3   zB<html><head><title>{url}</title></head><body>{files}</body></html>rE  )r@   ÚfileséÈ   ÚOKé”  úPath not foundú	Not foundzcontent-typez	text/html)re  rf  )rg  rh  ri  )r   r#   r=   r§   r(  rW   rD   Úisfiler¨   r1   rÇ   rÉ   ra   r×   r¹   rò   r$  r   ÚStringIOr»   r¼   )r@   rB   rC   rD   ZparamrE   rä   rX   rd  rÃ   Úfilepathr  ZbodyrÂ   ZstatusÚmessager¶   Zbody_streamr&   r&   r'   r  B  s,    


r  )N)N)N)N)r    )[r�   r0  ÚsysrW   rZ   r  r  rG  r�   rÒ   Ú	functoolsr   Zsetuptools.externr   Zsetuptools.extern.six.movesr   r   r   r   r"   Zpkg_resourcesr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Z	distutilsr   Zdistutils.errorsr   Zfnmatchr   Zsetuptools.py27compatr   Zsetuptools.py33compatr   Zsetuptools.wheelr   r›   rJ   ÚIry   rá   rK   r¯   r?   rS   Ú__all__Z_SOCKET_TIMEOUTZ_tmplr$  rR   r`  r(   r   rG   r   rI   rY   r   rk   rp   rt   r�   Úobjectr‚   rŽ   r   râ   r@  r?  r{   rD  rH  rI  rT  rO  r§   r¨   r  rb  r  r&   r&   r&   r'   Ú<module>   s|   <
	

!
"
!    ~
&.