3

Q'ícٜã@s”dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZddl
mZmZmZmZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z ddlm!Z!ddl"m#Z#dd	l$m%Z%dd
l&m'Z'ddl(m)Z)ddl*m+Z+dd
l,m-Z-ej.dƒZ/ej.dej0ƒZ1ej.dƒZ2ej.dej0ƒj3Z4dj5ƒZ6ddddgZ7dZ8dZ9e9j:ej;dd…edZ<dd„Z=dd„Z>dd„Z?dEd d„Z@dFd!d"„ZAdGd#d$„ZBdedfd%d„ZCdHd&d'„ZDd(d)„ZEej.d*ej0ƒZFeEd+d,„ƒZGGd-d.„d.eHƒZIGd/d0„d0eIƒZJGd1d„deƒZKej.d2ƒjLZMd3d4„ZNd5d6„ZOdId7d8„ZPd9d:„ZQGd;d<„d<eHƒZRGd=d>„d>ejSƒZTejUjVfd?d@„ZWePe8ƒeWƒZWdAdB„ZXdCdD„ZYdS)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_.+!]+)$zhref\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}é)Zpy_majorÚ
setuptoolscCs2y
tj|ƒStk
r,td|fƒ‚YnXdS)Nz1Not a URL, existing file, or requirement spec: %r)rÚparseÚ
ValueErrorr)Úspec©r&ú>/tmp/pip-build-l_bcah40/setuptools/setuptools/package_index.pyÚparse_requirement_arg2s

r(cCs°|jƒ}d\}}}|jdƒr¦|jdƒr8|dd…}d}nn|jddƒrb|dd…}|dd…}d}nD|jd
ƒr~|dd…}d}n(|jd
dƒr¦|dd…}|dd…}d}|||fS)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ùÿÿÿr0iìÿÿÿ)ÚlowerÚendswithÚ
startswith)Únamer1ÚbaseÚpy_verÚplatr&r&r'r;s$



c	Csxtjj|ƒ}|\}}}}}}tjj|jdƒdƒ}|dkrX|dkrXtjj|jdƒdƒ}d|krp|jddƒ\}}||fS)	Nú/ézsourceforge.netÚdownloadéú#éÿÿÿÿéþÿÿÿ)rr#ÚurlparseÚunquoteÚsplit)	ÚurlÚpartsÚschemeÚserverÚpathÚ
parametersÚqueryÚfragmentr5r&r&r'Úegg_info_for_urlSsrJccsdt|ƒ\}}xt|||ƒD]
}|VqW|r`tj|ƒ}|r`x$t||jdƒ|tdD]
}|VqRWdS)zEYield egg or source distribution objects that might be found at a URLr9)Ú
precedenceN)rJÚdistros_for_locationÚEGG_FRAGMENTÚmatchrÚgroupr)rBÚmetadatar5rIÚdistrNr&r&r'r^s

cCsä|jdƒr|dd
…}|jdƒr8d|kr8tj|||ƒgS|jdƒrxd|krxt|ƒ}|jƒs^gSt||j|jtddgS|jd	ƒrªt|ƒ\}}}|dk	rªt	||||t
|ƒSx4tD],}|j|ƒr°|dt|ƒ…}t	|||ƒSq°WgS)z:Yield egg or source distribution objects based on basenamez.egg.zipNr-z.eggú-z.whlr9)ÚlocationÚproject_nameÚversionrKz.exer0)
r2r	Ú
from_locationrZ
is_compatiblerTrUrrrr
Ú
EXTENSIONSÚlen)rSÚbasenamerPÚwheelZwin_baser6ÚplatformÚextr&r&r'rLls.



rLcCstt|ƒtjj|ƒ|ƒS)zEYield possible egg or source distribution objects based on a filename)rLrÚosrFrY)ÚfilenamerPr&r&r'Údistros_for_filenamesr_c
cs‚|jdƒ}|r.tdd„|dd…Dƒƒr.dSxNtdt|ƒdƒD]8}t||dj|d|…ƒdj||d…ƒ|||dVqBWdS)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!
    rRcss|]}tjd|ƒVqdS)z	py\d\.\d$N)ÚrerN)Ú.0Úpr&r&r'ú	<genexpr>«sz(interpret_distro_name.<locals>.<genexpr>r;Nr9)Ú
