3

Q'íc€ã@sZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZyddlZdZWnek
r”dZYnXddlmZddlmZddlZddlmZmZddlmZdd	lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-dd
l.m/Z/ddl0m1Z1ddl2m3Z3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;ddl<m=Z=m>Z>ddl?m@Z@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHddlImJZJddlKmLZLddlMmNZNddlOmPZPddlQmRZRdddd d!d"d#d$d%d&d'gZSejTeUƒZVd(d)„ZWGd*d+„d+e@ƒZXGd,d-„d-e=ƒZYGd.d/„d/eNƒZZGd0d1„d1e>ƒZ[Gd2d3„d3e:j\ƒZ]dWd4d„Z^ej_d5ej`ƒZaej_d6ej`ƒZbd7d„Zcd8d„Zdd9d „Zed:d!„Zfd;d"„Zgd<d=„Zhd>d$„Zid?d%„Zjd@dA„ZkdBdC„ZldDdE„ZmdFdG„ZndXdHd&„ZodYdId#„ZpdJdK„ZqGdLdM„dMeRjrƒZsdZdNd'„ZtdOdP„ZudQdR„ZvdSdT„ZwdUdV„ZxdS)[é)Úabsolute_importNTF)Úparse)Úrequest)ÚInstallationErrorÚHashMismatch)ÚPyPI)
ÚsplitextÚrmtreeÚformat_sizeÚdisplay_pathÚ
backup_dirÚask_path_existsÚunpack_fileÚARCHIVE_EXTENSIONSÚconsumeÚcall_subprocess)Úauto_decode)Úcheck_path_owner)Ú
indent_log)ÚSETUPTOOLS_SHIM)Úlibc_ver)ÚDownloadProgressBarÚDownloadProgressSpinner)Úwrite_delete_marker_file)Úvcs)ÚrequestsÚsix)ÚBaseAdapterÚHTTPAdapter)ÚAuthBaseÚ
HTTPBasicAuth)ÚCONTENT_CHUNK_SIZEÚResponse)Úget_netrc_auth)ÚCaseInsensitiveDict)Úurllib3)ÚCacheControlAdapter)Ú	FileCache)Ú	LockError)Ú
xmlrpc_clientÚget_file_contentÚis_urlÚurl_to_pathÚpath_to_urlÚis_archive_fileÚunpack_vcs_linkÚunpack_file_urlÚ
is_vcs_urlÚis_file_urlÚunpack_http_urlÚ
unpack_urlcCsdtjdœtjƒdtjƒidœ}|dddkrBtjƒ|dd<n’|dddkr’tjjd	krntjd
d…}ntj}djd
d„|Dƒƒ|dd<nB|dddkr´tjƒ|dd<n |dddkrÔtjƒ|dd<tjj	dƒrJddl
m}tt
dd„tdddg|jƒƒƒƒ}tt
dd„tddgtƒƒƒƒ}|r<||d<|rJ||d<tjj	dƒr|tjƒdr|dtjƒddœ|d<tjƒrštjƒ|jdiƒd<tjƒr¸tjƒ|jdiƒd<tjƒrÎtjƒ|d<tròtjd
d …d)kròtj|d"<d#j|tj|d*d&d'd(S)+z6
    Return a string representing the user agent.
    Úpip)ÚnameÚversionr6)Ú	installerÚpythonÚimplementationr:ÚCPythonr7ÚPyPyÚfinalNéÚ.cSsg|]}t|ƒ‘qS©)Ústr)Ú.0Úxr@r@ú+/tmp/pip-build-l_bcah40/pip/pip/download.pyú
