U ÀÒ.eëcã@sÜddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZmZddlmZddlmZdd lmZdd lmZdd lm Z dd l!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1e�r8ddlm2Z3n ddlm3Z3e.�r–ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>ddl?m@Z@edddddddddd d!d"d#d$gZCe DeE¡ZFd%d&„ZGd'd(„ZHd)d"„ZId*d „ZJed+d,d-�dŽd/d„ƒZKd0d1„ZLd2d3„ZMd4d„ZNd�d6d„ZOd7d8„ZPd9d:„ZQd;d„ZRdd?„ZTd@d„ZUdAd„ZVejWfdBdC„ZXd�dEd„ZYdFd„ZZdGd„Z[dHdI„Z\dJdK„Z]dLdM„Z^dNdO„Z_dPdQ„Z`dRdS„ZadDe)dDd.d.dfdTdU„ZbdVdW„ZcdXdY„ZddZd[„Zed\d]„ZfGd^d_„d_egƒZhGd`da„dae3ƒZiejjdbdc„ƒZkddd!„Zldedf„ZmGdgdh„dhegƒZnd‘did#„Zodjdk„Zpdldm„Zqdndo„Zrd’dqdr„Zsdsdt„Ztdudv„Zudwdx„Zvdydz„Zwd{d|„Zxd}d~„Zydd€„Zzd�d$„Z{d‚dƒ„Z|Gd„d…„d…egƒZ}d†d‡„Z~dˆd‰„ZdŠd‹„Z€dŒd�„Z�dS)“é)Úabsolute_importN©Údeque)Ú pkg_resources)Úretry)ÚPY2Ú text_type)Úinput)Úparse)Úunquote)Ú __version__)Ú CommandError)Údistutils_schemeÚget_major_minor_versionÚ site_packagesÚ user_site)ÚWINDOWSÚ expanduserÚ stdlib_pkgsÚstr_to_display)Úwrite_delete_marker_file)ÚMYPY_CHECK_RUNNING)Úrunning_under_virtualenvÚvirtualenv_no_global)ÚBytesIO)ÚStringIO) ÚAnyÚAnyStrÚ ContainerÚIterableÚListÚOptionalÚTextÚTupleÚUnionÚcast)Ú DistributioncCs|S©N©)Ztype_Úvaluer(r(ú}z|jtjkr.‚W5d}~XYnXdS)z os.path.makedirs without EEXIST.N)r9ÚmakedirsÚOSErrorÚerrnoZEEXIST)r:Úer(r(r*r6qs  c CsPz0tj tjd¡}|dkr(dtjWS|WSWntttfk rJYnXdS)Nr)z __main__.pyz-cz %s -m pipÚpip) r9r:ÚbasenameÚsysÚargvÚ executableÚAttributeErrorÚ TypeErrorÚ IndexError)Úprogr(r(r*r4{s  i¸ iô)Zstop_max_delayZ wait_fixedFcCstj||td�dS)N)Ú ignore_errorsÚonerror)Úshutilr+Úrmtree_errorhandler)ÚdirrRr(r(r*r+‰sÿc CsXzt |¡jtj@ }Wnttfk r2YdSX|rRt |tj¡||ƒdS‚dS)zÑOn 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)r9ÚstatÚst_modeÚS_IWRITEÚIOErrorrFÚchmod)Úfuncr:Úexc_infoZhas_attr_readonlyr(r(r*rU�srUcCsd|dkr dSt|tƒr|Sz| t ¡d¡}Wn0tk r^trRtd |¡ƒ}nt |ƒ}YnX|S)zû Convert a bytes (or text) path to text (unicode in Python 2) for display and logging purposes. This function should never error out. Also, this function is mainly needed for Python 2 since in Python 3 str paths are already text. NÚstrictzb{!r}) Ú isinstancerÚdecoderKÚgetfilesystemencodingÚUnicodeDecodeErrorrrr?Úascii)r:r,r(r(r*Úpath_to_display¤s  rdcCsttj tj |¡¡}tjddkrB| t ¡d¡}| t  ¡d¡}|  t  ¡tjj ¡rpd|t t  ¡ƒd…}|S)zTGives the display value for a given path, making it relative to cwd if possible.réÚreplaceÚ.N)r9r:Únormcaser>rKÚ version_infor`raÚencodeÚgetdefaultencodingÚ startswithÚgetcwdÚseprC©r:r(r(r*r,Æsú.bakcCs6d}|}tj ||¡r.|d7}|t|ƒ}q||S)z\Figure out the name of a directory to back up the given dir to (adding .bak, .bak2, etc)é)r9r:ÚexistsÚstr)rVÚextÚnÚ extensionr(r(r*r-Ós cCs2tj dd¡ ¡D]}||kr|Sqt||ƒS)NZPIP_EXISTS_ACTIONÚ)r9ÚenvironÚgetÚsplitr.)ÚmessageÚoptionsÚactionr(r(r*Úask_path_existsßs r~cCstj d¡rtd|ƒ‚dS)z&Raise an error if no input is allowed.Z PIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sN)r9rxryÚ Exception©r{r(r(r*Ú_check_no_inputçs  ÿÿr�cCsFt|ƒt|ƒ}| ¡ ¡}||krrh)r:Zresolve_symlinksr(r(r*r23s  cCs@t |¡\}}| ¡ d¡r8|dd…|}|dd…}||fS)z,Like os.path.splitext, but take off .tar tooz.taréüÿÿÿN)Ú posixpathr/rƒÚendswith)r:Úbasertr(r(r*r/As  cCsztj |¡\}}|r.|r.tj |¡s.t |¡t ||¡tj |¡\}}|rv|rvzt |¡Wntk rtYnXdS)z7Like os.renames(), but handles renaming across devices.N) r9r:rzrrrErTZmoveÚ removedirsrF)ÚoldÚnewÚheadÚtailr(r(r*r3Ks  cCstƒs dS| ttjƒ¡S)zü Return True if path is within sys.prefix, if we're running in a virtualenv. If we're not in a virtualenv, all paths are considered "local." Caution: this function assumes the head of path has been normalized with normalize_path. T)rrlr2rKÚprefixror(r(r*Úis_local]s r›cCs tt|ƒƒS)z� Return True if given Distribution object is installed locally (i.e. within current virtualenv). Always True if we're not in a virtualenv. )r›Ú dist_location©Údistr(r(r*Ú dist_is_localls rŸcCst|ƒ ttƒ¡S)zF Return True if given Distribution is installed in user site. )rœrlr2rr�r(r(r*Údist_in_usersitexsr cCst|ƒ ttƒ¡S)z[ Return True if given Distribution is installed in sysconfig.get_python_lib(). )rœrlr2rr�r(r(r*Údist_in_site_packages€sr¡cCs,tt|ƒƒ}| ttdƒd d¡dƒ¡S)zf Return True if given Distribution is installed in path matching distutils_scheme layout. rwZpurelibÚpythonr)r2rœrlrrz)ržZ norm_pathr(r(r*Údist_in_install_path‰s ÿr£cCs6tjD]*}tj ||jd¡}tj |¡rdSqdS)zC Return True if given Distribution is an editable install. ú .egg-linkTF)rKr:r9r;Ú project_namerŠ)ržZ path_itemÚegg_linkr(r(r*Údist_is_editable“s   r§cs€|rt |¡}ntj}|r t‰ndd„‰|r6dd„‰ndd„‰|rLdd„‰ndd„‰|r^t‰nd d „‰‡‡‡‡‡fd d „|DƒS) a^ Return a list of installed Distribution objects. If ``local_only`` is True (default), only return installations local to the current virtualenv, if in a virtualenv. ``skip`` argument is an iterable of lower-case project names to ignore; defaults to stdlib_pkgs If ``include_editables`` is False, don't report editables. If ``editables_only`` is True , only report editables. If ``user_only`` is True , only report installations in the user site directory. If ``paths`` is set, only report the distributions present at the specified list of locations. cSsdS©NTr(©Údr(r(r*Ú local_testÃsz/get_installed_distributions..local_testcSsdSr¨r(r©r(r(r*Ú editable_testÇsz2get_installed_distributions..editable_testcSs t|ƒ Sr'©r§r©r(r(r*r¬ÊscSst|ƒSr'r­r©r(r(r*Úeditables_only_testÎsz8get_installed_distributions..editables_only_testcSsdSr¨r(r©r(r(r*r®ÑscSsdSr¨r(r©r(r(r*Ú user_test×sz.get_installed_distributions..user_testcs:g|]2}ˆ|ƒr|jˆkrˆ|ƒrˆ|ƒrˆ|ƒr|‘qSr()Úkey)Ú.0rª©r¬r®r«Úskipr¯r(r*Ú Ûs ûz/get_installed_distributions..)rÚ WorkingSetÚ working_setrŸr )Z local_onlyr³Zinclude_editablesZeditables_onlyZ user_onlyÚpathsr¶r(r²r*Úget_installed_distributionsŸs    r¸cCsxg}tƒr*| t¡tƒsBtrB| t¡ntr8| t¡| t¡|D],}tj ||j¡d}tj  |¡rF|SqFdS)a Return the path for the .egg-link file if it exists, otherwise, None. There's 3 scenarios: 1) not in a virtualenv try to find in site.USER_SITE, then site_packages 2) in a no-global virtualenv try to find in site_packages 3) in a yes-global virtualenv try to find in site_packages, then site.USER_SITE (don't look in global location) For #1 and #3, there could be odd cases, where there's an egg-link in 2 locations. This method will just return the first one found. r¤N) rÚappendrrrr9r:r;r¥rŠ)ržZsitesZsiteZegglinkr(r(r*Ú egg_link_pathäs       rºcCst|ƒ}|rt|ƒSt|jƒS)aO Get the site-packages location of this distribution. Generally this is dist.location, except in the case of develop-installed packages, where dist.location is the source code location, and we want to know where the egg-link file is. The returned location is normalized (in particular, with symlinks removed). )rºr2Úlocation)ržr¦r(r(r*rœs rœcGstj|f|žŽdSr')ÚloggerÚinfo)ÚmsgÚargsr(r(r*Ú write_outputsrÀcCst |¡t|ƒdSr')r9rEr)Z build_dirr(r(r*Ú_make_build_dirs rÁc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚFakeFilezQWrap a list of lines in an object with readline() to make ConfigParser happy.cCsdd„|Dƒ|_dS)Ncss|] }|VqdSr'r()r±Úlr(r(r*Ú &sz$FakeFile.__init__..©Ú_gen)ÚselfÚlinesr(r(r*Ú__init__%szFakeFile.__init__cCsPz4zt|jƒWWStk r0|j ¡YWSXWntk rJYdSXdS)Nrw)ÚnextrÆÚ NameErrorÚ StopIteration©rÇr(r(r*Úreadline(szFakeFile.readlinecCs|jSr'rÅrÍr(r(r*Ú__iter__1szFakeFile.__iter__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÉrÎrÏr(r(r(r*rÂ"s rÂc@s$eZdZedd„ƒZedd„ƒZdS)Ú StreamWrappercCs ||_|ƒSr')Ú orig_stream)ÚclsrÕr(r(r*Ú from_stream7szStreamWrapper.from_streamcCs|jjSr')rÕÚencodingrÍr(r(r*rØ=szStreamWrapper.encodingN)rÐrÑrÒÚ classmethodr×ÚpropertyrØr(r(r(r*rÔ5s rÔc cs@tt|ƒ}tt|t |¡ƒztt|ƒVW5tt||ƒXdS)zËReturn 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)ÚgetattrrKÚsetattrrÔr×)Z stream_nameZ orig_stdoutr(r(r*Úcaptured_outputBs  rÝcCstdƒS)zÜCapture 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. Ústdout©rÝr(r(r(r*r5Qs cCstdƒS)z See captured_stdout(). Ústderrrßr(r(r(r*Úcaptured_stderr]srác@s eZdZdZdd„Zdd„ZdS)Úcached_propertyzôA property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property. Source: https://github.com/bottlepy/bottle/blob/0.11.5/bottle.py#L175 cCst|dƒ|_||_dS)NrÓ)rÛrÓr\)rÇr\r(r(r*rÉls zcached_property.__init__cCs(|dkr |S| |¡}|j|jj<|Sr')r\Ú__dict__rÐ)rÇÚobjrÖr)r(r(r*Ú__get__pszcached_property.__get__N)rÐrÑrÒrÓrÉrår(r(r(r*râdsrâcCs4tj |¡}|dkrt ¡}| |¡}|r0|jSdS)zCGet the installed version of dist_name avoiding pkg_resources cacheN)rZ Requirementr rµÚfindÚversion)Z dist_namer¶Zreqržr(r(r*r7xs   cCst|dd�dS)zConsume an iterable at C speed.r)ÚmaxlenNr)Úiteratorr(r(r*ÚconsumeŠsrêcOs@tt|tt|ƒƒƒf|Ž}dd„| ¡Dƒ}||d<tdd|ƒS)NcSsi|]\}}||“qSr(r()r±r°r)r(r(r*Ú ’szenum..Zreverse_mappingÚEnumr()ÚdictÚzipÚrangerCÚitemsÚtype)Z sequentialZnamedZenumsÚreverser(r(r*Úenum�srócCs*|dkr |Sd|krd |¡}d ||¡S)z. Build a netloc from a host-port pair Nú:ú[{}]z{}:{})r?)ZhostÚportr(r(r*Ú build_netloc—s  r÷ÚhttpscCs4| d¡dkr(d|kr(d|kr(d |¡}d ||¡S)z) Build a full URL from a netloc. rôreú@ú[rõz{}://{})Úcountr?)ÚnetlocÚschemer(r(r*Úbuild_url_from_netloc¤s rþcCst|ƒ}t |¡}|j|jfS)z2 Return the host-port pair from a netloc. )rþÚ urllib_parseZurlparseZhostnamerö)rüÚurlZparsedr(r(r*Ú parse_netloc¯s rcCsXd|kr|dfS| dd¡\}}d|kr6| dd¡}n|df}tdd„|Dƒƒ}||fS)zp Parse out and remove the auth information from a netloc. Returns: (netloc, (username, password)). rù)NNrqrôNcss"|]}|dkrdnt|ƒVqdSr')Úurllib_unquote)r±Úxr(r(r*rÄÎsz)split_auth_from_netloc..)ÚrsplitrzÚtuple)rüÚauthZ user_passr(r(r*Úsplit_auth_from_netloc¹sÿrcCsLt|ƒ\}\}}|dkr|S|dkr.d}d}nt |¡}d}dj|||d�S)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ú****rwz:****z{user}{password}@{netloc})ÚuserÚpasswordrü)rrÿZquoter?)rür r r(r(r*Ú redact_netlocÕs  þr cCs@t |¡}||jƒ}|j|d|j|j|jf}t |¡}||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)rÿZurlsplitrürýr:ZqueryZfragmentZ urlunsplit)rZtransform_netlocZpurlZ netloc_tupleZ url_piecesZsurlr(r(r*Ú_transform_urlìs  ÿ r cCst|ƒSr')r©rür(r(r*Ú _get_netlocsrcCs t|ƒfSr')r r r(r(r*Ú_redact_netlocsrcCst|tƒ\}\}}|||fS)z† Parse a url into separate netloc, auth, and url with no auth. Returns: (url_without_auth, netloc, (username, password)) ©r r)rZurl_without_authrürr(r(r*Úsplit_auth_netloc_from_urlsrcCst|tƒdS)z7Return a copy of url with 'username:password@' removed.rr©rr(r(r*r8scCst|tƒdS)z.Replace the password in a given url with ****.r)r rrr(r(r*Úredact_auth_from_urlsrc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú HiddenTextcCs||_||_dSr')ÚsecretÚredacted)rÇrrr(r(r*rÉ"szHiddenText.__init__cCsd t|ƒ¡S)Nz)r?rsrÍr(r(r*Ú__repr__+szHiddenText.__repr__cCs|jSr'©rrÍr(r(r*Ú__str__/szHiddenText.__str__cCs t|ƒt|ƒkrdS|j|jkS)NF)rñr©rÇÚotherr(r(r*Ú__eq__4szHiddenText.__eq__cCs ||k Sr'r(rr(r(r*Ú__ne__?szHiddenText.__ne__N)rÐrÑrÒrÉrrrrr(r(r(r*r!s   rcCs t|dd�S)Nrr)r)r)r(r(r*Ú hide_valueDsrcCst|ƒ}t||d�S)Nr)rr)rrr(r(r*Úhide_urlIsrcCs°tƒ}dD]P}| dj|d�¡| djtjd|d�¡| djtjdd…d |iŽ¡q |oxtoxtj tj d¡|k}|r¬tj d d gtj d d…}t d  d  |¡¡ƒ‚dS)z�Protection of pip.exe from modification on Windows On Windows, any operation modifying pip should be run as: python -m pip ... )rwz.exezpip{ext})rtz pip{}{ext}rz pip{}.{}{ext}Nrertz-mrIrqz3To modify pip, please run the following command: {}ú ) ÚsetÚaddr?rKrirr9r:rJrLrMr r;)Z modifying_pipZ pip_namesrtZshould_show_use_python_msgZ new_commandr(r(r*Ú(protect_pip_from_modification_on_windowsOs,"ÿýÿ þÿÿr#cCstjdk otj ¡S)z!Is this console interactive? N)rKÚstdinÚisattyr(r(r(r*Úis_console_interactivemsr&)F)rp)T)N)rø)‚Z __future__rÚ contextlibrGr†ÚioZloggingr9r’rTrWrKÚ collectionsrZ pip._vendorrZpip._vendor.retryingrZpip._vendor.sixrrZpip._vendor.six.movesr Zpip._vendor.six.moves.urllibr rÿZ"pip._vendor.six.moves.urllib.parser rrIr Zpip._internal.exceptionsr Zpip._internal.locationsrrrrZpip._internal.utils.compatrrrrZ pip._internal.utils.marker_filesrZpip._internal.utils.typingrZpip._internal.utils.virtualenvrrrrÚtypingrrrrr r!r"r#r$r%Zpip._vendor.pkg_resourcesr&ÚintrBÚ__all__Z getLoggerrÐr¼r@rDr6r4r+rUrdr,r-r~r�r.r…r‡r0r1ÚDEFAULT_BUFFER_SIZEr�r2r/r3r›rŸr r¡r£r§r¸rºrœrÀrÁÚobjectrÂrÔÚcontextmanagerrÝr5rárâr7rêrór÷rþrrr r rrrr8rrrrr#r&r(r(r(r*ÚsÜ            0 ú     "         ú E$       #