py_versionrKr[)rAÚanyÚrangerXr	Újoin)rSrYrPrdrKr[rCrbr&r&r'r”s
 $ccsntƒ}|j}|dkr>xTtjj|j|ƒD]}||ƒ|Vq&Wn,x*|D]"}||ƒ}||krD||ƒ|VqDWdS)zHList unique elements, preserving order. Remember all elements ever seen.N)ÚsetÚaddrÚmovesÚfilterfalseÚ__contains__)ÚiterableÚkeyÚseenZseen_addÚelementÚkr&r&r'Úunique_everseen¸s
rrcstˆƒ‡fdd„ƒ}|S)zs
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    cstˆ||ŽƒS)N)rr)ÚargsÚkwargs)Úfuncr&r'ÚwrapperÐszunique_values.<locals>.wrapper)r)rurvr&)rur'Ú
unique_valuesÊsrwz3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>ccsÆxvtj|ƒD]h}|jƒ\}}tttj|jƒjdƒƒƒ}d|ksFd|krx,t	j|ƒD]}t
jj|t
|jdƒƒƒVqRWqWxHdD]@}|j|ƒ}|d	kr~t	j||ƒ}|r~t
jj|t
|jdƒƒƒVq~WdS)
zEFind rel="homepage" and rel="download" links in `page`, yielding URLsú,Zhomepager:r9ú
<th>Home Pageú<th>Download URLN)ryrzr=)ÚRELÚfinditerÚgroupsrhrÚstrÚstripr1rAÚHREFrr#ÚurljoinÚ
htmldecoderOÚfindÚsearch)rBÚpagerNÚtagÚrelZrelsÚposr&r&r'Úfind_external_linksÛs"

r‰c@s(eZdZdZdd„Zdd„Zdd„ZdS)	ÚContentCheckerzP
    A null content checker that defines the interface for checking content
    cCsdS)z3
        Feed a block of data to the hash.
        Nr&)ÚselfÚblockr&r&r'ÚfeedószContentChecker.feedcCsdS)zC
        Check the hash. Return False if validation fails.
        Tr&)r‹r&r&r'Úis_validùszContentChecker.is_validcCsdS)zu
        Call reporter with information about the checker (hash name)
        substituted into the template.
        Nr&)r‹ÚreporterÚtemplater&r&r'ÚreportÿszContentChecker.reportN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrŽr‘r&r&r&r'rŠîsrŠc@sBeZdZejdƒZdd„Zedd„ƒZdd„Z	dd	„Z
