o gK @sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddlm Z ddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!ddl"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)dd l*m+Z+dd l,m-Z-dd l.m/Z/gd Z0e1e2Z3e d Z4eee5e5efZ6ee7e7e7fZ8ee9eee9ee9ffZ:de9fddZ;dee7dfdee7e7e7ffddZe#de$de%dddde9d e?ddfd!d"Z@d#edefde9d$e6ddfd%d&ZAde9de9fd'd(ZBdde9d*e9de9fd+d,ZCd-e9d.ee9de9fd/d0ZDd-e9ddfd1d2ZEd-e9d.ee9de9fd3d4ZFd-e9de9fd5d6ZGd-e9de9fd7d8ZHd9e9de7fd:d;ZIdZKd?eeedeee9ee7ffd@dAZLde9de?fdBdCZMejNfdDedEe7deeOfdFdGZPdde9dHe?de9fdIdJZQde9dee9e9ffdKdLZRdMe9dNe9ddfdOdPZSde9de?fdQdRZTdSedTeddfdUdVZUGdWdXdXe ZVejWdYe9deeVfdZd[ZXdeeVfd\d]ZYdeeVfd^d_ZZd`edaedeefdbdcZ[dde9deee7de9fdfdgZ\ddie9dje9de9fdkdlZ]die9dee9ee7ffdmdnZ^die9de:fdodpZ_die9de9fdqdrZ`dse9dtee9geedffdee9e:ffdudvZadie9de:fdwdxZbdie9dee9fdydzZcdse9dee9e9ee9e9fffd{d|Zddse9de9fd}d~Zedse9de9fddZfGdddZgde9degfddZhdse9degfddZide?ddfddZjde?fddZkdde9de7deee7ffddZlde?fddZmdeedeeeeffddZndee4ge?fdee4deee4ee4ffddZodS)N)StringIO) filterfalsetee zip_longest) TracebackType) AnyBinaryIOCallableContextManagerIterableIteratorListOptionalTextIOTupleTypeTypeVarcast)retrystop_after_delay wait_fixed) __version__) CommandError)get_major_minor_version)WINDOWS)running_under_virtualenv) rmtree display_path backup_dirasksplitext format_sizeis_installable_dirnormalize_pathrenamesget_progcaptured_stdout ensure_dirremove_auth_from_urlTreturncCs4tjtjtdd}tj|}dt|tS)Nz..zpip {} from {} (python {})) ospathjoindirname__file__abspathformatrr) pip_pkg_dirr3:/usr/lib/python3/dist-packages/pip/_internal/utils/misc.pyget_pip_versionDs r5py_version_info.cCsDt|dkr|dt|d7}n t|dkr|dd}td|S)ax Convert a tuple of ints representing a Python version to one of length three. :param py_version_info: a tuple of ints representing a Python version, or None to specify no version. The tuple can have any length. :return: a tuple of length three if `py_version_info` is non-None. Otherwise, return `py_version_info` unchanged (i.e. None). )rN VersionInfo)lenr)r6r3r3r4normalize_version_infoOs    r:r,c Cs`zt|WdSty/}z|jtjkr|jtjkr$WYd}~dSWYd}~dSd}~ww)z os.path.makedirs without EEXIST.N)r+makedirsOSErrorerrnoEEXIST ENOTEMPTY)r,er3r3r4r'bsr'c CsJztjtjd}|dvrtjdWS|WStttfy$YdSw)Nr)z __main__.pyz-cz -m pippip) r+r,basenamesysargv executableAttributeError TypeError IndexError)progr3r3r4r%lsr%Tr7g?)reraisestopwaitFdir ignore_errorscCstj||tddS)N)rNonerror)shutilrrmtree_errorhandler)rMrNr3r3r4rzrfuncexc_infocCsNz t|jtj@ }Wn tyYdSw|r&t|tj||dS)zOn Windows, the files in .svn are read-only, so when rmtree() tries to remove them, an exception is thrown. We catch that here, remove the read-only attribute, and hopefully continue without problems.N)r+statst_modeS_IWRITEr<chmod)rSr,rThas_attr_readonlyr3r3r4rQs rQcCsFtjtj|}|ttjjr!d|ttd}|S)zTGives the display value for a given path, making it relative to cwd if possible..N)r+r,normcaser0 startswithgetcwdsepr9r,r3r3r4rsr.bakextcCsDd}|}tj||r|d7}|t|}tj||s ||S)z\Figure out the name of a directory to back up the given dir to (adding .bak, .bak2, etc))r+r,existsstr)rMran extensionr3r3r4rs rmessageoptionscCs2tjddD] }||vr|Sq t||S)NPIP_EXISTS_ACTION)r+environgetsplitr)rgrhactionr3r3r4ask_path_existss  rocCstjdr td|dS)z&Raise an error if no input is allowed. PIP_NO_INPUTz5No input was expected ($PIP_NO_INPUT set); question: N)r+rkrl Exceptionrgr3r3r4_check_no_inputs rscCsD t|t|}|}||vrtd|d|n|Sq)z@Ask the message interactively, with the given possible responsesrbz>Your response ({!r}) was not one of the expected responses: {}z, )rsinputstriplowerprintr1r-)rgrhresponser3r3r4rs rcCst|t|S)zAsk for input interactively.)rsrtrrr3r3r4 ask_inputsrycCst|t|S)z!Ask for a password interactively.)rsgetpassrrr3r3r4 ask_passwords r{valcCs.|}|dvr dS|dvrdStd|)zConvert a string representation of truth to true (1) or false (0). True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. )yyesttrueon1rb)renoffalseoff0rzinvalid truth value )rv ValueError)r|r3r3r4 strtobools rbytescCsX|dkr d|ddS|dkrdt|dS|dkr%d|dSdt|S) Ni@Bz {:.1f} MBg@@ii'z{} kBz {:.1f} kBz{} bytes)r1int)rr3r3r4r!sr!rowscs@dd|D}ddt|ddiDfdd|D}|fS)zReturn a list of formatted rows and a list of column sizes. For example:: >>> tabulate([['foobar', 2000], [0xdeadbeef]]) (['foobar 2000', '3735928559'], [10, 4]) cSg|] }ttt|qSr3)tuplemaprd.0rowr3r3r4 ztabulate..cSrr3)maxrr9)rcolr3r3r4rr fillvaluerjcs$g|]}dttj|qS) )r-rrdljustrstriprsizesr3r4rs$)r)rtabler3rr4tabulatesrcCsHtj|sdStjtj|drdStjtj|dr"dSdS)atIs path is a directory containing pyproject.toml or setup.py? If pyproject.toml exists, this is a PEP 517 project. Otherwise we look for a legacy setuptools layout by identifying setup.py. We don't check for the setup.cfg because using it without setup.py is only available for PEP 517 projects, which are already covered by the pyproject.toml check. Fzpyproject.tomlTzsetup.py)r+r,isdirisfiler-r_r3r3r4r"s r"filesizeccs ||}|s dS|Vq)z7Yield pieces of data from a file-like object until EOF.TN)read)rrchunkr3r3r4 read_chunks s rresolve_symlinkscCs6tj|}|rtj|}ntj|}tj|S)zN Convert a path to its canonical, case-normalized, absolute version. )r+r, expanduserrealpathr0r[)r,rr3r3r4r#s   r#cCs@t|\}}|dr|dd|}|dd}||fS)z,Like os.path.splitext, but take off .tar tooz.tarN) posixpathr rvendswith)r,baserar3r3r4r !s  r oldnewcCstj|\}}|r|rtj|st|t||tj|\}}|r<|r>zt|WdSty;YdSwdSdS)z7Like os.renames(), but handles renaming across devices.N) r+r,rmrcr;rPmove removedirsr<)rrheadtailr3r3r4r$*s   r$cCs|t|}d}tr|ttjSddlm}ddlm}||r<|d}|D]}t ||}|t|r9dSq(dSdS)a Return True if this is a path pip is allowed to modify. If we're in a virtualenv, sys.prefix points to the virtualenv's prefix; only sys.prefix is considered local. If we're not in a virtualenv, in general we can modify anything. However, if the OS vendor has configured distutils to install somewhere other than sys.prefix (which could be a subdirectory of sys.prefix, e.g. /usr/local), we consider sys.prefix itself nonlocal and the domain of the OS vendor. (In other words, everything _other than_ sys.prefix is considered local.) Caution: this function assumes the head of path has been normalized with normalize_path. z/usrr) get_scheme) SCHEME_KEYSrjTF) r#rr\rCprefixpip._internal.locationsrpip._internal.models.schemergetattr)r,rrrschemekey local_pathr3r3r4is_local;s    rmsgargscGstj|g|RdSN)loggerinfo)rrr3r3r4 write_outputasrc@s<eZdZUdZeed<ededdfddZeddZ dS) StreamWrapperN orig_streamr*cCs ||_|Sr)r)clsrr3r3r4 from_streamhszStreamWrapper.from_streamcCs|jjSr)rencodingselfr3r3r4roszStreamWrapper.encoding) __name__ __module__ __qualname__rr__annotations__ classmethodrpropertyrr3r3r3r4res r stream_namec csLtt|}tt|t|ztt|VWtt||dStt||w)zReturn a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO. Taken from Lib/support/__init__.py in the CPython repo. N)rrCsetattrrr)r orig_stdoutr3r3r4captured_outputts  rcCtdS)zCapture the output of sys.stdout: with captured_stdout() as stdout: print('hello') self.assertEqual(stdout.getvalue(), 'hello ') Taken from Lib/support/__init__.py in the CPython repo. stdoutrr3r3r3r4r&s r&cCr)z See captured_stdout(). stderrrr3r3r3r4captured_stderrsr sequentialnamedcOsDtt|tt|fi|}dd|D}||d<tdd|S)NcSsi|]\}}||qSr3r3)rrvaluer3r3r4 szenum..reverse_mappingEnumr3)dictzipranger9itemstype)rrenumsreverser3r3r4enums rhostportcCs.|dur|Sd|vrd|d}|d|S)z. Build a netloc from a host-port pair N:[]r3)rrr3r3r4 build_netlocs  rhttpsnetlocrcCs8|ddkrd|vrd|vrd|d}|d|S)z) Build a full URL from a netloc. r@rrz://)count)rrr3r3r4build_url_from_netlocs rcCs t|}tj|}|j|jfS)z2 Return the host-port pair from a netloc. )rurllibparseurlparsehostnamer)rurlparsedr3r3r4 parse_netlocs  rcCstd|vr|dfS|dd\}}d}d|vr|dd\}}n|d}}tj|}|dur4tj|}|||ffS)zp Parse out and remove the auth information from a netloc. Returns: (netloc, (username, password)). r)NNrbNr)rsplitrmrrunquote)rauthpwuserr3r3r4split_auth_from_netlocs    rcCsNt|\}\}}|dur|S|durd}d}ntj|}d}dj|||dS)z Replace the sensitive data in a netloc with "****", if it exists. For example: - "user:pass@example.com" returns "user:****@example.com" - "accesstoken@example.com" returns "****@example.com" N****rjz:****z{user}{password}@{netloc})rpasswordr)rrrquoter1)rrrr3r3r4 redact_netlocs rrtransform_netloccCsJtj|}||j}|j|d|j|j|jf}tj|}|t d|fS)aRTransform and replace netloc in a url. transform_netloc is a function taking the netloc and returning a tuple. The first element of this tuple is the new netloc. The entire tuple is returned. Returns a tuple containing the transformed url as item 0 and the original tuple returned by transform_netloc as item 1. r NetlocTuple) rrurlsplitrrr,queryfragment urlunsplitr)rrpurl netloc_tuple url_piecessurlr3r3r4_transform_urls  rcCst|Sr)rrr3r3r4 _get_netlocsrcCs t|fSr)rrr3r3r4_redact_netlocs rcCst|t\}\}}|||fS)z Parse a url into separate netloc, auth, and url with no auth. Returns: (url_without_auth, netloc, (username, password)) rr)rurl_without_authrrr3r3r4split_auth_netloc_from_url s rcCt|tdS)z7Return a copy of url with 'username:password@' removed.rrrr3r3r4r(sr(cCr)z.Replace the password in a given url with ****.r)rrrr3r3r4redact_auth_from_urlsrc@sPeZdZdededdfddZdefddZdefd d Zd edefd d Z dS) HiddenTextsecretredactedr*NcCs||_||_dSr)rr)rrrr3r3r4__init__#s zHiddenText.__init__cCsdt|S)Nz)r1rdrr3r3r4__repr__'szHiddenText.__repr__cCs|jSrrrr3r3r4__str__*szHiddenText.__str__othercCs t|t|kr dS|j|jkS)NF)rr)rrr3r3r4__eq__.s zHiddenText.__eq__) rrrrdrrrrboolr r3r3r3r4r"s rrcCs t|ddS)Nrr)r)rr3r3r4 hide_value7s r"cCst|}t||dS)Nr)rr)rrr3r3r4hide_url;s r# modifying_pipcCszddtjddjtjddg}|o!to!tjtjd|v}|r;tjddgtjd d}t d d |dS) zProtection of pip.exe from modification on Windows On Windows, any operation modifying pip should be run as: python -m pip ... zpip.exez pip{}.exerz pip{}.{}.exeNrz-mrArbz3To modify pip, please run the following command: {}r) r1rC version_inforr+r,rBrDrErr-)r$ pip_namesshould_show_use_python_msg new_commandr3r3r4(protect_pip_from_modification_on_windows@sr)cCstjduo tjS)zIs this console interactive?N)rCstdinisattyr3r3r3r4is_console_interactiveZrRr, blocksizecCslt}d}t|d}t||dD] }|t|7}||qWd||fS1s-wY||fS)z5Return (hash, length) for path using hashlib.sha256()rrb)rN)hashlibsha256openrr9update)r,r.hlengthrblockr3r3r4 hash_file_s    r7cCs$zddl}WdStyYdSw)z8 Return whether the wheel package is installed. rNFT)wheel ImportError)r8r3r3r4is_wheel_installedks   r:iterablecCst|}t||S)zb Return paired elements. For example: s -> (s0, s1), (s2, s3), (s4, s5), ... )iterr)r;r3r3r4pairwisews r=predcCs t|\}}t||t||fS)z Use a predicate to partition entries into false entries and true entries, like partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9 )rrfilter)r>r;t1t2r3r3r4 partitions rB)F)r`)T)r)r-)p contextlibr=rzr0iologgingr+rrPrUrC urllib.parserr itertoolsrrrtypesrtypingrrr r r r r rrrrrrpip._vendor.tenacityrrrrArpip._internal.exceptionsrrrpip._internal.utils.compatrpip._internal.utils.virtualenvr__all__ getLoggerrrr) BaseExceptionExcInforr8rdrr5r:r'r%r!rrQrrrorsrryr{rfloatr!rr"DEFAULT_BUFFER_SIZErrr#r r$rrrcontextmanagerrr&rrrrrrrrrrrr(rrr"r#r)r,r7r:r=rBr3r3r3r4s  <      $  "  *     &      $   "