3
ÀÞL]‡—  ã            !   @   s$  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ d d	lm Z! d d
l"m#Z$ d dl%m&Z& d dl'm(Z(m)Z) d dl*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 e�rhd dlm:Z; nd dlm;Z; e6�rÎd dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZJ d dlKmLZL y"d dl<mMZMmNZN eNeOeOeOf ZPW n" eQk
�r   dd„ ZMdZPY nX dddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3gZRejSeTƒZUejSd4ƒZVd5ZWd6ZXd«ZYd¬ZZd>eXfZ[d­Z\e[eY e\ eZ Z]e[e\ Z^yd dl_Z_e^eY7 Z^W n  eQk
�rÆ   eUj`dBƒ Y nX yd dlaZae^eZ7 Z^W n  eQk
�rü   eUj`dCƒ Y nX dDdE„ ZbdFdG„ ZcdHd.„ ZddId(„ ZeedJdKdL�d®dNd„ƒZfdOdP„ ZgdQdR„ ZhdSd„ Zid¯dUd„ZjdVdW„ ZkdXdY„ ZldZd„ Zmd[d\„ Znd]d^„ Zod_d „ Zpd`d!„ Zqdad"„ Zrdbd#„ Zsejtfdcdd„Zuded$„ Zvdfd%„ Zwd°dhd&„Zxdid„ Zydjd'„ Zzdkdl„ Z{dmdn„ Z|dodp„ Z}dqdr„ Z~dsdt„ Zdge1dgdMdMdfdudv„Z€dwdx„ Z�dydz„ Z‚d{d|„ Zƒd±d}d)„Z„d~d*„ Z…dd+„ Z†d€d�„ Z‡d‚dƒ„ Zˆd²d…d,„Z‰d†d‡„ ZŠG dˆd‰„ d‰e‹ƒZŒG dŠd‹„ d‹e;ƒZ�ejŽdŒd�„ ƒZ�dŽd-„ Z�d�d�„ Z‘G d‘d’„ d’e‹ƒZ’d³d“d2„Z“d”d•„ Z”d–d—„ Z•d˜d™„ Z–dšd›„ Z—dœd�„ Z˜dždŸ„ Z™d d¡„ Zšd¢d£„ Z›d¤d¥„ Zœd¦d3„ Z�d§d¨„ Zžd©dª„ ZŸdS )´é    )Úabsolute_importN)Údeque)Úpkg_resources)Úretry)ÚPY2Ú	text_type)ÚinputÚshlex_quote)Úparse)Úrequest)Úunquote)Ú__version__)ÚCommandErrorÚInstallationError)Úsite_packagesÚ	user_site)ÚWINDOWSÚconsole_to_strÚ
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ÚMappingÚMatchÚOptionalÚTextÚUnion)ÚDistribution)ÚLink)ÚSpinnerInterface)ÚcastÚTuplec             C   s   |S )N© )ÚtypÚvalr,   r,   ú7/tmp/pip-build-69lrc5qx/pip/pip/_internal/utils/misc.pyr*   ?   s    r*   ÚrmtreeÚdisplay_pathÚ
backup_dirÚaskÚsplitextÚformat_sizeÚis_installable_dirÚis_svn_pageÚfile_contentsÚsplit_leading_dirÚhas_leading_dirÚnormalize_pathÚrenamesÚget_progÚ
unzip_fileÚ
untar_fileÚunpack_fileÚcall_subprocessÚcaptured_stdoutÚ
ensure_dirÚARCHIVE_EXTENSIONSÚSUPPORTED_EXTENSIONSÚWHEEL_EXTENSIONÚget_installed_versionÚremove_auth_from_urlzpip.subprocessorz(----------------------------------------z.whlú.tar.bz2ú.tbzú.tar.xzú.txzú.tlzú.tar.lzú	.tar.lzmaz.zipú.tar.gzú.tgzú.tarzbz2 module is not availablezlzma module is not availablec              C   s<   t jjt jjtƒddƒ} t jj| ƒ} djt| tj	d d… ƒS )Nz..zpip {} from {} (python {})é   )
ÚosÚpathÚjoinÚdirnameÚ__file__ÚabspathÚformatr   ÚsysÚversion)Úpip_pkg_dirr,   r,   r/   Úget_pip_versionm   s    r^   c             C   sD   t | ƒdk r"| dt | ƒ d 7 } nt | ƒdkr:| dd… } tt| ƒ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).
    rS   r   N)r   )Úlenr*   ÚVersionInfo)Zpy_version_infor,   r,   r/   Únormalize_version_infoy   s
    ra   c             C   sD   yt j| ƒ W n0 tk
r> } z|jtjkr.‚ W Y dd}~X nX dS )z os.path.makedirs without EEXIST.N)rT   ÚmakedirsÚOSErrorÚerrnoÚEEXIST)rU   Úer,   r,   r/   rC   �   s
    c              C   sL   y,t jjtjd ƒ} | dkr&dtj S | S W n tttfk
rF   Y nX dS )Nr   ú__main__.pyú-cz	%s -m pipÚpip)rg   rh   )	rT   rU   Úbasenamer[   ÚargvÚ
executableÚAttributeErrorÚ	TypeErrorÚ
IndexError)Úprogr,   r,   r/   r=   —   s    
i¸  iô  )Ústop_max_delayÚ
wait_fixedFc             C   s   t j| |td� d S )N)Úignore_errorsÚonerror)Úshutilr0   Úrmtree_errorhandler)Údirrs   r,   r,   r/   r0   ¥   s    c             C   s2   t j|ƒjtj@ r,t j|tjƒ | |ƒ dS ‚ dS )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)rT   ÚstatÚst_modeÚS_IREADÚchmodÚS_IWRITE)ÚfuncrU   Úexc_infor,   r,   r/   rv   ¬   s
    rv   c             C   sd   | dkrdS t | tƒr| S y| jtjƒ dƒ}W n0 tk
r^   trRtdj| ƒƒ}nt	| ƒ}Y nX |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Ústrictzb{!r})
Ú
isinstancer   Údecoder[   ÚgetfilesystemencodingÚUnicodeDecodeErrorr   r   rZ   Úascii)rU   r1   r,   r,   r/   Úpath_to_display»   s    	
r…   c             C   st   t jjt jj| ƒƒ} tjd dkrB| jtjƒ dƒ} | jtj	ƒ dƒ} | j
t jƒ t jj ƒrpd| tt jƒ ƒd…  } | S )zTGives the display value for a given path, making it relative to cwd
    if possible.r   é   ÚreplaceÚ.N)rT   rU   ÚnormcaserY   r[   Úversion_infor�   r‚   ÚencodeÚgetdefaultencodingÚ
startswithÚgetcwdÚsepr_   )rU   r,   r,   r/   r1   Ý   s    ú.bakc             C   s:   d}|}x(t jj| | ƒr0|d7 }|t|ƒ }q
W | | S )z\Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)é   )rT   rU   ÚexistsÚstr)rw   ÚextÚnÚ	extensionr,   r,   r/   r2   ê   s    c             C   s2   x&t jjddƒjƒ D ]}||kr|S qW t| |ƒS )NÚPIP_EXISTS_ACTIONÚ )rT   ÚenvironÚgetÚsplitr3   )ÚmessageÚoptionsÚactionr,   r,   r/   Úask_path_existsö   s    rŸ   c             C   s   t jjdƒrtd|  ƒ‚dS )z&Raise an error if no input is allowed.ÚPIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sN)rT   r™   rš   Ú	Exception)rœ   r,   r,   r/   Ú_check_no_inputþ   s    r¢   c             C   sJ   xDt | ƒ t| ƒ}|jƒ jƒ }||kr>td|dj|ƒf ƒ q|S qW dS )z@Ask the message interactively, with the given possible responsesz<Your response (%r) was not one of the expected responses: %sz, N)r¢   r   ÚstripÚlowerÚprintrV   )rœ   r�   Úresponser,   r,   r/   r3     s    c             C   s   t | ƒ t| ƒS )zAsk for input interactively.)r¢   r   )rœ   r,   r,   r/   Ú	ask_input  s    r§   c             C   s   t | ƒ tj| ƒS )z!Ask for a password interactively.)r¢   Úgetpass)rœ   r,   r,   r/   Úask_password  s    r©   c             C   sL   | dkrd| d d  S | d	kr,d| d  S | dkr@d| d  S d|  S d S )
Niè  z%.1fMBg     @�@é
   z%ikBz%.1fkBz%ibytesi@B i'  r,   )Úbytesr,   r,   r/   r5   &  s    c             C   sP   t jj| ƒsdS t jj| dƒ}t jj|ƒr.dS t jj| dƒ}t jj|ƒrLdS dS )zBIs path is a directory containing setup.py or pyproject.toml?
    Fzsetup.pyTzpyproject.toml)rT   rU   ÚisdirrV   Úisfile)rU   Úsetup_pyZpyproject_tomlr,   r,   r/   r6   2  s    c             C   s   t jd| ƒot jd| t jƒS )zT
    Returns true if the page appears to be the index page of an svn repository
    z<title>[^<]*Revision \d+:z#Powered by (?:<a[^>]*?>)?Subversion)ÚreÚsearchÚI)Úhtmlr,   r,   r/   r7   A  s    c          	   C   s$   t | dƒ�}|jƒ jdƒS Q R X d S )NÚrbzutf-8)ÚopenÚreadr�   )ÚfilenameÚfpr,   r,   r/   r8   J  s    c             c   s    x| j |ƒ}|sP |V  qW dS )z7Yield pieces of data from a file-like object until EOF.N)rµ   )ÚfileÚsizeÚchunkr,   r,   r/   Úread_chunksP  s
    
r»   c             C   sh   | j dƒj dƒ} d| krHd| kr4| jdƒ| jdƒk s<d| krH| jddƒS d| kr\| jddƒS | dgS d S )Nú/ú\r‘   r˜   )ÚlstripÚfindr›   )rU   r,   r,   r/   r9   Y  s    $c             C   sD   d}x:| D ]2}t |ƒ\}}|s"dS |dkr0|}q
||kr
dS q
W dS )zyReturns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)NFT)r9   )ÚpathsÚcommon_prefixrU   ÚprefixÚrestr,   r,   r/   r:   e  s    
Tc             C   s2   t | ƒ} |rtjj| ƒ} ntjj| ƒ} tjj| ƒS )zN
    Convert a path to its canonical, case-normalized, absolute version.

    )r   rT   rU   ÚrealpathrY   r‰   )rU   Úresolve_symlinksr,   r,   r/   r;   u  s
    c             C   s@   t j| ƒ\}}|jƒ jdƒr8|dd… | }|dd… }||fS )z,Like os.path.splitext, but take off .tar tooz.taré   NéüÿÿÿrÇ   )Ú	posixpathr4   r¤   Úendswith)rU   Úbaser”   r,   r,   r/   r4   ƒ  s
    c             C   s|   t jj|ƒ\}}|r0|r0t jj|ƒ r0t j|ƒ tj| |ƒ t jj| ƒ\}}|rx|rxyt j|ƒ W n tk
rv   Y nX dS )z7Like os.renames(), but handles renaming across devices.N)	rT   rU   r›   r’   rb   ru   ÚmoveÚ
removedirsrc   )ÚoldÚnewÚheadÚtailr,   r,   r/   r<   �  s    
c             C   s   t ƒ s
dS t| ƒjttjƒƒ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."

    T)r   r;   r�   r[   rÂ   )rU   r,   r,   r/   Úis_localŸ  s    rÑ   c             C   s   t t| ƒƒ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_local¬  s    	rÔ   c             C   s   t t| ƒƒ}|jt tƒƒS )zF
    Return True if given Distribution is installed in user site.
    )r;   rÒ   r�   r   )rÓ   Ú	norm_pathr,   r,   r/   Údist_in_usersite¸  s    rÖ   c             C   s   t t| ƒƒjt tƒƒS )z[
    Return True if given Distribution is installed in
    sysconfig.get_python_lib().
    )r;   rÒ   r�   r   )rÓ   r,   r,   r/   Údist_in_site_packagesÁ  s    
r×   c             C   s8   x2t jD ](}tjj|| jd ƒ}tjj|ƒrdS qW dS )zC
    Return True if given Distribution is an editable install.
    z	.egg-linkTF)r[   rU   rT   rV   Úproject_namer­   )rÓ   Ú	path_itemÚegg_linkr,   r,   r/   Údist_is_editableÌ  s
    rÛ   c                s€   |rt j|ƒ}nt j}| r t‰ndd„ ‰|r6dd„ ‰ ndd„ ‰ |rLdd„ ‰ndd„ ‰|r^t‰nd	d
„ ‰‡ ‡‡‡‡fd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.
    c             S   s   dS )NTr,   )Údr,   r,   r/   Ú
local_testü  s    z/get_installed_distributions.<locals>.local_testc             S   s   dS )NTr,   )rÜ   r,   r,   r/   Úeditable_test   s    z2get_installed_distributions.<locals>.editable_testc             S   s
   t | ƒ S )N)rÛ   )rÜ   r,   r,   r/   rÞ     s    c             S   s   t | ƒS )N)rÛ   )rÜ   r,   r,   r/   Úeditables_only_test  s    z8get_installed_distributions.<locals>.editables_only_testc             S   s   dS )NTr,   )rÜ   r,   r,   r/   rß   
  s    c             S   s   dS )NTr,   )rÜ   r,   r,   r/   Ú	user_test  s    z.get_installed_distributions.<locals>.user_testc                s:   g | ]2}ˆ|ƒr|j ˆkrˆ |ƒrˆ|ƒrˆ|ƒr|‘qS r,   )Úkey)Ú.0rÜ   )rÞ   rß   rÝ   Úskiprà   r,   r/   ú
<listcomp>  s    
z/get_installed_distributions.<locals>.<listcomp>)r   Ú
WorkingSetÚworking_setrÔ   rÖ   )Ú
local_onlyrã   Úinclude_editablesÚeditables_onlyÚ	user_onlyrÀ   ræ   r,   )rÞ   rß   rÝ   rã   rà   r/   Úget_installed_distributionsØ  s     

rë   c             C   s„   g }t ƒ r6tƒ r|jtƒ qN|jtƒ trN|jtƒ ntrD|jtƒ |jtƒ x0|D ](}tjj|| jƒd }tjj	|ƒrT|S qTW dS )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.
    z	.egg-linkN)
r   r   Úappendr   r   rT   rU   rV   rØ   r­   )rÓ   ÚsitesÚsiteÚegglinkr,   r,   r/   Úegg_link_path  s    



rð   c             C   s   t | ƒ}|r|S | jS )zÿ
    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.

    )rð   Úlocation)rÓ   rÚ   r,   r,   r/   rÒ   D  s    	rÒ   c              C   s   t jdƒ} t j| ƒ | S )zBGet the current umask which involves having to set it temporarily.r   )rT   Úumask)Úmaskr,   r,   r/   Úcurrent_umaskS  s    

rô   c             C   s&  t |ƒ t| dƒ}�ztj|dd�}t|jƒ ƒo2|}xÞ|jƒ D ]Ò}|j}|}|r\t|ƒd }t	j
j||ƒ}t	j
j|ƒ}	|jdƒsŠ|jdƒr”t |ƒ q>t |	ƒ |j|ƒ}
z&t|dƒ�}tj|
|ƒ W dQ R X W d|
jƒ  |jd	? }|oôtj|ƒoô|d
@ �rt	j|dtƒ  d
B ƒ X q>W W d|jƒ  X dS )aŸ  
    Unzip the file (with path `filename`) to the destination `location`.  All
    files are written based on system defaults and umask (i.e. permissions are
    not preserved), except that regular file members with any execute
    permissions (user, group, or world) have "chmod +x" applied after being
    written. Note that for windows, any execute changes using os.chmod are
    no-ops per the python docs.
    r³   T)Ú
allowZip64r‘   r¼   r½   ÚwbNé   éI   iÿ  )rC   r´   ÚzipfileÚZipFiler:   ÚnamelistÚinfolistr¶   r9   rT   rU   rV   rW   rÉ   ru   ÚcopyfileobjÚcloseÚexternal_attrrx   ÚS_ISREGr{   rô   )r¶   rñ   ÚflattenÚzipfpÚzipÚleadingÚinfoÚnameÚfnrw   r·   ÚdestfpÚmoder,   r,   r/   r>   Z  s0    




 c              C   s  t |ƒ | jƒ jdƒs$| jƒ jdƒr*d}nL| jƒ jtƒr>d}n8| jƒ jtƒrRd}n$| jƒ jdƒrfd}ntjd| ƒ d	}tj| |ƒ}�znt	d
d„ |j
ƒ D ƒƒ}�xP|j
ƒ D �]B}|j}|rÄt|ƒd }tjj||ƒ}|jƒ rät |ƒ q¨|jƒ �r:y|j||ƒ W n8 tk
�r6 } ztjd| |j|ƒ w¨W Y dd}~X nX q¨y|j|ƒ}	W n< ttfk
�r„ } ztjd| |j|ƒ w¨W Y dd}~X nX t tjj|ƒƒ t|dƒ�}
tj|	|
ƒ W dQ R X |	jƒ  |j||ƒ |jd@ r¨tj|dtƒ  dB ƒ q¨W W d|jƒ  X dS )aŸ  
    Untar the file (with path `filename`) to the destination `location`.
    All files are written based on system defaults and umask (i.e. permissions
    are not preserved), except that regular file members with any execute
    permissions (user, group, or world) have "chmod +x" applied after being
    written.  Note that for windows, any execute changes using os.chmod are
    no-ops per the python docs.
    z.gzz.tgzzr:gzzr:bz2zr:xzz.tarÚrz-Cannot determine compression type for file %szr:*c             S   s   g | ]
}|j ‘qS r,   )r  )râ   Úmemberr,   r,   r/   rä   £  s    zuntar_file.<locals>.<listcomp>r‘   z/In the tar file %s the member %s is invalid: %sNrö   rø   iÿ  )rC   r¤   rÉ   ÚBZ2_EXTENSIONSÚXZ_EXTENSIONSÚloggerÚwarningÚtarfiler´   r:   Ú
getmembersr  r9   rT   rU   rV   r¬   ÚissymÚ_extract_memberr¡   ÚextractfileÚKeyErrorrm   rW   ru   rý   rþ   Úutimer	  r{   rô   )r¶   rñ   r	  Útarr  r  r  rU   Úexcr·   r  r,   r,   r/   r?   ˆ  s\    



c             C   sÚ   t jj| ƒ} |dks,| jƒ jtƒs,tj| ƒrDt| || jdƒ d� n’|dkslt	j
| ƒsl| jƒ jtt t ƒrxt| |ƒ n^|rº|jdƒrºtt| ƒƒrºddlm} d|j }|ƒ j||d	� ntjd
| ||ƒ td| ƒ‚d S )Nzapplication/zipz.whl)r  zapplication/x-gzipz	text/htmlr   )Ú
Subversionzsvn+)ÚurlzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of %s)rT   rU   rÄ   r¤   rÉ   ÚZIP_EXTENSIONSrù   Ú
is_zipfiler>   r  Ú
is_tarfileÚTAR_EXTENSIONSr  r  r?   r�   r7   r8   Zpip._internal.vcs.subversionr  r  Úunpackr  Úcriticalr   )r¶   rñ   Úcontent_typeÚlinkr  r  r,   r,   r/   r@   Ô  s.    



c             C   s   dj dd„ | D ƒƒS )z/
    Format command arguments for display.
    ú c             s   s   | ]}t |ƒV  qd S )N)r	   )râ   Úargr,   r,   r/   ú	<genexpr>  s    z&format_command_args.<locals>.<genexpr>)rV   )Úargsr,   r,   r/   Úformat_command_argsü  s    r'  c       	      C   sD   t | ƒ}t|dd�}t|ƒ}dj|ƒ}dj|||t|ƒ|td�}|S )z§
    Create and return the error message to use to log a subprocess error
    with command output.

    :param lines: A list of lines, each ending with a newline.
    zcommand bytes)Údescr˜   zŸCommand errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider})Úexit_statusÚcommand_displayÚcwd_displayZ
line_countÚoutputZdivider)r'  r   r…   rV   rZ   r_   ÚLOG_DIVIDER)	Úcmd_argsÚcwdÚlinesr)  Úcommandr*  r+  r,  Úmsgr,   r,   r/   Úmake_subprocess_output_error  s    
r3  Úraisec	             C   s,  |dkrg }|dkrg }|r*t j}	tj}
nt j}	tj}
t jƒ |
k}| oN|dk	}|dkr`t| ƒ}|	d|ƒ tj	j
ƒ }|r‚|j|ƒ x|D ]}|j|dƒ qˆW y*tj| tjtjtj||d�}|jjƒ  W n2 tk
rø } zt jd||ƒ ‚ W Y dd}~X nX g }xHt|jjƒ ƒ}|�sP |jƒ }|j|d ƒ |	|ƒ |�r |jƒ  �q W z|jƒ  W d|j�rh|jjƒ  X |j�oz|j|k}|�rž|�r”|jdƒ n
|jdƒ |�r"|dk�rè|�sÐt| |||jd	�}t j|ƒ d
j |j|ƒ}t!|ƒ‚n:|dk�rt j"d||j|ƒ n|dk�rnt#dt$|ƒ ƒ‚dj%|ƒS )a   
    Args:
      show_stdout: if true, use INFO to log the subprocess's stderr and
        stdout streams.  Otherwise, use DEBUG.  Defaults to False.
      extra_ok_returncodes: an iterable of integer return codes that are
        acceptable, in addition to 0. Defaults to None, which means [].
      unset_environ: an iterable of environment variable names to unset
        prior to calling subprocess.Popen().
    NzRunning command %s)ÚstderrÚstdinÚstdoutr/  Úenvz#Error %s while executing command %sÚ