d
d„ZdS)
ÚHashCheckerzK(?P<hash_name>sha1|sha224|sha384|sha256|sha512|md5)=(?P<expected>[a-f0-9]+)cCs||_tj|ƒ|_||_dS)N)Ú	hash_nameÚhashlibÚnewÚhashÚexpected)r‹r—r›r&r&r'Ú__init__
szHashChecker.__init__cCs>tjj|ƒd}|stƒS|jj|ƒ}|s0tƒS|f|jƒŽS)z5Construct a (possibly null) ContentChecker from a URLr9r=)rr#r?rŠÚpatternr„Ú	groupdict)ÚclsrBrIrNr&r&r'Úfrom_urlszHashChecker.from_urlcCs|jj|ƒdS)N)ršÚupdate)r‹rŒr&r&r'rszHashChecker.feedcCs|jjƒ|jkS)N)ršÚ	hexdigestr›)r‹r&r&r'rŽ szHashChecker.is_validcCs||j}||ƒS)N)r—)r‹rrÚmsgr&r&r'r‘#s
zHashChecker.reportN)r’r“r”r`ÚcompilerrœÚclassmethodr rrŽr‘r&r&r&r'r–sr–cs<eZdZdZdKdd„ZdLd	d
„ZdMdd„ZdNd
d„Zdd„Zdd„Z	dd„Z
dd„ZdOdd„Zdd„Z
dP‡fdd„	Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZdQd'd(„ZdRd)d*„Zd+d,„Zd-Zd.d/„Zd0d1„ZdSd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Zd<d=„Ze dTd>d?„ƒZ!d@dA„Z"dBdC„Z#dDdE„Z$dFdG„Z%dHdI„Z&‡Z'S)Urz;A distribution index that scans web pages for download URLsúhttps://pypi.python.org/simpleÚ*NTcOs”tj|f|ž|Ž|dd|jdƒ…|_i|_i|_i|_tjdj	t
t|ƒƒƒj|_
g|_|ortjor|prtjƒ}|r†tj|ƒ|_n
tjj|_dS)Nr8ú|)r
rœr2Ú	index_urlÚscanned_urlsÚfetched_urlsÚ
package_pagesr`r¤rgrrrNÚallowsÚto_scanrZis_availableZfind_ca_bundleZ
opener_forÚopenerrÚrequestÚurlopen)r‹r©ÚhostsZ	ca_bundleZ
verify_sslrsÚkwZuse_sslr&r&r'rœ+szPackageIndex.__init__FcCsÂ||jkr|rdSd|j|<t|ƒs4|j|ƒdStt|ƒƒ}|r^|j|ƒsRdS|jd|ƒ|sr|sr||jkr†tt|j	|ƒƒdS|j|ƒsžd|j|<dS|j
d|ƒd|j|<d}|j|||ƒ}|dkrÔdSd|j|j<d|j
jddƒjƒkr|jƒdS|j}|jƒ}t|tƒsRt|tjjƒr4d	}n|j
jd
ƒpDd	}|j|dƒ}|jƒx6tj|ƒD](}	tjj|t|	jdƒƒƒ}
|j|
ƒqfW|j |j!ƒr¾t"|d
dƒdkr¾|j#||ƒ}dS)z<Evaluate a URL as a possible download, and maybe retrieve itNTzFound link: %sz
Reading %sz<Download error on %s: %%s -- Some packages may not be found!Úhtmlzcontent-typeÚzlatin-1ÚcharsetÚignorer9Úcodei”)$rªÚ
URL_SCHEMEÚprocess_filenameÚlistrÚurl_okÚdebugr«rriÚinfoÚopen_urlrBÚheadersÚgetr1ÚcloseÚreadÚ
isinstancer~rÚerrorÚ	HTTPErrorÚ	get_paramÚdecoder€r|r#rr‚rOÚprocess_urlr3r©ÚgetattrÚ
process_index)r‹rBÚretrieveÚdistsÚtmplÚfr5r…r¶rNÚlinkr&r&r'rÉ@sP





 zPackageIndex.process_urlcCstjj|ƒs|jd|ƒdStjj|ƒrd|rdtjj|ƒ}x(tj|ƒD]}|jtjj||ƒdƒqFWt	|ƒ}|rŒ|j
