U .ec@sddlmZddlZddlZddlZddlZddlZddlZddlZddl 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/m0Z0m1Z1er8ddlm2Z3n ddlm3Z3e.rddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>ddl?m@Z@edddddddddd d!d"d#d$gZCeDeEZFd%d&ZGd'd(ZHd)d"ZId*d ZJed+d,d-dd/dZKd0d1ZLd2d3ZMd4dZNdd6dZOd7d8ZPd9d:ZQd;dZRdd?ZTd@dZUdAdZVejWfdBdCZXddEdZYdFdZZdGdZ[dHdIZ\dJdKZ]dLdMZ^dNdOZ_dPdQZ`dRdSZadDe)dDd.d.dfdTdUZbdVdWZcdXdYZddZd[Zed\d]ZfGd^d_d_egZhGd`dadae3ZiejjdbdcZkddd!ZldedfZmGdgdhdhegZnddid#ZodjdkZpdldmZqdndoZrddqdrZsdsdtZtdudvZudwdxZvdydzZwd{d|Zxd}d~ZyddZzdd$Z{ddZ|GdddegZ}ddZ~ddZddZddZdS))absolute_importNdeque) pkg_resources)retry)PY2 text_type)input)parse)unquote) __version__) CommandError)distutils_schemeget_major_minor_version site_packages user_site)WINDOWS expanduser stdlib_pkgsstr_to_display)write_delete_marker_file)MYPY_CHECK_RUNNING)running_under_virtualenvvirtualenv_no_global)BytesIO)StringIO) AnyAnyStr ContainerIterableListOptionalTextTupleUnioncast) DistributioncCs|SN)Ztype_valuer(r(}z|jtjkr.W5d}~XYnXdS)z os.path.makedirs without EEXIST.N)r9makedirsOSErrorerrnoZEEXIST)r:er(r(r*r6qs  c CsPz0tjtjd}|dkr(dtjWS|WSWntttfk rJYnXdS)Nr)z __main__.pyz-cz %s -m pippip) r9r:basenamesysargv executableAttributeError TypeError IndexError)progr(r(r*r4{s  i i)Zstop_max_delayZ wait_fixedFcCstj||tddS)N) ignore_errorsonerror)shutilr+rmtree_errorhandler)dirrRr(r(r*r+sc CsXzt|jtj@ }Wnttfk r2YdSX|rRt|tj||dSdS)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)r9statst_modeS_IWRITEIOErrorrFchmod)funcr:exc_infoZhas_attr_readonlyr(r(r*rUsrUcCsd|dkr dSt|tr|Sz|td}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. Nstrictzb{!r}) isinstancerdecoderKgetfilesystemencodingUnicodeDecodeErrorrrr?ascii)r:r,r(r(r*path_to_displays  rdcCsttjtj|}tjddkrB|td}|t d}| t tjj rpd|t t d}|S)zTGives the display value for a given path, making it relative to cwd if possible.rreplace.N)r9r:normcaser>rK version_infor`raencodegetdefaultencoding startswithgetcwdseprCr: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:existsstr)rVextn extensionr(r(r*r-s cCs2tjddD]}||kr|Sqt||S)NZPIP_EXISTS_ACTION)r9environgetsplitr.)messageoptionsactionr(r(r*ask_path_existss r~cCstjdrtd|dS)z&Raise an error if no input is allowed.Z PIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sN)r9rxry Exceptionr{r(r(r*_check_no_inputs  rcCsFt|t|}|}||krrh)r:Zresolve_symlinksr(r(r*r23s  cCs@t|\}}|dr8|dd|}|dd}||fS)z,Like os.path.splitext, but take off .tar tooz.tarN) posixpathr/rendswith)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)oldnewheadtailr(r(r*r3Ks  cCsts dS|ttjS)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)rrlr2rKprefixror(r(r*is_local]s rcCs 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_locationdistr(r(r* dist_is_localls rcCst|ttS)zF Return True if given Distribution is installed in user site. )rrlr2rrr(r(r*dist_in_usersitexsrcCst|ttS)z[ Return True if given Distribution is installed in sysconfig.get_python_lib(). )rrlr2rrr(r(r*dist_in_site_packagessrcCs,tt|}|ttddddS)zf Return True if given Distribution is installed in path matching distutils_scheme layout. rwZpurelibpythonr)r2rrlrrz)rZ norm_pathr(r(r*dist_in_install_paths rcCs6tjD]*}tj||jd}tj|rdSqdS)zC Return True if given Distribution is an editable install. .egg-linkTF)rKr:r9r; project_namer)rZ path_itemegg_linkr(r(r*dist_is_editables   rcs|rt|}ntj}|r tndd|r6ddndd|rLddndd|r^tnd d fd d |DS) 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. cSsdSNTr(dr(r(r* local_testsz/get_installed_distributions..local_testcSsdSrr(rr(r(r* editable_testsz2get_installed_distributions..editable_testcSs t| Sr'rrr(r(r*rscSst|Sr'rrr(r(r*editables_only_testsz8get_installed_distributions..editables_only_testcSsdSrr(rr(r(r*rscSsdSrr(rr(r(r* user_testsz.get_installed_distributions..user_testcs:g|]2}|r|jkr|r|r|r|qSr()key).0rrrrskiprr(r* s z/get_installed_distributions..)r WorkingSet working_setrr)Z local_onlyrZinclude_editablesZeditables_onlyZ user_onlypathsrr(rr*get_installed_distributionss    rcCsxg}tr*|ttsBtrB|tntr8|t|t|D],}tj||jd}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. rN) rappendrrrr9r:r;rr)rZsitesZsiteZegglinkr(r(r* egg_link_paths       rcCst|}|rt|St|jS)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). )rr2location)rrr(r(r*rs rcGstj|f|dSr')loggerinfo)msgargsr(r(r* write_outputsrcCst|t|dSr')r9rEr)Z build_dirr(r(r*_make_build_dirs rc@s(eZdZdZddZddZddZdS) FakeFilezQWrap a list of lines in an object with readline() to make ConfigParser happy.cCsdd|D|_dS)Ncss|] }|VqdSr'r()rlr(r(r* &sz$FakeFile.__init__.._gen)selflinesr(r(r*__init__%szFakeFile.__init__cCsPz4zt|jWWStk r0|jYWSXWntk rJYdSXdS)Nrw)nextr NameError StopIterationrr(r(r*readline(szFakeFile.readlinecCs|jSr'rrr(r(r*__iter__1szFakeFile.__iter__N)__name__ __module__ __qualname____doc__rrrr(r(r(r*r"s rc@s$eZdZeddZeddZdS) StreamWrappercCs ||_|Sr') orig_stream)clsrr(r(r* from_stream7szStreamWrapper.from_streamcCs|jjSr')rencodingrr(r(r*r=szStreamWrapper.encodingN)rrr classmethodrpropertyrr(r(r(r*r5s rc cs@tt|}tt|t|ztt|VW5tt||XdS)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)getattrrKsetattrrr)Z stream_nameZ orig_stdoutr(r(r*captured_outputBs  rcCstdS)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. stdoutrr(r(r(r*r5Qs cCstdS)z See captured_stdout(). stderrrr(r(r(r*captured_stderr]src@s eZdZdZddZddZdS)cached_propertyzA 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)rrr\)rr\r(r(r*rls zcached_property.__init__cCs(|dkr |S||}|j|jj<|Sr')r\__dict__r)robjrr)r(r(r*__get__pszcached_property.__get__N)rrrrrrr(r(r(r*rdsrcCs4tj|}|dkrt}||}|r0|jSdS)zCGet the installed version of dist_name avoiding pkg_resources cacheN)rZ Requirementr rfindversion)Z dist_namerZreqrr(r(r*r7xs   cCst|dddS)zConsume an iterable at C speed.r)maxlenNr)iteratorr(r(r*consumesrcOs@tt|tt|f|}dd|D}||d<tdd|S)NcSsi|]\}}||qSr(r()rrr)r(r(r* szenum..Zreverse_mappingEnumr()dictziprangerCitemstype)Z sequentialZnamedZenumsreverser(r(r*enumsrcCs*|dkr |Sd|krd|}d||S)z. Build a netloc from a host-port pair N:[{}]z{}:{})r?)Zhostportr(r(r* build_netlocs  rhttpscCs4|ddkr(d|kr(d|kr(d|}d||S)z) Build a full URL from a netloc. rre@[rz{}://{})countr?)netlocschemer(r(r*build_url_from_netlocs rcCst|}t|}|j|jfS)z2 Return the host-port pair from a netloc. )r urllib_parseZurlparseZhostnamer)rurlZparsedr(r(r* parse_netlocs 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)NNrqrNcss"|]}|dkrdnt|VqdSr')urllib_unquote)rxr(r(r*rsz)split_auth_from_netloc..)rsplitrztuple)rauthZ user_passr(r(r*split_auth_from_netlocsrcCsLt|\}\}}|dkr|S|dkr.d}d}nt|}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****rwz:****z{user}{password}@{netloc})userpasswordr)rrZquoter?)rr r r(r(r* redact_netlocs  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)rZurlsplitrrr:ZqueryZfragmentZ urlunsplit)rZtransform_netlocZpurlZ netloc_tupleZ url_piecesZsurlr(r(r*_transform_urls   r cCst|Sr')rrr(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_authrrr(r(r*split_auth_netloc_from_urlsrcCst|tdS)z7Return a copy of url with 'username:password@' removed.rrrr(r(r*r8scCst|tdS)z.Replace the password in a given url with ****.r)r rrr(r(r*redact_auth_from_urlsrc@s4eZdZddZddZddZddZd d Zd S) HiddenTextcCs||_||_dSr')secretredacted)rrrr(r(r*r"szHiddenText.__init__cCsdt|S)Nz)r?rsrr(r(r*__repr__+szHiddenText.__repr__cCs|jSr'rrr(r(r*__str__/szHiddenText.__str__cCs t|t|krdS|j|jkS)NF)rrrotherr(r(r*__eq__4szHiddenText.__eq__cCs ||k Sr'r(rr(r(r*__ne__?szHiddenText.__ne__N)rrrrrrrrr(r(r(r*r!s   rcCs t|ddS)Nrr)r)r)r(r(r* hide_valueDsrcCst|}t||dS)Nr)rr)rrr(r(r*hide_urlIsrcCst}dD]P}|dj|d|djtjd|d|djtjddd |iq |oxtoxtjtj d|k}|rtj d d gtj d 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 ... )rwz.exezpip{ext})rtz pip{}{ext}rz pip{}.{}{ext}Nrertz-mrIrqz3To modify pip, please run the following command: {} ) setaddr?rKrirr9r:rJrLrMr r;)Z modifying_pipZ pip_namesrtZshould_show_use_python_msgZ new_commandr(r(r*(protect_pip_from_modification_on_windowsOs," r#cCstjdk otjS)z!Is this console interactive? N)rKstdinisattyr(r(r(r*is_console_interactivemsr&)F)rp)T)N)r)Z __future__r contextlibrGrioZloggingr9rrTrWrK collectionsrZ pip._vendorrZpip._vendor.retryingrZpip._vendor.sixrrZpip._vendor.six.movesr Zpip._vendor.six.moves.urllibr rZ"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.virtualenvrrrrtypingrrrrr r!r"r#r$r%Zpip._vendor.pkg_resourcesr&intrB__all__Z getLoggerrrr@rDr6r4r+rUrdr,r-r~rr.rrr0r1DEFAULT_BUFFER_SIZErr2r/r3rrrrrrrrrrrobjectrrcontextmanagerrr5rrr7rrrrrrr r rrrr8rrrrr#r&r(r(r(r*s            0      "          E$       #