<listcomp>Sszuser_agent.<locals>.<listcomp>ÚJythonÚ
IronPythonÚlinuxr)ÚdistrocSs|dS)Nér@)rCr@r@rDÚ<lambda>_szuser_agent.<locals>.<lambda>ÚidcSs|dS)NrJr@)rCr@r@rDrKcsÚlibÚlibcrIÚdarwinÚmacOSÚsystemÚreleaseÚcpuééÚopenssl_versionz9{data[installer][name]}/{data[installer][version]} {json}ú,ú:T)Ú
separatorsÚ	sort_keys)ÚdataÚjson)rTrU)rWrX)r5Ú__version__ÚplatformÚpython_versionÚpython_implementationÚsysÚpypy_version_infoÚreleaselevelÚjoinÚ
startswithÚpip._vendorrIÚdictÚfilterÚzipÚlinux_distributionrÚmac_verrQÚ
setdefaultrRÚmachineÚHAS_TLSÚversion_infoÚsslÚOPENSSL_VERSIONÚformatr\Údumps)r[rbrIÚdistro_infosrNr@r@rDÚ
user_agent?sP




ruc@s.eZdZddd„Zdd„Zdd„Zdd	„Zd
S)ÚMultiDomainBasicAuthTcCs||_i|_dS)N)Ú	promptingÚ	passwords)Úselfrwr@r@rDÚ__init__ƒszMultiDomainBasicAuth.__init__cCsÖtj|jƒ}|jjddƒd}tj|dd…|f|dd…ƒ|_|jj|dƒ\}}|dkrn|j|jƒ\}}|dkr˜|dkr˜t	|jƒ}|r|nd\}}|s |rÄ||f|j|<t
|p¶d|p¼dƒ|ƒ}|jd|jƒ|S)	Nú@rJrTÚÚresponseéÿÿÿÿ)NN)NN)
Úurllib_parseÚurlparseÚurlÚnetlocÚrsplitÚ
urlunparserxÚgetÚparse_credentialsr#r Ú
register_hookÚ
handle_401)ryÚreqÚparsedr‚ÚusernameÚpasswordÚ
netrc_authr@r@rDÚ__call__‡s&
zMultiDomainBasicAuth.__call__cKs |jdkr|S|js|Stj|jƒ}tjjd|jƒ}t	j	dƒ}|sH|rX||f|j
|j<|j|jj
ƒt|ppd|pvdƒ|jƒ}|jj|f|Ž}|jj|ƒ|S)Ni‘z
User for %s: z
Password: r|)Ústatus_coderwrr€rrÚmovesÚinputr‚ÚgetpassrxÚcontentÚrawÚrelease_connr rÚ
connectionÚsendÚhistoryÚappend)ryÚrespÚkwargsrŠr‹rŒr‰Únew_respr@r@rDrˆ¨s


zMultiDomainBasicAuth.handle_401cCs8d|kr4|jddƒd}d|kr,|jddƒS|dfSdS)Nr{rJrrX)NN)rƒÚsplit)ryr‚Úuserinfor@r@rDr†Êsz&MultiDomainBasicAuth.parse_credentialsN)T)Ú__name__Ú
__module__Ú__qualname__rzrŽrˆr†r@r@r@rDrvs
!"rvc@seZdZddd„Zdd„ZdS)ÚLocalFSAdapterNc
Cs®t|jƒ}tƒ}d|_|j|_ytj|ƒ}	Wn.tk
rZ}
zd|_|
|_WYdd}
~
XnPXtj	j
|	jdd}tj
|ƒdp~d}t||	j|dœƒ|_t|dƒ|_|jj|_|S)	NéÈi”T)Úusegmtrz
text/plain)zContent-TypezContent-Lengthz
Last-ModifiedÚrb)r,rr"rÚosÚstatÚOSErrorr”ÚemailÚutilsÚ
formatdateÚst_mtimeÚ	mimetypesÚ
guess_typer$Úst_sizeÚheadersÚopenÚclose)
ryrÚstreamÚtimeoutÚverifyÚcertÚproxiesÚpathnameršÚstatsÚexcÚmodifiedÚcontent_typer@r@rDr—Õs$