d|ƒtt|j
|ƒƒdS)Nz
Not found: %sTz	Found: %s)r]rFÚexistsÚwarnÚisdirÚrealpathÚlistdirrºrgr_r½r»rri)r‹ÚfnÚnestedrFÚitemrÍr&r&r'rºsszPackageIndex.process_filenamecCsbt|ƒ}|o|jdƒjƒdk}|s8|jtjj|ƒdƒr<dSd}|rRt||ƒ‚n|j||ƒdS)Nr9ÚfileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r¹rOr1r­rr#r?rrÒ)r‹rBÚfatalÚsÚis_filer£r&r&r'r¼ƒszPackageIndex.url_okcCs2ttjj|ƒ}dd„|Dƒ}ttj|j|ƒƒdS)Ncss0|](}tj|ƒD]}|jdƒr||fVqqdS)z	.egg-linkN)r]rÕr2)rarFÚentryr&r&r'rc“sz.PackageIndex.scan_egg_links.<locals>.<genexpr>)Úfilterr]rFrÓr»Ú	itertoolsÚstarmapÚ
scan_egg_link)r‹Úsearch_pathÚdirsZ	egg_linksr&r&r'Úscan_egg_linksszPackageIndex.scan_egg_linksc
Csttjj||ƒƒ}ttdttj|ƒƒƒ}WdQRXt	|ƒdkrDdS|\}}x>t
tjj||ƒƒD](}tjj|f|žŽ|_t|_
|j|ƒq`WdS)Nr;)Úopenr]rFrgr»rÞrr~rrXrrSrrKri)r‹rFrÝZ	raw_linesÚlinesZegg_pathZ
setup_pathrQr&r&r'rášs zPackageIndex.scan_egg_linkc

s؇fdd„}xHtj|ƒD]:}y |tjj|t|jdƒƒƒƒWqtk
rPYqXqW||ƒ\}}|rÐxXt||ƒD]J}t	|ƒ\}}	|j
dƒr²|	r²|r¨|d||f7}n
ˆj|ƒˆj|ƒqrWt
jdd„|ƒSdSd	S)
z#Process the contents of a PyPI pagecsŒ|jˆjƒrˆtttjj|tˆjƒd…jdƒƒƒ}t|ƒdkrˆd|dkrˆt	|dƒ}t
|dƒ}dˆjj|j
ƒiƒ|<t|ƒt|ƒfSdS)Nr8r;r<r9rT)NN)r3r©r»rrr#r@rXrArrr¬Ú
setdefaultr1r)rÐrCÚpkgÚver)r‹r&r'Úscan­s"z(PackageIndex.process_index.<locals>.scanr9z.pyz
#egg=%s-%scSsd|jdddƒS)Nz<a href="%s#md5=%s">%s</a>r9r!r;)rO)Úmr&r&r'Ú<lambda>Ðsz,PackageIndex.process_index.<locals>.<lambda>rµN)r€r|rr#rr‚rOr$r‰rJr2Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)
r‹rBr…rêrNrèréÚnew_urlr5Úfragr&)r‹r'r˪s$ 

zPackageIndex.process_indexcCs|jd|ƒdS)NzPPage at %s links to .py file(s) without version info; an index scan is required.)Úscan_all)r‹rBr&r&r'ríÕszPackageIndex.need_version_infocGs:|j|jkr*|r |j|f|žŽ|jdƒ|j|jƒdS)Nz6Scanning index of all packages (this may take a while))r©r«rÒr¾rî)r‹r£rsr&r&r'róÛszPackageIndex.scan_allcCs~|j|j|jdƒ|jj|jƒs:|j|j|jdƒ|jj|jƒsR|j|ƒx&t|jj|jfƒƒD]}|j|ƒqhWdS)Nr8)	rîr©Úunsafe_namer¬rÁrnrTÚnot_found_in_indexr»)r‹ÚrequirementrBr&r&r'Ú
find_packagesäs
zPackageIndex.find_packagescsR|jƒ|j|ƒx,||jD]}||kr.|S|jd||ƒqWtt|ƒj||ƒS)Nz%s does not match %s)Úprescanr÷rnr½ÚsuperrÚobtain)r‹röÚ	installerrQ)Ú	__class__r&r'rúós
zPackageIndex.obtaincCsL|j|jd|ƒ|jƒsH|jƒtj|ƒtd|jjtj	j
|ƒfƒ‚dS)z-
        checker is a ContentChecker
        zValidating %%s checksum for %sz7%s validation failed for %s; possible download problem?N)r‘r½rŽrÂr]Úunlinkrršr4rFrY)r‹Úcheckerr^Útfpr&r&r'Ú
check_hashüs

zPackageIndex.check_hashcCsTxN|D]F}|jdks4t|ƒs4|jdƒs4tt|ƒƒr@|j|ƒq|jj|ƒqWdS)z;Add `urls` to the list that will be prescanned for searchesNzfile:)r®r¹r3r»rrîÚappend)r‹ÚurlsrBr&r&r'Úadd_find_linkss



zPackageIndex.add_find_linkscCs"|jrtt|j|jƒƒd|_dS)z7Scan urls scheduled for prescanning (e.g. --find-links)N)r®r»rrî)r‹r&r&r'røszPackageIndex.prescancCs<||jr|jd}}n|jd}}|||jƒ|jƒdS)Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))rnr¾rÒrôró)r‹röÚmethr£r&r&r'rõ!s
zPackageIndex.not_found_in_indexcCs~t|tƒsjt|ƒ}|rR|j|jdƒ||ƒ}t|ƒ\}}|jdƒrN|j|||ƒ}|Stj	j
|ƒrb|St|ƒ}t|j
||ƒddƒS)aLocate 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.
        r9z.pyrSN)rÄrr¹Ú
_download_urlrOrJr2Ú	gen_setupr]rFrÑr(rÊÚfetch_distribution)r‹r%ÚtmpdirrDÚfoundr5rIr&r&r'r:+s

zPackageIndex.downloadc	sàˆjd|ƒi‰d}d
‡‡‡‡‡fdd„	}|rHˆjƒˆj|ƒ||ƒ}|r`|dk	r`|||ƒ}|dkr‚ˆjdk	rzˆjƒ||ƒ}|dkr¢|r¢ˆj|ƒ||ƒ}|dkrˆjdˆr¸dpºd|ƒnˆjd|ƒ|j|jd	SdS)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.
        zSearching for %sNcs”|dkrˆ}x‚||jD]t}|jtkrJˆrJ|ˆkrˆjd|ƒdˆ|<q||ko`|jtkp`ˆ}|rˆj|jˆƒ}||_tj	j
|jƒr|SqWdS)Nz&Skipping development or system egg: %sr9)rnrKrrÒrr:rSÚdownload_locationr]rFrÑ)ÚreqÚenvrQÚtestÚloc)Ú
develop_okr‹ÚskippedÚsourcerr&r'rƒes z-PackageIndex.fetch_distribution.<locals>.findz:No local packages or working download links found for %s%sza source distribution of rµzBest match: %s)rS)N)r¾rør÷r®rÒÚcloner
)	r‹rörÚ
force_scanrrZlocal_indexrQrƒr&)rr‹rrrr'rMs0




zPackageIndex.fetch_distributioncCs"|j||||ƒ}|dk	r|jSdS)a3Obtain 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)rrS)r‹rörrrrQr&r&r'Úfetch™szPackageIndex.fetchc

Csütj|ƒ}|r*dd„t||jdƒdƒDƒp,g}t|ƒdkrÚtjj|ƒ}tjj|ƒ|krŠtjj	||ƒ}ddl
m}|||ƒsŠtj
||ƒ|}ttjj	|dƒdƒ2}	|	jd|dj|djtjj|ƒdfƒWdQRX|S|rðtd	||fƒ‚ntd
ƒ‚dS)NcSsg|]}|jr|‘qSr&)rU)raÚdr&r&r'ú
<listcomp>©sz*PackageIndex.gen_setup.<locals>.<listcomp>r9r)Úsamefilezsetup.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.)rMrNrrOrXr]rFrYÚdirnamergZsetuptools.command.easy_installrÚshutilÚcopy2råÚwriterTrUÚsplitextr)
r‹r^rIrrNrÍrYÚdstrrÙr&r&r'r¦s2

 zPackageIndex.gen_setupi cCs|jd|ƒd}zîtj|ƒ}|j|ƒ}t|tjjƒrJtd||j	|j
fƒ‚|jƒ}d}|j}d}d|kr’t|dƒ}	t
tt|	ƒƒ}|j|||||ƒt|dƒZ}
xD|j|ƒ}|rÞ|j|ƒ|
j|ƒ|d7}|j|||||ƒq Pq W|j|||
ƒWdQRX|S|r|jƒXdS)	NzDownloading %szCan't download %s: %s %srr9zcontent-lengthzContent-LengthÚwbr=)r¾r–r r¿rÄrrÅrÆrr¸r£Údl_blocksizerÚmaxrÚintÚ
reporthookrårÃrrrrÂ)r‹rBr^ÚfprþrÀÚblocknumÚbsÚsizeÚsizesrÿrŒr&r&r'Ú_download_toÑs:





zPackageIndex._download_tocCsdS)Nr&)r‹rBr^r%Zblksizer'r&r&r'r#õszPackageIndex.reporthookcCsŒ|jdƒrt|ƒSyt||jƒSttjfk
r€}z>djdd„|jDƒƒ}|r^|j	||ƒnt
d||fƒ‚WYdd}~Xntjj
k
r¢}z|Sd}~Xnætjjk
rì}z,|rÊ|j	||jƒnt
d||jfƒ‚WYdd}~Xnœtjk
r8}z.|r|j	||jƒnt
d||jfƒ‚WYdd}~XnPtjtjfk
r†}z*|rf|j	||ƒnt
d||fƒ‚WYdd}~XnXdS)Nzfile:ú cSsg|]}t|ƒ‘qSr&)r~)raÚargr&r&r'rþsz)PackageIndex.open_url.<locals>.<listcomp>z%s %szDownload error for %s: %sz;%s returned a bad status line. The server might be down, %s)r3Ú
local_openÚopen_with_authr¯r$rÚ
InvalidURLrgrsrÒrrrÅrÆÚURLErrorÚreasonÚ
BadStatusLineÚlineÚ
HTTPExceptionÚsocket)r‹rBÚwarningÚvr£r&r&r'r¿øs6
"zPackageIndex.open_urlcCsêt|ƒ\}}|r4x&d|kr0|jddƒjddƒ}qWnd}|jdƒrN|dd…}tjj||ƒ}|dksn|jd	ƒrz|j||ƒS|d
ksŒ|jdƒr˜|j||ƒS|jdƒr®|j	||ƒS|d
krÎt
jjt
j
j|ƒdƒS|j|dƒ|j||ƒSdS)Nz..Ú.ú\Ú_Z__downloaded__z.egg.zipr-Úsvnzsvn+Úgitzgit+zhg+rÙr;Tr0)rJÚreplacer2r]rFrgr3Ú
_download_svnÚ
_download_gitÚ_download_hgrr°Úurl2pathnamer#r?r¼Ú_attempt_download)r‹rDrBrr4rIr^r&r&r'rs$


zPackageIndex._download_urlcCs|j|dƒdS)NT)rÉ)r‹rBr&r&r'rî8szPackageIndex.scan_urlcCs6|j||ƒ}d|jddƒjƒkr.|j|||ƒS|SdS)Nr´zcontent-typerµ)r)rÁr1Ú_download_html)r‹rBr^rÀr&r&r'rA;szPackageIndex._attempt_downloadcCslt|ƒ}x@|D]8}|jƒrtjd|ƒrD|jƒtj|ƒ|j||ƒSPqW|jƒtj|ƒtd|ƒ‚dS)Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	rårr`r„rÂr]rýr=r)r‹rBrÀr^rÙr2r&r&r'rBBs