ÚerrorÚdoner4  )r.  r/  r0  r)  zSCommand errored out with exit status {}: {} Check the logs for full command output.Úwarnz$Command "%s" had error code %s in %sÚignorezInvalid value: on_returncode=%sr˜   )&Úsubprocess_loggerr  Ústd_loggingÚINFOÚdebugÚDEBUGÚgetEffectiveLevelr'  rT   r™   ÚcopyÚupdateÚpopÚ
subprocessÚPopenÚSTDOUTÚPIPEr6  rþ   r¡   r   r   r7  ÚreadlineÚrstriprì   ÚspinÚwaitÚ
returncodeÚfinishr3  r:  rZ   r   r  Ú
ValueErrorÚreprrV   )ÚcmdÚshow_stdoutr/  Úon_returncodeZextra_ok_returncodesÚcommand_descÚextra_environZunset_environÚspinnerZlog_subprocessZ
used_levelZshowing_subprocessZuse_spinnerr8  r  Úprocr  Ú
all_outputÚlineZproc_had_errorr2  Zexc_msgr,   r,   r/   rA   .  sˆ    













c             C   s   t j| ƒ t| ƒ d S )N)rT   rb   r   )Ú	build_dirr,   r,   r/   Ú_make_build_dir´  s    
r]  c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚFakeFilezQWrap a list of lines in an object with readline() to make
    ConfigParser happy.c             C   s   dd„ |D ƒ| _ d S )Nc             s   s   | ]
}|V  qd S )Nr,   )râ   Úlr,   r,   r/   r%  ½  s    z$FakeFile.__init__.<locals>.<genexpr>)Ú_gen)Úselfr0  r,   r,   r/   Ú__init__¼  s    zFakeFile.__init__c             C   sD   y*y
t | jƒS  tk
r&   | jj ƒ S X W n tk
r>   dS X d S )Nr˜   )Únextr`  Ú	NameErrorÚStopIteration)ra  r,   r,   r/   rK  ¿  s    
zFakeFile.readlinec             C   s   | j S )N)r`  )ra  r,   r,   r/   Ú__iter__È  s    zFakeFile.__iter__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rb  rK  rf  r,   r,   r,   r/   r^  ¹  s   	r^  c               @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚStreamWrapperc             C   s   || _ | ƒ S )N)Úorig_stream)Úclsrl  r,   r,   r/   Úfrom_streamÎ  s    zStreamWrapper.from_streamc             C   s   | j jS )N)rl  Úencoding)ra  r,   r,   r/   ro  Ô  s    zStreamWrapper.encodingN)rg  rh  ri  Úclassmethodrn  Úpropertyro  r,   r,   r,   r/   rk  Ì  s   rk  c             c   s@   t t| ƒ}tt| tj|ƒƒ zt t| ƒV  W dtt| |ƒ X dS )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)Úgetattrr[   Úsetattrrk  rn  )Ústream_nameÚorig_stdoutr,   r,   r/   Úcaptured_outputÙ  s
    
