3 (\K@sddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZmZmZddlmZddlmZddlmZddlmZmZddlmZmZdd lmZm Z dd l!m"Z"dd l#m$Z$dd l%m&Z&dd l'm(Z)ddl'm*Z+ddl,m-Z-ddl.Z.ddl/m0Z0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddlZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGddlHmIZIddlJmKZKddlLmMZMddlNmOZOeKrddlPmQZQmRZRmSZSmTZTmUZUmVZVddlWmXZXddlYmZZZddlNm[Z[y ddl\Z\Wne]k r<dZ\YnXe\dk pJe-Z^dd d!d"d#d$d%d&d'd(d)g Z_ej`eaZbdZZcd-d.Zdd/d0ZeGd1d2d2eZfGd3d4d4eZgGd5d6d6eZhGd7d8d8eZiGd9d:d:ejjZkd[d;dZle jmdd Zqd?d!Zrd@d"ZsdAd#ZtdBd$ZudCdDZvdEd&ZwdFd'ZxdGdHZydIdJZzdKdLZ{dMdNZ|d\dPd(Z}d]dQd%Z~GdRdSdSe&jZd^dUd)ZdVdWZdXdYZdS)_)absolute_importN)requestssixurllib3)CacheControlAdapter) FileCache) LockError) BaseAdapter HTTPAdapter)AuthBase HTTPBasicAuth)CONTENT_CHUNK_SIZEResponse)CaseInsensitiveDict)get_netrc_auth) xmlrpc_client)parse)request) IS_PYOPENSSL) HashMismatchInstallationError)write_delete_marker_file)PyPI) auto_decode)check_path_owner)libc_ver) ARCHIVE_EXTENSIONSask_path_exists backup_dirconsume display_path format_sizeget_installed_versionrmtreesplit_auth_from_netlocsplitext unpack_file) TempDirectory)MYPY_CHECK_RUNNING)DownloadProgressProvider)vcs)OptionalTupleDictIOTextUnion)Link)Hashes)AuthInfoget_file_contentis_url url_to_path path_to_urlis_archive_fileunpack_vcs_linkunpack_file_url is_vcs_url is_file_urlunpack_http_url unpack_url BUILD_BUILDIDBUILD_IDCIcCstddtDS)z? Return whether it looks like pip is running under CI. css|]}|tjkVqdS)N)osenviron).0namerFi/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/download.py bsz looks_like_ci..)anyCI_ENVIRONMENT_VARIABLESrFrFrFrG looks_like_ciZsrKcCsDdtjdtjdtjid}|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<trtj|d <td!}|d k r||d"<trd#nd |d$<tjjd%}|d k r*||d&<d'j|tj |d,d#d*d+S)-z6 Return a string representing the user agent. pip)rEversionrE) installerpythonimplementationrPCPythonrMPyPyfinalN.cSsg|] }t|qSrF)str)rDxrFrFrG yszuser_agent..Jython IronPythonlinuxr)distrocSs|dS)NrF)rWrFrFrGszuser_agent..idcSs|dS)Nr]rF)rWrFrFrGr^sliblibcr\darwinmacOSsystemreleasecpuopenssl_version setuptoolssetuptools_versionTZciZPIP_USER_AGENT_USER_DATA user_dataz9{data[installer][name]}/{data[installer][version]} {json},:) separators sort_keys)datajson)rkrl)!rL __version__platformpython_versionpython_implementationsyspypy_version_info releaseleveljoin startswith pip._vendorr\dictfilterziplinux_distributionrmac_verrd setdefaultremachineHAS_TLSsslOPENSSL_VERSIONr"rKrBrCgetformatrpdumps)rorvr\ distro_infosrarirjrFrFrG user_agentes^           rc@s.eZdZd ddZddZddZdd Zd S) MultiDomainBasicAuthTcCs||_i|_dS)N) prompting passwords)selfrrFrFrG__init__szMultiDomainBasicAuth.__init__cCstj|j}t|j\}}tj|dd|f|dd|_|jj|d\}}|dkrb|\}}|dkr|dkrt|j}|r|nd\}}|s|r||f|j|<t |pd|pd|}|j d|j |S)Nr]response)NN)NN) urllib_parseurlparseurlr$netloc urlunparserrrr register_hook handle_401)rreqparsedrZurl_user_passwordusernamepassword netrc_authrFrFrG__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}|jd|j|jj|f|}|jj||S)Niz User for %s: z Password: rr) status_coderrrrrmovesinputrgetpassrcontentraw release_connr rr warn_on_401 connectionsendhistoryappend)rrespkwargsrrrrnew_resprFrFrGrs      zMultiDomainBasicAuth.handle_401cKs|jdkrtjd|jjdS)Niz)401 Error, Credentials not correct for %s)rloggerwarningrr)rrrrFrFrGrs z MultiDomainBasicAuth.warn_on_401N)T)__name__ __module__ __qualname__rrrrrFrFrFrGrs !#rc@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)usegmtrz text/plain)z Content-TypezContent-Lengthz Last-Modifiedrb)r6rrrrBstatOSErrorremailutils formatdatest_mtime mimetypes guess_typerst_sizeheadersopenclose) rrstreamtimeoutverifycertproxiespathnamerstatsexcmodified content_typerFrFrGrs$    zLocalFSAdapter.sendcCsdS)NrF)rrFrFrGr#szLocalFSAdapter.close)NNNNN)rrrrrrFrFrFrGrs 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.)superrrr directoryrr)rargsr) __class__rFrGr-s  zSafeFileCache.__init__c s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrrrrIOError)rrr)rrFrGrAs  zSafeFileCache.getc s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrsetrrr)rrr)rrFrGrNs  zSafeFileCache.setc s@|jdkrdSytt|j||Stttfk r:YnXdS)N)rrrdeleterrr)rrr)rrFrGr[s  zSafeFileCache.delete) rrr__doc__rrrr __classcell__rFrF)rrGr's   rc@seZdZddZdS)InsecureHTTPAdaptercCsd|_d|_dS)N CERT_NONE) cert_reqsca_certs)rconnrrrrFrFrG cert_verifykszInsecureHTTPAdapter.cert_verifyN)rrrrrFrFrFrGrisrcs,eZdZdZfddZfddZZS) PipSessionNc s|jdd}|jdd}|jdg}tt|j||t|jd<t|_tj |dddd gd d }|r|t t |d d |d}n t |d}t |d}|jd||jd||jdtx|D]}|jdj||qWdS)Nretriesrcacheinsecure_hostsz User-Agentiiiig?)totalstatus_forcelistbackoff_factorT) use_dir_lock)r max_retries)rzhttps://zhttp://zfile://z https://{}/)poprrrrrrauthrRetryrrr rmountrr) rrrrrrsecure_adapterinsecure_adapterhost)rrFrGrts*            zPipSession.__init__cs(|jd|jtt|j||f||S)Nr)rrrrr)rmethodrrr)rrFrGrszPipSession.request)rrrrrrrrFrF)rrGrps >rc CsL|dkrtdtj|}|r|jdj}|dkrR|rR|jdrRtd||f|dkr|jddd}|jdd }t j |}|r|jdd|jd dd}t j |}|jd rd |j d }|}n|j|}|j|j|jfSy&t|d }t|j}WdQRXWn4tk rB} ztd t| WYdd} ~ XnX||fS) a*Gets the content of a file; it may be a filename, file: URL, or http: URL. Returns (location, content). Content is unicode. :param url: File path or url. :param comes_from: Origin description of requirements. :param session: Instance of pip.download.PipSession. NzAget_file_content() missing 1 required keyword argument: 'session'r]filehttpz6Requirements file %s references URL %s, which is localrl\/|rz$Could not open requirements file: %s) TypeError _scheme_researchgrouplowerryrsplitreplace_url_slash_drive_rematchrunquotelstriprraise_for_statusrtextrrreadrrV) r comes_fromsessionrschemepathrfrrrFrFrGr4s>             z^(http|https|file):z /*([a-z])\|cCs6d|kr dS|jdddj}|ddddgtjkS) z)Returns true if the name looks like a URLrlFr]rrhttpsrftp)rrr* all_schemes)rErrFrFrGr5scCsp|jdstd|tj|\}}}}}| s8|dkr>d}n tjdkrRd|}n td|tj||}|S)z( Convert a file: URL to a path. zfile:z4You can only turn file: urls into filenames (not %r) localhostrwin32z\\z:non-local file URIs are not supported on this platform: %r) ryAssertionErrorrurlsplitrurr ValueErrorurllib_request url2pathname)r_rrrFrFrGr6s    cCs*tjjtjj|}tjdtj|}|S)zh Convert a path to a file: URL. The path will be made absolute and have quoted path parts. zfile:)rBrnormpathabspathrurljoinr pathname2url)rrrFrFrGr7scCs t|dj}|tkrdSdS)z9Return True if `name` is a considered as an archive file.r]TF)r%rr)rEextrFrFrGr8scCst|}|j|dS)N)_get_used_vcs_backendunpack)linklocation vcs_backendrFrFrGr9$scCs.x(tjD]}|j|jkr||j}|SqWdS)N)r*backendsrschemesr)rbackendrrFrFrGr)s   rcCs tt|S)N)boolr)rrFrFrGr;0scCs|jjjdS)Nzfile:)rrry)rrFrFrGr<5scCst|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. )r6url_without_fragmentrBrisdir)r link_pathrFrFrG is_dir_url:s r"cOs|S)NrF)iterablerrrFrFrG_progress_indicatorFsr$c sDytjd}Wntttfk r0d}YnXtdd}tjtj krRd}n&|r\d}n|dkrjd}n|std}nd}|j }fdd } fd d } t } |j t j kr|} n|j} |rt||d } |rtjd | t|n tjd| n |rtjd| n tjd| tjd|| | | tt} |r8|j| nt| dS)Nzcontent-lengthr from_cacheF(iTc 3s\y$xjj|ddD] }|VqWWn2tk rVxjj|}|sHP|Vq6WYnXdS)NF)decode_content)rrAttributeErrorr) chunk_sizechunk)rrFrG resp_reades  z _download_url..resp_readc3s"x|D]}j||VqWdS)N)write)chunksr*) content_filerFrGwritten_chunkss  z%_download_url..written_chunks)maxzDownloading %s (%s)zDownloading %szUsing cached %szDownloading from URL %si@)intrr KeyErrorrgetattrrgetEffectiveLevelloggingINFOshow_urlr$rrrr)infor!debugr check_against_chunksr)rrr.hashes progress_bar total_length cached_resp show_progressr7r+r/progress_indicatorrdownloaded_chunksrF)r.rrG _download_urlJsL   %     rBcCsd}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 %sr]zSaved %s)rCrDrErF)rBrrxfilenameexistsrr rrremovershutilmoveruexitcopyr8)rHrrrNdownload_locationr dest_filerFrFrG _copy_files.     rQonc Cs|dkrtdtddz}d}|r0t|||}|rH|}tj|d} nt|||j||\}} t||| ||r| rt||||st j |WdQRXdS)Nz@unpack_http_url() missing 1 required keyword argument: 'session'r)kindr) rr'_check_download_dirrr_download_http_urlrr&rQrBunlink) rr download_dirrr;r<temp_diralready_downloaded_path from_pathrrFrFrGr=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)symlinksz*Link is a directory, ignoring download_dirNr)r6rr"rBrr r#rKcopytreerr8check_against_pathrTrrr&rQ)rrrWr;r!rYrZrrFrFrGr:s,     c@s$eZdZdZdddZd ddZdS) PipXmlrpcTransportzRProvide a `xmlrpclib.Transport` implementation via a `PipSession` object. FcCs*tjj||tj|}|j|_||_dS)N)r Transportrrrr_scheme_session)r index_urlr use_datetime index_partsrFrFrGr3s 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)rorrzHTTP error %s while getting %s)r`rrrapostrverboseparse_responserr HTTPErrorrcriticalrr) rrhandler request_bodyrfpartsrrrrrFrFrGr9s     zPipXmlrpcTransport.requestN)F)F)rrrrrrrFrFrFrGr^.s r^FcCs`t|rt||nKs cCsB|jjddd}y |j|ddidd}|jWn8tjk rj}ztjd|jj |WYd d }~XnX|j jd d }|j } |j jd } | rt j | \} } | jd p| } t| d} | stj|} | r| | 7} | o|j|jkrtjj|jd} | r| | 7} tjj|| }t|d}t|||||Wd QRX||fS)z6Download link url into temp_dir using provided session#r]rzAccept-EncodingidentityT)rrzHTTP error %s while getting %sNz content-typerzcontent-dispositionrHwb)rrrrrrhrrirrrrHcgi parse_headerr%rguess_extensionrBrrxrrB)rrrXr;r< target_urlrrrrHcontent_dispositiontypeparamsr file_pathr.rFrFrGrU|s<      rUc Csntjj||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) rBrrxrHrIrr8r]rrrV)rrWr; download_pathrFrFrGrTs   rT)r?r@rA)NN)NNNrR)NN)NFNNrR) __future__rrq email.utilsrrrpr5rrBrrrerKrurzrrrpip._vendor.cachecontrolrpip._vendor.cachecontrol.cachesrpip._vendor.lockfilerZpip._vendor.requests.adaptersr r Zpip._vendor.requests.authr r Zpip._vendor.requests.modelsr rZpip._vendor.requests.structuresrZpip._vendor.requests.utilsrpip._vendor.six.movesrZpip._vendor.six.moves.urllibrrrrZpip._vendor.urllib3.utilrrLZpip._internal.exceptionsrrZpip._internal.locationsrZpip._internal.models.indexrZpip._internal.utils.encodingrZpip._internal.utils.filesystemrZpip._internal.utils.glibcrZpip._internal.utils.miscrrrrr r!r"r#r$r%r&Zpip._internal.utils.temp_dirr'Zpip._internal.utils.typingr(Zpip._internal.utils.uir)Zpip._internal.vcsr*Ztypingr+r,r-r.r/r0Zpip._internal.models.linkr1Zpip._internal.utils.hashesr2r3r ImportErrorr__all__ getLoggerrrrJrKrrrrrSessionrr4compileIrrr5r6r7r8r9rr;r<r"r$rBrQr=r:r_r^r>rUrTrFrFrFrGs               4            OR!BJ /    f * 2  *B