zPackageIndex._download_htmlcCs|jddƒd}d}|jƒjdƒrÜd|krÜtjj|ƒ\}}}}}}	|rÜ|jdƒrÜd|d	d…krÜ|d	d…jddƒ\}}tjj|ƒ\}
}|
rÜd
|
kr´|
jd
dƒ\}}
d||
f}nd|
}|}||||||	f}tjj|ƒ}|jd
||ƒt	j
d|||fƒ|S)Nr<r9rrµzsvn:ú@z//r8r;ú:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s)rAr1r3rr#r?Ú	splituserÚ
urlunparser¾r]Úsystem)r‹rBr^ÚcredsrDÚnetlocrFrbÚqrÏÚauthÚhostÚuserÚpwrCr&r&r'r=Qs$ zPackageIndex._download_svncCsptjj|ƒ\}}}}}|jddƒd}|jddƒd}d}d|krR|jddƒ\}}tjj||||dfƒ}||fS)Nú+r9r<rrCrµr=)rr#ÚurlsplitrAÚrsplitÚ
urlunsplit)rBÚ
pop_prefixrDrIrFrHròÚrevr&r&r'Ú_vcs_split_rev_from_urlfsz$PackageIndex._vcs_split_rev_from_urlcCsl|jddƒd}|j|dd\}}|jd||ƒtjd||fƒ|dk	rh|jd|ƒtjd	||fƒ|S)
Nr<r9rT)rSzDoing git clone from %s to %szgit clone --quiet %s %szChecking out %sz"(cd %s && git checkout --quiet %s))rArUr¾r]rG)r‹rBr^rTr&r&r'r>xs
zPackageIndex._download_gitcCsl|jddƒd}|j|dd\}}|jd||ƒtjd||fƒ|dk	rh|jd|ƒtjd	||fƒ|S)
Nr<r9rT)rSzDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %sz(cd %s && hg up -C -r %s -q))rArUr¾r]rG)r‹rBr^rTr&r&r'r?ˆs
zPackageIndex._download_hgcGstj|f|žŽdS)N)rr½)r‹r£rsr&r&r'r½˜szPackageIndex.debugcGstj|f|žŽdS)N)rr¾)r‹r£rsr&r&r'r¾›szPackageIndex.infocGstj|f|žŽdS)N)rrÒ)r‹r£rsr&r&r'rҞszPackageIndex.warn©r§)r¦rVNT)F)F)F)N)N)FFFN)FF)N)F)(r’r“r”r•rœrÉrºr¼rärárËrírór÷rúrrrørõr:rrrr r)r#r¿rrîrArBr=ÚstaticmethodrUr>r?r½r¾rÒÚ
__classcell__r&r&)rür'r(sL