rv  c               C   s   t dƒ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.
    r7  )rv  r,   r,   r,   r/   rB   è  s    	c               C   s   t dƒS )z 
    See captured_stdout().
    r5  )rv  r,   r,   r,   r/   Úcaptured_stderrô  s    rw  c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú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
    c             C   s   t |dƒ| _|| _d S )Nrj  )rr  rj  r}   )ra  r}   r,   r,   r/   rb    s    zcached_property.__init__c             C   s(   |d kr| S | j |ƒ }|j| j j< |S )N)r}   Ú__dict__rg  )ra  Úobjrm  Úvaluer,   r,   r/   Ú__get__  s    zcached_property.__get__N)rg  rh  ri  rj  rb  r|  r,   r,   r,   r/   rx  û  s   rx  c             C   s4   t jj| ƒ}|dkrt jƒ }|j|ƒ}|r0|jS dS )zCGet the installed version of dist_name avoiding pkg_resources cacheN)r   ÚRequirementr
   rå   r¿   r\   )Ú	dist_nameræ   ÚreqrÓ   r,   r,   r/   rG     s
    
c             C   s   t | dd� dS )zConsume an iterable at C speed.r   )ÚmaxlenN)r   )Úiteratorr,   r,   r/   Úconsume!  s    r‚  c              O   s@   t t| tt| ƒƒƒf|Ž}dd„ |jƒ D ƒ}||d< tdf |ƒS )Nc             S   s   i | ]\}}||“qS r,   r,   )râ   rá   r{  r,   r,   r/   ú
<dictcomp>)  s    zenum.<locals>.<dictcomp>Zreverse_mappingÚEnum)Údictr  Úranger_   ÚitemsÚtype)Z
sequentialÚnamedÚenumsÚreverser,   r,   r/   Úenum'  s    rŒ  c             C   s*   t jjt jj| ƒƒ} tjdtj| ƒƒ}|S )zh
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    zfile:)rT   rU   ÚnormpathrY   Úurllib_parseÚurljoinÚurllib_requestÚpathname2url)rU   r  r,   r,   r/   Úpath_to_url.  s    r’  c             C   sX   d| kr| dfS | j ddƒ\}} d|kr6|jddƒ}n|df}tdd„ |D ƒƒ}| |fS )zp
    Parse out and remove the auth information from a netloc.

    Returns: (netloc, (username, password)).
    ú@Nr‘   ú:c             s   s"   | ]}|d krd nt |ƒV  qd S )N)Úurllib_unquote)râ   Úxr,   r,   r/   r%  O  s    z)split_auth_from_netloc.<locals>.<genexpr>)NN)Úrsplitr›   Útuple)ÚnetlocÚauthÚ	user_passr,   r,   r/   Úsplit_auth_from_netloc9  s    rœ  c             C   sB   t | ƒ\} \}}|dkr| S |dkr(dnd}djtj|ƒ|| d�S )z�
    Replace the password in a netloc with "****", if it exists.

    For example, "user:pass@example.com" returns "user:****@example.com".
    Nr˜   z:****z{user}{password}@{netloc})ÚuserÚpasswordr™  )rœ  rZ   rŽ  Úquote)r™  r�  rž  r,   r,   r/   Úredact_netlocU  s    r   c             C   s@   t j| ƒ}||jƒ}|j|d |j|j|jf}t j|ƒ}||fS )aR  Transform 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Ž  Úurlsplitr™  ÚschemerU   ÚqueryÚfragmentÚ
