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:[email protected]" returns "user:****@example.com" - "[email protected]" 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$       #