3



+
		
#
J

)$
#z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?cCs|jdƒ}t|ƒS)Nr9)rOr)rNÚwhatr&r&r'Ú
decode_entity§s
rZcCs
tt|ƒS)z'Decode HTML entities in the given text.)Ú
entity_subrZ)Útextr&r&r'r‚¬sr‚cs‡fdd„}|S)Ncs‡‡fdd„}|S)Ncs.tjƒ}tjˆƒz
ˆ||ŽStj|ƒXdS)N)r4ÚgetdefaulttimeoutÚsetdefaulttimeout)rsrtZold_timeout)ruÚtimeoutr&r'Ú_socket_timeout³s


z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr&)rur`)r_)rur'r`²sz'socket_timeout.<locals>._socket_timeoutr&)r_r`r&)r_r'Úsocket_timeout±sracCs2tjj|ƒ}|jƒ}tj|ƒ}|jƒ}|jddƒ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µ)rr#r@ÚencodeÚbase64ÚencodestringrÈr<)rKZauth_sZ
auth_bytesZ
encoded_bytesÚencodedr&r&r'Ú_encode_authÀs

rgc@s(eZdZdZdd„Zdd„Zdd„ZdS)	Ú
Credentialz:
    A username/password pair. Use like a namedtuple.
    cCs||_||_dS)N)ÚusernameÚpassword)r‹rirjr&r&r'rœÜszCredential.__init__ccs|jV|jVdS)N)rirj)r‹r&r&r'Ú__iter__àszCredential.__iter__cCsdt|ƒS)Nz%(username)s:%(password)s)Úvars)r‹r&r&r'Ú__str__äszCredential.__str__N)r’r“r”r•rœrkrmr&r&r&r'rh×srhc@s0eZdZdd„Zedd„ƒZdd„Zdd„Zd	S)