urlunsplit)r  Ztransform_netlocÚpurlZnetloc_tupleÚ
url_piecesÚsurlr,   r,   r/   Ú_transform_urle  s
    



r©  c             C   s   t | ƒS )N)rœ  )r™  r,   r,   r/   Ú_get_netlocy  s    rª  c             C   s
   t | ƒfS )N)r   )r™  r,   r,   r/   Ú_redact_netloc}  s    r«  c             C   s   t | tƒ\}\}}|||fS )z†
    Parse a url into separate netloc, auth, and url with no auth.

    Returns: (url_without_auth, netloc, (username, password))
    )r©  rª  )r  Zurl_without_authr™  rš  r,   r,   r/   Úsplit_auth_netloc_from_url�  s    r¬  c             C   s   t | tƒd S )z7Return a copy of url with 'username:password@' removed.r   )r©  rª  )r  r,   r,   r/   rH   Œ  s    c             C   s   t | tƒd S )z.Replace the password in a given url with ****.r   )r©  r«  )r  r,   r,   r/   Úredact_password_from_url”  s    r­  c             C   sz   ddj tjd ƒdj tjdd… Ž g}| oBtoBtjjtjd ƒ|k}|rvtjddgtjd	d…  }t	d
j dj
|ƒƒƒ‚dS )z�Protection of pip.exe from modification on Windows

    On Windows, any operation modifying pip should be run as:
        python -m pip ...
    zpip.exez	pip{}.exer   zpip{}.{}.exeNr†   z-mri   r‘   z3To modify pip, please run the following command:
{}r#  )rZ   r[   rŠ   r   rT   rU   rj   rk   rl   r   rV   )Zmodifying_pipZ	pip_namesZshould_show_use_python_msgZnew_commandr,   r,   r/   Ú(protect_pip_from_modification_on_windowsš  s    
r®  )rI   rJ   )rK   rL   rM   rN   rO   )rP   rQ   rR   )F)r�   )T)T)FNr4  NNNNN)N) Ú
__future__r   Ú
contextlibrd   r¨   ÚioÚloggingr?  rT   rÈ   r¯   ru   rx   rG  r[   r  rù   Úcollectionsr   Úpip._vendorr   Zpip._vendor.retryingr   Zpip._vendor.sixr   r   Zpip._vendor.six.movesr   r	   Zpip._vendor.six.moves.urllibr
   rŽ  r   r�  Z"pip._vendor.six.moves.urllib.parser   r•  ri   r   Zpip._internal.exceptionsr   r   Zpip._internal.locationsr   r   Zpip._internal.utils.compatr   r   r   r   r   Z pip._internal.utils.marker_filesr   Zpip._internal.utils.typingr   Zpip._internal.utils.virtualenvr   r   r   r   Útypingr   r   r   r    r!   r"   r#   r$   r%   r&   Zpip._vendor.pkg_resourcesr'   Zpip._internal.models.linkr(   Zpip._internal.utils.uir)   r*   r+   Úintr`   ÚImportErrorÚ__all__Ú	getLoggerrg  r  r>  r-  rF   r  r  r  r  rD   rE   Úbz2rA  Úlzmar^   ra   rC   r=   r0   rv   r…   r1   r2   rŸ   r¢   r3   r§   r©   r5   r6   r7   r8   ÚDEFAULT_BUFFER_SIZEr»   r9   r:   r;   r4   r<   rÑ   rÔ   rÖ   r×   rÛ   rë   rð   rÒ   rô   r>   r?   r@   r'  r3  rA   r]  Úobjectr^  rk  Úcontextmanagerrv  rB   rw  rx  rG   r‚  rŒ  r’  rœ  r   r©  rª  r«  r¬  rH   r­  r®  r,   r,   r,   r/   Ú<module>   s$  0




"

		

	?'
.L(,       
}