zLocalFSAdapter.sendcCsdS)Nr@)ryr@r@rDr²ðszLocalFSAdapter.close)NNNNN)rŸr r¡r—r²r@r@r@rDr¢Ós
r¢csDeZdZdZ‡fdd„Z‡fdd„Z‡fdd„Z‡fdd	„Z‡ZS)
Ú
SafeFileCachezw
    A file based cache which is safe to use even when the target directory may
    not be accessible or writable.
    cs4tt|ƒj||Žt|jƒs0tjd|jƒd|_dS)NzßThe directory '%s' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.)Úsuperr½rzrÚ	directoryÚloggerÚwarning)ryÚargsr›)Ú	__class__r@rDrzús
zSafeFileCache.__init__c
s@|jdkrdSytt|ƒj||ŽStttfk
r:YnXdS)N)r¿r¾r½r…r(r¨ÚIOError)ryrÂr›)rÃr@rDr…s
zSafeFileCache.getc
s@|jdkrdSytt|ƒj||ŽStttfk
r:YnXdS)N)r¿r¾r½Úsetr(r¨rÄ)ryrÂr›)rÃr@rDrÅs
zSafeFileCache.setc
s@|jdkrdSytt|ƒj||ŽStttfk
r:YnXdS)N)r¿r¾r½Údeleter(r¨rÄ)ryrÂr›)rÃr@rDrÆ(s
zSafeFileCache.delete)	rŸr r¡Ú__doc__rzr…rÅrÆÚ
__classcell__r@r@)rÃrDr½ôs


r½c@seZdZdd„ZdS)ÚInsecureHTTPAdaptercCsd|_d|_dS)NÚ	CERT_NONE)Ú	cert_reqsÚca_certs)ryÚconnrrµr¶r@r@rDÚcert_verify8szInsecureHTTPAdapter.cert_verifyN)rŸr r¡rÎr@r@r@rDrÉ6srÉcs,eZdZdZ‡fdd„Z‡fdd„Z‡ZS)Ú
PipSessionNc	sÔ|jddƒ}|jddƒ}|jdgƒ}tt|ƒj||Žtƒ|jd<tƒ|_tj	|dgdd}|rvt
t|d	d
|d}n
t|d}t
|d}|jd
|ƒ|jd|ƒ|jdtƒƒx|D]}|jdj|ƒ|ƒq¶WdS)NÚretriesrÚcacheÚinsecure_hostsz
User-Agenti÷gÐ?)ÚtotalÚstatus_forcelistÚbackoff_factorT)Úuse_dir_lock)rÑÚmax_retries)r×zhttps://zhttp://zfile://zhttps://{0}/)Úpopr¾rÏrzrur°rvÚauthr%ÚRetryr&r½rrÉÚmountr¢rr)	ryrÂr›rÐrÑrÒÚsecure_adapterÚinsecure_adapterÚhost)rÃr@rDrzAs*