Ú
PyPIConfigcCsPtjdddgdƒ}tjj||ƒtjjtjjdƒdƒ}tjj	|ƒrL|j
|ƒdS)z%
        Load from ~/.pypirc
        rirjÚ
repositoryrµú~z.pypircN)ÚdictÚfromkeysrÚRawConfigParserrœr]rFrgÚ
expanduserrÑrÃ)r‹ÚdefaultsÚrcr&r&r'rœés
zPyPIConfig.__init__cs&‡fdd„ˆjƒDƒ}ttˆj|ƒƒS)Ncs g|]}ˆj|dƒjƒr|‘qS)ro)rÁr)raÚsection)r‹r&r'r÷sz2PyPIConfig.creds_by_repository.<locals>.<listcomp>)ÚsectionsrqrÚ_get_repo_cred)r‹Zsections_with_repositoriesr&)r‹r'Úcreds_by_repositoryôszPyPIConfig.creds_by_repositorycCs6|j|dƒjƒ}|t|j|dƒjƒ|j|dƒjƒƒfS)Nrorirj)rÁrrh)r‹rwÚrepor&r&r'ryýszPyPIConfig._get_repo_credcCs*x$|jjƒD]\}}|j|ƒr|SqWdS)zŒ
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)rzÚitemsr3)r‹rBroÚcredr&r&r'Úfind_credentials
zPyPIConfig.find_credentialN)r’r“r”rœÚpropertyrzryr~r&r&r&r'rnès	rncCs:tjj|ƒ\}}}}}}|jdƒr,tjdƒ‚|d
krFtjj|ƒ\}}	nd}|s~tƒj|ƒ}
|
r~t	|
ƒ}|
j
|f}tjd|žŽ|rÄdt
|ƒ}||	||||f}tjj|ƒ}
tjj|
ƒ}|jd|ƒntjj|ƒ}|jd	tƒ||ƒ}|r6tjj|jƒ\}}}}}}||kr6||	kr6||||||f}tjj|ƒ|_|S)z4Open a urllib2 request, handling HTTP authenticationrDznonnumeric port: ''ÚhttpÚhttpsNú*Authenticating as %s for %s (from .pypirc)zBasic Ú
Authorizationz
User-Agent)r€r)r‚)rr#r?r2rr.rErnr~r~rirr¾rgrFr°ÚRequestÚ
add_headerÚ
user_agentrB)rBr¯rDrIrFÚparamsrHròrKrLr}r¾rCrñr°r$Ús2Úh2Úpath2Zparam2Zquery2Zfrag2r&r&r'r-s6


