3 PfO@s^ddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZyddlZdZWnek rdZYnXddlmZddlmZddlZddlmZmZddlmZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)dd l*m+Z+dd l,m-Z-dd l.m/Z/ddl0m1Z1ddl2m3Z3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;ddlZ>ddl?m@Z@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHddl9mIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQdddd d!d"d#d$d%d&d'd(d)g ZRejSeTZUd*d+ZVGd,d-d-e@ZWGd.d/d/e=ZXGd0d1d1eMZYGd2d3d3e>ZZGd4d5d5e:j[Z\dWd6dZ]e j^d7e j_Z`e j^d8e j_Zad9dZbd:dZcd;d Zddd?Zgd@d$ZhdAd%ZidBdCZjdDdEZkdFdGZldHdIZmdXdJd&ZndYdKd#ZodLdMZpGdNdOdOeQjqZrdZdPd'ZsdQd)ZtdRd(ZudSdTZvdUdVZwdS)[)absolute_importNTF)parse)request)InstallationError HashMismatch)PyPI) splitextrmtree format_size display_path backup_dirask_path_exists unpack_fileARCHIVE_EXTENSIONSconsumecall_subprocess) auto_decode)check_path_owner) indent_log)SETUPTOOLS_SHIM)libc_ver)DownloadProgressBarDownloadProgressSpinner)write_delete_marker_file)vcs)requestssix) BaseAdapter HTTPAdapter)AuthBase HTTPBasicAuth)CONTENT_CHUNK_SIZEResponse)get_netrc_auth)CaseInsensitiveDict)urllib3)CacheControlAdapter) FileCache) LockError) xmlrpc_clientget_file_contentis_url url_to_path path_to_urlis_archive_fileunpack_vcs_linkunpack_file_url is_vcs_url is_file_urlunpack_http_url unpack_urlparse_content_dispositionsanitize_content_filenamecCs dtjdtjdtjid}|dddkrBtj|dd<n|dddkrtjjd krntjd d }ntj}d jd d|D|dd<nB|dddkrtj|dd<n |dddkrtj|dd<tjj drJddl m }t t ddtdddg|j}t t ddtddgt}|r<||d<|rJ||d<tjj dr|tjdr|dtjdd|d<tjrtj|jdid<tjrtj|jdid<tjrtj|d<trtjd d d)krtj|d"<d#j|tj|d*d&d'd(S)+z6 Return a string representing the user agent. pip)nameversionr8)Z installerpythonimplementationr;ZCPythonr9ZPyPyfinalN.cSsg|] }t|qS)str).0xr?r?/usr/lib/python3.6/download.py Tszuser_agent..ZJythonZ IronPythonlinuxr)distrocSs|dS)Nr?)rBr?r?rC`szuser_agent..idcSs|dS)NrGr?)rBr?r?rCrHdsliblibcrFdarwinZmacOSsystemreleaseZcpuZopenssl_versionz9{data[installer][name]}/{data[installer][version]} {json},:T)Z separatorsZ sort_keys)datajson)rOrP)rQrR)r7 __version__platformZpython_versionZpython_implementationsyspypy_version_info releaseleveljoin startswith pip._vendorrFdictfilterzipZlinux_distributionrZmac_verrM setdefaultrNmachineHAS_TLS version_infosslZOPENSSL_VERSIONformatrTdumps)rSrXrFZ distro_infosrKr?r?rC user_agent@sP        rgc@s.eZdZd ddZddZddZdd Zd S) MultiDomainBasicAuthTcCs||_i|_dS)N) prompting passwords)selfrir?r?rC__init__szMultiDomainBasicAuth.__init__cCstj|j}|jjddd}tj|dd|f|dd|_|jj|d\}}|dkrn|j|j\}}|dkr|dkrt |j}|r|nd\}}|s|r||f|j|<t |pd|pd|}|j d|j |S) N@rGrOresponse)NN)NN) urllib_parseurlparseurlnetlocrsplit urlunparserjgetparse_credentialsr#r Z register_hook handle_401)rkreqparsedrtusernamepasswordZ netrc_authr?r?rC__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)Niz User for %s: z Password: rn) status_coderirqrrrsrZmovesinputrtgetpassrjcontentrawZ release_connr rZ connectionsendhistoryappend)rkrespkwargsr{r|r}rzZnew_respr?r?rCrys     zMultiDomainBasicAuth.handle_401cCs8d|kr4|jddd}d|kr,|jddS|dfSdS)NrmrGrrR)NN)rusplit)rkrtZuserinfor?r?rCrxs  z&MultiDomainBasicAuth.parse_credentialsN)T)__name__ __module__ __qualname__rlr~ryrxr?r?r?rCrhs !"rhc@seZdZdddZddZdS)LocalFSAdapterNc Cst|j}t}d|_|j|_ytj|} Wn.tk rZ} zd|_| |_WYdd} ~ XnPXtj j | j dd} t j |dp~d} t| | j| d|_t|d|_|jj|_|S) NiT)Zusegmtrz text/plain)z Content-TypezContent-Lengthz Last-Modifiedrb)r,rsr"rosstatOSErrorremailZutilsZ formatdatest_mtime mimetypes guess_typer$st_sizeheadersopenclose) rkrstreamtimeoutverifycertZproxiespathnamerZstatsexcZmodified content_typer?r?rCrs$    zLocalFSAdapter.sendcCsdS)Nr?)rkr?r?rCrszLocalFSAdapter.close)NNNNN)rrrrrr?r?r?rCrs rcsDeZdZdZfddZfddZfddZfdd ZZS) SafeFileCachezw A file based cache which is safe to use even when the target directory may not be accessible or writable. cs4tt|j||t|js0tjd|jd|_dS)NzThe 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.)superrrlr directoryloggerwarning)rkargsr) __class__r?rCrls  zSafeFileCache.__init__c s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrrwr(rIOError)rkrr)rr?rCrws  zSafeFileCache.getc s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrsetr(rr)rkrr)rr?rCrs  zSafeFileCache.setc s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrdeleter(rr)rkrr)rr?rCr)s  zSafeFileCache.delete) rrr__doc__rlrwrr __classcell__r?r?)rrCrs   rc@seZdZddZdS)InsecureHTTPAdaptercCsd|_d|_dS)NZ CERT_NONE)Z cert_reqsZca_certs)rkZconnrsrrr?r?rC cert_verify9szInsecureHTTPAdapter.cert_verifyN)rrrrr?r?r?rCr7srcs,eZdZdZfddZfddZZS) PipSessionNc s|jdd}|jdd}|jdg}tt|j||t|jd<t|_tj |dgdd}|rvt t |d d |d }n t |d }t |d }|jd ||jd||jdtx|D]}|jdj||qWdS)Nretriesrcacheinsecure_hostsz User-Agentig?)ZtotalZstatus_forcelistZbackoff_factorT)Z use_dir_lock)r max_retries)rzhttps://zhttp://zfile://z https://{0}/)poprrrlrgrrhZauthr%ZRetryr&rrrZmountrre) rkrrrrrZsecure_adapterZinsecure_adapterhost)rr?rCrlBs*           zPipSession.__init__cs(|jd|jtt|j||f||S)Nr)r`rrrr)rkmethodrsrr)rr?rCr~szPipSession.request)rrrrrlrrr?r?)rrCr>s             z^(http|https|file):z /*([a-z])\|cCs6d|kr dS|jdddj}|ddddgtjkS) z)Returns true if the name looks like a URLrRFrGrrZhttpsrZftp)rrrZ all_schemes)r8rr?r?rCr+scCsH|jdstd|tj|\}}}}}|r6d|}tj||}|S)z( Convert a file: URL to a path. zfile:z4You can only turn file: urls into filenames (not %r)z\\)r[AssertionErrorrqZurlspliturllib_requestZ url2pathname)rs_rtrr?r?rCr,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:)rrnormpathabspathrqZurljoinrZ pathname2url)rrsr?r?rCr-scCs t|dj}|tkrdSdS)z9Return True if `name` is a considered as an archive file.rGTF)rrr)r8extr?r?rCr.scCst|}|j|dS)N)_get_used_vcs_backendunpack)linklocation vcs_backendr?r?rCr/scCs.x(tjD]}|j|jkr||j}|SqWdS)N)rZbackendsrZschemesrs)rZbackendrr?r?rCrs   rcCs tt|S)N)boolr)rr?r?rCr1scCs|jjjdS)Nzfile:)rsrr[)rr?r?rCr2scCst|j}tjj|S)zReturn 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_fragmentrrisdir)r link_pathr?r?rC is_dir_urls rcOs|S)Nr?)iterablerrr?r?rC_progress_indicatorsrc sLytjd}Wntttfk r0d}YnXtdd}tjtj krRd}n&|r\d}n|dkrjd}n|std}nd}|j }fdd }fd d } t } |j t j kr|} n|j} |r|rtjd | t|t|d j} ntjd| tj} n |rtjd| n tjd| tjd|| | |tt} |r@|j| nt| dS)Nzcontent-lengthrZ from_cacheF(iTc 3s\y$xjj|ddD] }|VqWWn2tk rVxjj|}|sHP|Vq6WYnXdS)NF)Zdecode_content)rrAttributeErrorr)Z chunk_sizechunk)rr?rC resp_reads  z _download_url..resp_readc3s"x|D]}j||VqWdS)N)write)Zchunksr) content_filer?rCwritten_chunks;s  z%_download_url..written_chunkszDownloading %s (%s))maxzDownloading %szUsing cached %szDownloading from URL %si@)intr ValueErrorKeyErrorrgetattrrZgetEffectiveLevelloggingINFOshow_urlrrtrrinfor riterrdebugr!Zcheck_against_chunksr) rrrhashesZ total_lengthZ cached_respZ show_progressrrrZprogress_indicatorrsZdownloaded_chunksr?)rrrC _download_urlsL   %       rcCsd}tjj||j}tjj|rtdt|d }|dkr@d}nj|dkrdtjdt|tj |nF|dkrt |}tjd t|t|t j ||n|dkrt jd |rt j||tjd t|dS)NTz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abortiwbaFz Deleting %szBacking up %s to %srGzSaved %s)rrrrrp)rrrZfilenameexistsr r rrremover shutilZmoverWexitcopyr)rrrrZdownload_locationroZ dest_filer?r?rC _copy_fileas.     rc Cs|dkrtdtjdd}d}|r0t|||}|rH|}tj|d}nt||||\}}t|||||r~| r~t||||st j |t |dS)Nz@unpack_http_url() missing 1 required keyword argument: 'session'z-unpackzpip-r) rtempfileZmkdtemp_check_download_dirrr_download_http_urlrrrunlinkr ) rr download_dirrrtemp_diralready_downloaded_path from_pathrr?r?rCr3|s,     cCst|j}t|rHtjj|r&t|tj||dd|rDt j ddS|rV|j |d}|rjt |||}|rt|}n|}t j|d}t|||||r| rt|||dS)zUnpack 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)Zsymlinksz*Link is a directory, ignoring download_dirNr)r,rrrrrr rZcopytreerrcheck_against_pathrrrrr)rrrrrrrrr?r?rCr0s,     c Cstjj|rt|d}tjg}|jd|jt||jd|d|g7}tj d|t t ||ddWdQRXtjj |tj |d }tj d ||t||ddd dS) zCopy 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-csdistz --dist-dirzRunning setup.py sdist for %sF)cwdZ show_stdoutNrzUnpacking sdist %s into %s)rr)rrrr rW executablerrrrrrrZlistdirr)rrZsetup_pyZ sdist_argsrr?r?rC_copy_dist_from_dirs     r c@s$eZdZdZdddZd ddZdS) PipXmlrpcTransportzRProvide a `xmlrpclib.Transport` implementation via a `PipSession` object. FcCs*tjj||tj|}|j|_||_dS)N)r) Transportrlrqrrr_scheme_session)rkZ index_urlrZ use_datetimeZ index_partsr?r?rCrls zPipXmlrpcTransport.__init__c Cs|j||dddf}tj|}y6ddi}|jj|||dd}|j||_|j|jSt j k r} zt j d| j j|WYdd} ~ XnXdS)Nz Content-Typeztext/xmlT)rSrrzHTTP error %s while getting %s)rrqrvrZpostrverboseZparse_responserr HTTPErrorrcriticalror) rkrZhandlerZ request_bodyrpartsrsrrorr?r?rCrs     zPipXmlrpcTransport.requestN)F)F)rrrrrlrr?r?r?rCr s r cCs^t|rt||n:t|r.t||||dn |dkrs     0               BR!BH )  ` & 0$ '8