3 . g}@sJddlmZddlZddlZddlZddlZddlZddlZddl 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'g ZRejSeTZUd(d)ZVGd*d+d+e@ZWGd,d-d-e=ZXGd.d/d/eMZYGd0d1d1e>ZZGd2d3d3e:j[Z\dSd4dZ]e j^d5e j_Z`e j^d6e j_Zad7dZbd8dZcd9d Zdd:d!Zed;d"Zfdd$Zhd?d%Zid@dAZjdBdCZkdDdEZldFdGZmdTdHd&ZndUdId#ZodJdKZpGdLdMdMeQjqZrdVdNd'ZsdOdPZtdQdRZudS)W)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_urlcCs 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)nameversionr6)Z installerpythonimplementationr9ZCPythonr7ZPyPyfinalN.cSsg|] }t|qS)str).0xr=r=/usr/lib/python3.6/download.py Sszuser_agent..ZJythonZ IronPythonlinuxr)distrocSs|dS)Nr=)r@r=r=rA_szuser_agent..idcSs|dS)NrEr=)r@r=r=rArFcsliblibcrDdarwinZmacOSsystemreleaseZcpuZopenssl_versionz9{data[installer][name]}/{data[installer][version]} {json},:T)Z separatorsZ sort_keys)datajson)rMrN)rOrP)r5 __version__platformZpython_versionZpython_implementationsyspypy_version_info releaseleveljoin startswith pip._vendorrDdictfilterzipZlinux_distributionrZmac_verrK setdefaultrLmachineHAS_TLS version_infosslZOPENSSL_VERSIONformatrRdumps)rQrVrDZ distro_infosrIr=r=rA user_agent?sP        rec@s.eZdZd ddZddZddZdd Zd S) MultiDomainBasicAuthTcCs||_i|_dS)N) prompting passwords)selfrgr=r=rA__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@rErMresponse)NN)NN) urllib_parseurlparseurlnetlocrsplit urlunparserhgetparse_credentialsr#r Z register_hook handle_401)rireqparsedrrusernamepasswordZ netrc_authr=r=rA__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: rl) status_codergrorprqrZmovesinputrrgetpassrhcontentrawZ release_connr rZ connectionsendhistoryappend)rirespkwargsryrzr{rxZnew_respr=r=rArws     zMultiDomainBasicAuth.handle_401cCs8d|kr4|jddd}d|kr,|jddS|dfSdS)NrkrErrP)NN)rssplit)rirrZuserinfor=r=rArvs  z&MultiDomainBasicAuth.parse_credentialsN)T)__name__ __module__ __qualname__rjr|rwrvr=r=r=rArfs !"rfc@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,rqr"r}osstatOSErrorremailZutilsZ formatdatest_mtime mimetypes guess_typer$st_sizeheadersopenclose) rirstreamtimeoutverifycertZproxiespathnamerZstatsexcZmodified content_typer=r=rArs$    zLocalFSAdapter.sendcCsdS)Nr=)rir=r=rArszLocalFSAdapter.close)NNNNN)rrrrrr=r=r=rArs 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.)superrrjr directoryloggerwarning)riargsr) __class__r=rArjs  zSafeFileCache.__init__c s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrrur(rIOError)rirr)rr=rArus  zSafeFileCache.getc s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrsetr(rr)rirr)rr=rArs  zSafeFileCache.setc s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrdeleter(rr)rirr)rr=rAr(s  zSafeFileCache.delete) rrr__doc__rjrurr __classcell__r=r=)rrArs   rc@seZdZddZdS)InsecureHTTPAdaptercCsd|_d|_dS)NZ CERT_NONE)Z cert_reqsZca_certs)riZconnrqrrr=r=rA cert_verify8szInsecureHTTPAdapter.cert_verifyN)rrrrr=r=r=rAr6srcs,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}/)poprrrjrerrfZauthr%ZRetryr&rrrZmountrrc) rirrrrrZsecure_adapterZinsecure_adapterhost)rr=rArjAs*           zPipSession.__init__cs(|jd|jtt|j||f||S)Nr)r^rrrr)rimethodrqrr)rr=rAr}szPipSession.request)rrrrrjrrr=r=)rrAr=s ) rqZ comes_fromsessionrschemepathrfrrr=r=rAr*s>            z^(http|https|file):z /*([a-z])\|cCs6d|kr dS|jdddj}|ddddgtjkS) z)Returns true if the name looks like a URLrPFrErrZhttpsrZftp)rrrZ all_schemes)r6rr=r=rAr+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\\)rYAssertionErrorroZurlspliturllib_requestZ url2pathname)rq_rrrr=r=rAr,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:)rrnormpathabspathroZurljoinrZ pathname2url)rrqr=r=rAr-scCs t|dj}|tkrdSdS)z9Return True if `name` is a considered as an archive file.rETF)rrr)r6extr=r=rAr.scCst|}|j|dS)N)_get_used_vcs_backendunpack)linklocation vcs_backendr=r=rAr/scCs.x(tjD]}|j|jkr||j}|SqWdS)N)rZbackendsrZschemesrq)rZbackendrr=r=rArs   rcCs tt|S)N)boolr)rr=r=rAr1scCs|jjjdS)Nzfile:)rqrrY)rr=r=rAr2scCst|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=rA is_dir_urls rcOs|S)Nr=)iterablerrr=r=rA_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=rA resp_reads  z _download_url..resp_readc3s"x|D]}j||VqWdS)N)write)Zchunksr) content_filer=rAwritten_chunks:s  z%_download_url..written_chunkszDownloading %s (%s))maxzDownloading %szUsing cached %szDownloading from URL %si@)intr ValueErrorKeyErrorrgetattrrZgetEffectiveLevelloggingINFOshow_urlrrrrrinfor riterrdebugr!Zcheck_against_chunksr) rrrhashesZ total_lengthZ cached_respZ show_progressrrrZprogress_indicatorrqZdownloaded_chunksr=)rrrA _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 %srEzSaved %s)rrrrrn)rrrXfilenameexistsr r rrremover shutilZmoverUexitcopyr)rrrrZdownload_locationrmZ dest_filer=r=rA _copy_file`s.     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=rAr3{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=rAr0s,     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 rU executablerrrrrrrXlistdirr)rrZsetup_pyZ sdist_argsrr=r=rA_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) Transportrjrorpr_scheme_session)riZ index_urlrZ use_datetimeZ index_partsr=r=rArjs 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)rQrrzHTTP error %s while getting %s)r rortr ZpostrverboseZparse_responserr HTTPErrorrcriticalrmr}) rirZhandlerZ request_bodyrpartsrqrrmrr=r=rArs     zPipXmlrpcTransport.requestN)F)F)rrrrrjrr=r=r=rAr s r cCs^t|rt||n:t|r.t||||dn |dkrs     0               BR!BH )  ` & 0$ ';