r-cCs|S)Nr&)rBr&r&r'Ú
fix_sf_url?sr‹cCstjj|ƒ\}}}}}}tjj|ƒ}tjj|ƒr<tjj|ƒS|j	dƒrêtjj
|ƒrêg}xˆtj|ƒD]b}	tjj||	ƒ}
|	dkržt
|
dƒ}|jƒ}WdQRXPntjj
|
ƒr²|	d7}	|jdj|	dƒqbWd}
|
j|dj|ƒd	}d\}}n
d\}}}ddi}tj|ƒ}tjj|||||ƒS)z7Read a local path, with special support for directoriesr8z
index.htmlÚrNz<a href="{name}">{name}</a>)r4zB<html><head><title>{url}</title></head><body>{files}</body></html>rb)rBÚfileséÈÚOKé”úPath not foundú	Not foundzcontent-typez	text/html)rŽr)rr‘r’)rr#r?r°r@r]rFÚisfiler±r2rÓrÕrgrårÃrÚformatrÚStringIOrÅrÆ)rBrDrErFÚparamrHròr^rrÏÚfilepathr$ÚbodyrÎÚstatusÚmessagerÀZbody_streamr&r&r'r,Cs,


r,)N)N)N)N)r )Zr•Úsysr]r`rr4rdr˜rßÚ	functoolsrZsetuptools.externrZsetuptools.extern.six.movesrrrrr"Ú
pkg_resourcesrr	r
rrr
rrrrrrrrÚ	distutilsrZdistutils.errorsrÚfnmatchrZsetuptools.py27compatrZsetuptools.py33compatrZsetuptools.wheelrr¤rMÚIr€rïrNr¹rArWÚ__all__Z_SOCKET_TIMEOUTZ_tmplr”rUr†r(rrJrrLr_rrrrwr{r‰ÚobjectrŠr–rrðr[rZr‚rargrhrsrnr°r±r-r‹r,r&r&r&r'Ú<module>s|<
	

!
"

!
&.