zPipSession.__init__cs(|jd|jƒtt|ƒj||f|ž|ŽS)Nr´)rlr´r¾rÏr)ryÚmethodrrÂr›)rÃr@rDr}szPipSession.request)rŸr r¡r´rzrrÈr@r@)rÃrDrÏ=s<rÏc
CsL|dkrtdƒ‚tj|ƒ}|rè|jdƒjƒ}|dkrR|rR|jdƒrRtd||fƒ‚|dkrÊ|jddƒd}|jdd	ƒ}t	j
|ƒ}|r¢|jdƒd|jd
dƒd}tj|ƒ}|jd	ƒrÄd	|j
d	ƒ}|}n|j|ƒ}|jƒ|j|jfSy&t|dƒ}t|jƒƒ}WdQRXWn4tk
rB}	ztdt|	ƒƒ‚WYdd}	~	XnX||fS)
zGets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.NzAget_file_content() missing 1 required keyword argument: 'session'rJÚfileÚhttpz6Requirements file %s references URL %s, which is localrXú\ú/ú|r¥z$Could not open requirements file: %s)Ú	TypeErrorÚ
_scheme_reÚsearchÚgroupÚlowerrerrÚreplaceÚ_url_slash_drive_reÚmatchrÚunquoteÚlstripr…Úraise_for_statusrÚtextr±rÚreadrÄrA)
rÚ
comes_fromÚsessionrìÚschemeÚpathršÚfr“rºr@r@rDr*…s>





 z^(http|https|file):z/*([a-z])\|cCs6d|krdS|jddƒdjƒ}|ddddgtjkS)	z)Returns true if the name looks like a URLrXFrJrráÚhttpsràÚftp)rrérÚall_schemes)r6rôr@r@rDr+²scCsH|jdƒstd|ƒ‚tj|ƒ\}}}}}|r6d|}tj||ƒ}|S)z(
    Convert a file: URL to a path.
    zfile:z4You can only turn file: urls into filenames (not %r)z\\)reÚAssertionErrorrÚurlsplitÚurllib_requestÚurl2pathname)rÚ_r‚rõr@r@rDr,ºs
cCs*tjjtjj|ƒƒ}tjdtj|ƒƒ}|S)zh
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    zfile:)r¦rõÚnormpathÚabspathrÚurljoinrüÚpathname2url)rõrr@r@rDr-ËscCs t|ƒdjƒ}|tkrdSdS)z9Return True if `name` is a considered as an archive file.rJTF)rrér)r6Úextr@r@rDr.ÕscCst|ƒ}|j|ƒdS)N)Ú_get_used_vcs_backendÚunpack)ÚlinkÚlocationÚvcs_backendr@r@rDr/ÝscCs.x(tjD]}|j|jkr||jƒ}|SqWdS)N)rÚbackendsrôÚschemesr)rÚbackendrr@r@rDrâs
rcCstt|ƒƒS)N)Úboolr)rr@r@rDr1éscCs|jjƒjdƒS)Nzfile:)rrére)rr@r@rDr2íscCst|jƒ}tjj|ƒS)z’Return whether a file:// Link points to a directory.

    ``link`` must not have any other scheme but file://. Call is_file_url()
    first.

    )r,Úurl_without_fragmentr¦rõÚisdir)rÚ	link_pathr@r@rDÚ
is_dir_urlñs
rcOs|S)Nr@)ÚiterablerÂr›r@r@rDÚ_progress_indicatorüsrc

sLytˆjdƒ}Wntttfk
r0d}YnXtˆddƒ}tjƒtj	krRd}n&|r\d}n|dkrjd}n|std}nd}|j
}‡fdd	„}‡fd
d„}	t}
|jt
jkr¬|}n|j}|rð|rÚtjd|t|ƒƒt|d
j}
ntjd|ƒtƒj}
n |rtjd|ƒntjd|ƒtjd|ƒ|	|
|tƒtƒƒ}|r@|j|ƒnt|ƒdS)Nzcontent-lengthrÚ
from_cacheFé(ièTc3s\y$xˆjj|ddD]
}|VqWWn2tk
rVxˆjj|ƒ}|sHP|Vq6WYnXdS)NF)Údecode_content)r”r³ÚAttributeErrorrñ)Ú
chunk_sizeÚchunk)ršr@rDÚ	resp_readsz _download_url.<locals>.resp_readc3s"x|D]}ˆj|ƒ|VqWdS)N)Úwrite)Úchunksr)Úcontent_filer@rDÚwritten_chunks:s

z%_download_url.<locals>.written_chunkszDownloading %s (%s))ÚmaxzDownloading %szUsing cached %szDownloading from URL %si@œ)Úintr°Ú
ValueErrorÚKeyErrorråÚgetattrrÀÚgetEffectiveLevelÚloggingÚINFOÚshow_urlrr‚rr
Úinfor
rÚiterrÚdebugr!Úcheck_against_chunksr)
ršrrÚhashesÚtotal_lengthÚcached_respÚ
show_progressr&rrÚprogress_indicatorrÚdownloaded_chunksr@)rršrDÚ
_download_urlsL
%
r1cCsÎd}tjj||jƒ}tjj|ƒrªtdt|ƒdƒ}|dkr@d}nj|dkrdtjdt|ƒƒtj	|ƒnF|dkr˜t
|ƒ}tjd	t|ƒt|ƒƒtj||ƒn|dkrªt
jd
ƒ|rÊtj||ƒtjdt|ƒƒdS)NTz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abortÚiÚwÚbÚaFzDeleting %szBacking up %s to %srJzSaved %s)r2r3r4r5r~)r¦rõrdÚfilenameÚexistsr
rrÀrÁÚremoverÚshutilÚmoveraÚexitÚcopyr')r6rrr<Údownload_locationr}Ú	dest_filer@r@rDÚ
_copy_file`s.

r?c	Cs˜|dkrtdƒ‚tjddƒ}d}|r0t|||ƒ}|rH|}tj|ƒd}nt||||ƒ\}}t||||ƒ|r~|r~t|||ƒ|sŒt	j
|ƒt|ƒdS)Nz@unpack_http_url() missing 1 required keyword argument: 'session'z-unpackzpip-r)råÚtempfileÚmkdtempÚ_check_download_dirr­r®Ú_download_http_urlrr?r¦Úunlinkr	)	rrÚdownload_dirrór+Útemp_dirÚalready_downloaded_pathÚ	from_pathr¼r@r@rDr3{s,


cCs®t|jƒ}t|ƒrHtjj|ƒr&t|ƒtj||dd|rDt	j
dƒdS|rV|j|ƒd}|rjt|||ƒ}|rt|}n|}t
j|ƒd}t||||ƒ|rª|rªt|||ƒdS)z‘Unpack link into location.

    If download_dir is provided and link points to a file, make a copy
    of the link file inside download_dir.
    T)Úsymlinksz*Link is a directory, ignoring download_dirNr)r,r
rr¦rõrr	r9ÚcopytreerÀr'Úcheck_against_pathrBr­r®rr?)rrrEr+rrGrHr¼r@r@rDr0¢s,



c
Cs´tjj|ƒrt|ƒd}tjg}|jdƒ|jt|ƒ|jdƒ|d|g7}tj	d|ƒt
ƒt||ddWdQRXtjj|tj
|ƒd	ƒ}tj	d
||ƒt||ddddS)zÐCopy distribution files in `link_path` to `location`.

    Invoked when user requests to install a local directory. E.g.:

        pip install .
        pip install ~/dev/git-repos/python-prompt-toolkit

    zsetup.pyz-cÚsdistz
--dist-dirzRunning setup.py sdist for %sF)ÚcwdÚshow_stdoutNrzUnpacking sdist %s into %s)r¼r)r¦rõrr	raÚ
executabler™rrÀr'rrrdÚlistdirr)rrÚsetup_pyÚ
sdist_argsrLr@r@rDÚ_copy_dist_from_dirÒs

rSc@s$eZdZdZddd„Zd	dd„ZdS)
ÚPipXmlrpcTransportzRProvide a `xmlrpclib.Transport` implementation via a `PipSession`
    object.
    FcCs*tjj||ƒtj|ƒ}|j|_||_dS)N)r)Ú	Transportrzrr€rôÚ_schemeÚ_session)ryÚ	index_urlróÚuse_datetimeÚindex_partsr@r@rDrzûs
zPipXmlrpcTransport.__init__c
Cs|j||dddf}tj|ƒ}y6ddi}|jj|||dd}|jƒ||_|j|jƒSt	j
k
rŠ}	ztjd|	j
j|ƒ‚WYdd}	~	XnXdS)NzContent-Typeztext/xmlT)r[r°r³zHTTP error %s while getting %s)rVrr„rWÚpostrïÚverboseÚparse_responser”rÚ	HTTPErrorrÀÚcriticalr}r)
ryrÞÚhandlerÚrequest_bodyr\Úpartsrr°r}rºr@r@rDrs


zPipXmlrpcTransport.requestN)F)F)rŸr r¡rÇrzrr@r@r@rDrTös
rTcCs^t|ƒrt||ƒn:t|ƒr.t||||dn |dkr<tƒ}t|||||d|rZt|ƒdS)avUnpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    )r+N)r1r/r2r0rÏr3r)rrrEÚ
only_downloadrór+r@r@rDr4scCstjj|ƒS)zJ
    Sanitize the "filename" value from a Content-Disposition header.
    )r¦rõÚbasename)r6r@r@rDÚsanitize_content_filename;srecCs,tj|ƒ\}}|jdƒ}|r$t|ƒ}|p*|S)zƒ
    Parse the "filename" value from a Content-Disposition header, and
    return the default filename if the result is empty.
    r6)ÚcgiÚparse_headerr…re)Úcontent_dispositionÚdefault_filenameÚ_typeÚparamsr6r@r@rDÚparse_content_dispositionCs

rlc
Cs*|jjddƒd}y |j|ddidd}|jƒWn8tjk
rj}ztjd|jj	|ƒ‚WYd	d	}~XnX|j
jd
dƒ}|j}|j
jdƒ}	|	ršt|	|ƒ}t
|ƒd}
|
sÀtj|ƒ}
|
rÀ||
7}|
rð|j|jkrðtjj
|jƒd}
|
rð||
7}tjj||ƒ}t|d
ƒ}t||||ƒWd	QRX||fS)z6Download link url into temp_dir using provided sessionú#rJrzAccept-EncodingÚidentityT)r°r³zHTTP error %s while getting %sNzcontent-typer|zcontent-dispositionÚwb)rrr…rïrr^rÀr_r}rr°r6rlrr­Úguess_extensionr¦rõrdr±r1)
rrórFr+Ú
target_urlršrºr¼r6rhrÚ	file_pathrr@r@rDrCRs:

rCcCsntjj||jƒ}tjj|ƒrjtjd|ƒ|rfy|j|ƒWn*tk
rdtj	d|ƒtj
|ƒdSX|SdS)z† Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    zFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.N)r¦rõrdr6r7rÀr'rKrrÁrD)rrEr+Ú
download_pathr@r@rDrBŠs
rB)NN)NNN)NN)NFNN)yÚ
__future__rrfÚemail.utilsr©r’r\r$r­r¦r^Úrer9rar@rprnÚImportErrorZpip._vendor.six.moves.urllibrrrrür5Úpip.exceptionsrrÚ
pip.modelsrÚ	pip.utilsrr	r
rrr
rrrrÚpip.utils.encodingrÚpip.utils.filesystemrÚpip.utils.loggingrÚpip.utils.setuptools_buildrÚpip.utils.glibcrÚpip.utils.uirrÚ
pip.locationsrÚpip.vcsrrfrrÚpip._vendor.requests.adaptersrrZpip._vendor.requests.authrr Zpip._vendor.requests.modelsr!r"Zpip._vendor.requests.utilsr#Zpip._vendor.requests.structuresr$Zpip._vendor.requests.packagesr%Zpip._vendor.cachecontrolr&Úpip._vendor.cachecontrol.cachesr'Zpip._vendor.lockfiler(Zpip._vendor.six.movesr)Ú__all__Ú	getLoggerrŸrÀrurvr¢r½rÉÚSessionrÏr*ÚcompileÚIrærër+r,r-r.r/rr1r2rrr1r?r3r0rSrUrTr4rerlrCrBr@r@r@rDÚ<module>s 
0
BR!BH
)
`
&
0$
'8