3
zYðim  ã               @   s‚  d dl mZ 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mZmZ d dlmZmZmZmZmZ d dlm Z  d dl!m"Z" d d	l#m$Z$ d d
l%m&Z& e$�rd dlm'Z( nd dlm(Z( dddddddddddddddddddd d!d"d#d$gZ)e	j*e+ƒZ,dxZ-dyZ.dzZ/d{Z0e/e- e0 e. Z1e/e0 Z2yd dl3Z3e2e-7 Z2W n  e4k
�r®   e,j5d1ƒ Y nX yd dl6Z6e2e.7 Z2W n  e4k
�rä   e,j5d2ƒ Y nX d3d4„ Z7d5d!„ Z8d6d„ Z9e&d7d8d9�d|d;d„ƒZ:d<d=„ Z;d>d„ Z<d}d@d„Z=dAdB„ Z>dCd„ Z?dDd„ Z@dEd„ ZAdFd„ ZBdGd„ ZCejDfdHdI„ZEdJd„ ZFdKd„ ZGd~dMd„ZHdNd„ ZIdOd„ ZJdPdQ„ ZKdRdS„ ZLdTdU„ ZMdVdW„ ZNdXdY„ ZOdLedLd:d:fdZd[„ZPd\d]„ ZQd^d_„ ZRd`d„ ZSdadb„ ZTddcd„ZUddd„ ZVded„ ZWd€dgd„ZXdhdi„ ZYdjdk„ ZZG dldm„ dme[ƒZ\G dndo„ doe(ƒZ]ej^dpdq„ ƒZ_drd „ Z`G dsdt„ dte[ƒZad�dud$„Zbdvdw„ ZcdS )‚é    )Úabsolute_import)ÚdequeN)ÚInstallationError)Úconsole_to_strÚ
expanduserÚstdlib_pkgs)Úsite_packagesÚ	user_siteÚrunning_under_virtualenvÚvirtualenv_no_globalÚwrite_delete_marker_file)Úpkg_resources)Úinput)ÚPY2)Úretry)ÚBytesIO)ÚStringIOÚ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_terminal_sizeÚget_progÚ
unzip_fileÚ
untar_fileÚunpack_fileÚcall_subprocessÚcaptured_stdoutÚ
ensure_dirÚARCHIVE_EXTENSIONSÚSUPPORTED_EXTENSIONSÚget_installed_versionú.tar.bz2ú.tbzú.tar.xzú.txzú.tlzú.tar.lzú	.tar.lzmaú.zipú.whlú.tar.gzú.tgzú.tarzbz2 module is not availablezlzma module is not availablec             O   s,   yt | ƒS  tk
r&   |||Ž‚Y nX d S )N)Ú
__import__ÚImportError)Úpkg_or_module_stringÚExceptionTypeÚargsÚkwargs© r=   ú1/tmp/pip-build-ue6tjl93/pip/pip/utils/__init__.pyÚimport_or_raiseI   s    r?   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)ÚosÚmakedirsÚOSErrorÚerrnoÚEEXIST)ÚpathÚer=   r=   r>   r'   P   s
    c               C   sD   y$t jjtjd ƒdkr"dtj S W n tttfk
r>   Y nX dS )Nr   ú__main__.pyú-cz	%s -m pipÚpip)rG   rH   )	r@   rE   ÚbasenameÚsysÚargvÚ
executableÚAttributeErrorÚ	TypeErrorÚ
IndexErrorr=   r=   r=   r>   r!   Y   s    i¸  iô  )Ústop_max_delayÚ
wait_fixedFc             C   s   t j| |td� d S )N)Úignore_errorsÚonerror)Úshutilr   Úrmtree_errorhandler)ÚdirrS   r=   r=   r>   r   c   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)r@   ÚstatÚst_modeÚS_IREADÚchmodÚS_IWRITE)ÚfuncrE   Úexc_infor=   r=   r>   rV   i   s
    rV   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)r@   rE   ÚnormcaseÚabspathrK   Úversion_infoÚdecodeÚgetfilesystemencodingÚencodeÚgetdefaultencodingÚ
startswithÚgetcwdÚsepÚlen)rE   r=   r=   r>   r   x   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)é   )r@   rE   ÚexistsÚstr)rW   ÚextÚnÚ	extensionr=   r=   r>   r   „   s    c             C   s2   x&t jjddƒjƒ D ]}||kr|S qW t| |ƒS )NÚPIP_EXISTS_ACTIONÚ )r@   ÚenvironÚgetÚsplitr   )ÚmessageÚoptionsÚactionr=   r=   r>   Úask_path_exists�   s    r|   c             C   sZ   xTt jjdƒrtd|  ƒ‚t| ƒ}|jƒ jƒ }||krNtd|dj|ƒf ƒ q|S qW dS )z@Ask the message interactively, with the given possible responsesÚPIP_NO_INPUTz7No input was expected ($PIP_NO_INPUT set); question: %sz<Your response (%r) was not one of the expected responses: %sz, N)	r@   rv   rw   Ú	Exceptionr   ÚstripÚlowerÚprintÚjoin)ry   rz   Úresponser=   r=   r>   r   –   s    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>   r   ©   s    c             C   s2   t jj| ƒsdS t jj| dƒ}t jj|ƒr.dS dS )z@Return True if `path` is a directory containing a setup.py file.Fzsetup.pyT)r@   rE   Úisdirr‚   Úisfile)rE   Úsetup_pyr=   r=   r>   r   ´   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>   r   ¾   s    c          	   C   s$   t | dƒ�}|jƒ jdƒS Q R X d S )NÚrbzutf-8)ÚopenÚreadre   )ÚfilenameÚfpr=   r=   r>   r   Æ   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_chunksË   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fS d S )Nú/ú\rn   ru   )ÚlstripÚfindrx   )rE   r=   r=   r>   r   Ô   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)r   )ÚpathsÚcommon_prefixrE   ÚprefixÚrestr=   r=   r>   r   ß   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   r@   rE   Úrealpathrc   rb   )rE   Úresolve_symlinksr=   r=   r>   r   î   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¡   )Ú	posixpathr   r€   Úendswith)rE   Úbaserq   r=   r=   r>   r   û   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)	r@   rE   rx   ro   rA   rU   ÚmoveÚ
removedirsrB   )ÚoldÚnewÚheadÚtailr=   r=   r>   r     s    
c             C   sr   t | ƒ} t tjƒ}tƒ r(| jt tjƒƒS ddlm} | j|ƒrjx&|dƒjƒ D ]}| jt |ƒƒrLdS qLW dS dS dS )aB  
    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.)

    r   )Údistutils_schemeru   TFN)r   rK   rœ   r
   ri   Úpip.locationsr«   Úvalues)rE   rœ   r«   Ú
local_pathr=   r=   r>   Úis_local  s    

r¯   c             C   s   t t| ƒƒS )zh
    Return True if given Distribution object is installed somewhere pip
    is allowed to modify.

    )r¯   Údist_location)Údistr=   r=   r>   Údist_is_local5  s    r²   c             C   s   t t| ƒƒ}|jt tƒƒS )zF
    Return True if given Distribution is installed in user site.
    )r   r°   ri   r	   )r±   Ú	norm_pathr=   r=   r>   Údist_in_usersite>  s    r´   c             C   s   t t| ƒƒjt tƒƒS )ze
    Return True if given Distribution is installed in
    distutils.sysconfig.get_python_lib().
    )r   r°   ri   r   )r±   r=   r=   r>   Údist_in_site_packagesF  s    
rµ   c             C   s8   x2t jD ](}tjj|| jd ƒ}tjj|ƒrdS qW dS )z$Is distribution an editable install?z	.egg-linkTF)rK   rE   r@   r‚   Úproject_namer‡   )r±   Ú	path_itemÚegg_linkr=   r=   r>   Údist_is_editableP  s
    r¹   c                sl   | r
t ‰ndd„ ‰|r dd„ ‰ ndd„ ‰ |r6dd„ ‰ndd„ ‰|rHt‰nd	d
„ ‰‡ ‡‡‡‡fdd„tj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 ``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.

    c             S   s   dS )NTr=   )Údr=   r=   r>   Ú
local_testr  s    z/get_installed_distributions.<locals>.local_testc             S   s   dS )NTr=   )rº   r=   r=   r>   Úeditable_testv  s    z2get_installed_distributions.<locals>.editable_testc             S   s
   t | ƒ S )N)r¹   )rº   r=   r=   r>   r¼   y  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²   r´   r   Úworking_set)Ú
local_onlyrÁ   Úinclude_editablesÚeditables_onlyÚ	user_onlyr=   )r¼   r½   r»   rÁ   r¾   r>   Úget_installed_distributionsY  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	   r@   rE   r‚   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°   ·  s    r°   c           
   C   s’   dd„ } | dƒp| dƒp| dƒ}|sZy(t jt jƒ t jƒ}| |ƒ}t j|ƒ W n   Y nX |szt jjddƒt jjdd	ƒf}t|d ƒt|d ƒfS )
zlReturns a tuple (x, y) representing the width(x) and the height(x)
    in characters of the terminal window.c             S   sP   y4dd l }dd l}dd l}|jd|j| |jdƒƒ}W n
   d S |dkrLd S |S )Nr   ÚhhÚ1234)r   r   )ÚfcntlÚtermiosÚstructÚunpackÚioctlÚ
TIOCGWINSZ)ÚfdrÑ   rÒ   rÓ   Úcrr=   r=   r>   Úioctl_GWINSZÈ  s    z'get_terminal_size.<locals>.ioctl_GWINSZr   rn   r_   ÚLINESé   ÚCOLUMNSéP   )r@   rŽ   ÚctermidÚO_RDONLYÚcloserv   rw   Úint)rÙ   rØ   r×   r=   r=   r>   r    Å  s    c              C   s   t jdƒ} t j| ƒ | S )zBGet the current umask which involves having to set it temporarily.r   )r@   Úumask)Úmaskr=   r=   r>   Úcurrent_umaskã  s    

rä   c             C   s  t |ƒ t| dƒ}zòtj|dd�}t|jƒ ƒo0|}xÎ|jƒ D ]Â}|j}|j|ƒ}|}	|rdt	|ƒd }	t
jj||	ƒ}	t
jj|	ƒ}
|	jdƒs’|	jdƒrœt |	ƒ q<t |
ƒ t|	dƒ}z|j|ƒ W d|jƒ  |jd	? }|rütj|ƒrü|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)Ú
allowZip64rn   r–   r—   ÚwbNé   éI   iÿ  )r'   rŽ   ÚzipfileÚZipFiler   ÚnamelistÚinfolistr�   r�   r   r@   rE   r‚   Údirnamer£   Úwriterà   Úexternal_attrrX   ÚS_ISREGr[   rä   )r�   rÎ   ÚflattenÚzipfpÚzipÚleadingÚinfoÚnameÚdataÚfnrW   r‘   Úmoder=   r=   r>   r"   ê  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| |ƒ}�zxt	d
d„ |j
ƒ D ƒƒ}�xZ|j
ƒ D �]L}|j}|dkr¾q¨|rÎt|ƒd }tjj||ƒ}|jƒ rît |ƒ q¨|jƒ �rDy|j||ƒ W n8 tk
�r@ } 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 d kr|j ‘qS )Úpax_global_header)rö   )rÀ   Úmemberr=   r=   r>   rÂ   0  s    zuntar_file.<locals>.<listcomp>rû   rn   z/In the tar file %s the member %s is invalid: %sNræ   rè   iÿ  )r'   r€   r£   ÚBZ2_EXTENSIONSÚXZ_EXTENSIONSÚloggerÚwarningÚtarfilerŽ   r   Ú
getmembersrö   r   r@   rE   r‚   r†   ÚissymÚ_extract_memberr~   ÚextractfileÚKeyErrorrN   rí   rU   Úcopyfileobjrà   Úutimerù   r[   rä   )r�   rÎ   rù   Útarrô   rü   rø   rE   Úexcr‘   Údestfpr=   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| |ƒ nX|r´|jdƒr´tt| ƒƒr´ddlm} |d|j ƒj|ƒ ntjd	| ||ƒ td
| ƒ‚d S )Nzapplication/zipz.whl)rñ   zapplication/x-gzipz	text/htmlr   )Ú
Subversionzsvn+zZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of %s)r@   rE   rž   r€   r£   ÚZIP_EXTENSIONSré   Ú
is_zipfiler"   r  Ú
is_tarfileÚTAR_EXTENSIONSrý   rþ   r#   ri   r   r   Úpip.vcs.subversionr  ÚurlrÔ   rÿ   Úcriticalr   )r�   rÎ   Úcontent_typeÚlinkr  r=   r=   r>   r$   a  s,    


Úraisec             C   s,  |r
d }nt j}|d krng }xF| D ]>}	d|	ksFd|	ksFd|	ksFd|	krVd|	jddƒ }	|j|	ƒ q"W dj|ƒ}tjd|ƒ tjj	ƒ }
|r’|
j
|ƒ yt j| t jd |||
d�}W n2 tk
rà } ztjd	||ƒ ‚ W Y d d }~X nX |d k	�rNg }x\t|jjƒ ƒ}|�sP |jƒ }|j|d ƒ tjƒ tjk�r:tj|ƒ qò|d k	rò|jƒ  qòW |jƒ  |d k	�r~|j�rt|jd
ƒ n
|jdƒ |j�r|dk�rÞtjƒ tjk�rÈ| �rÈtjd|ƒ tjdj|ƒd ƒ td||j|f ƒ‚n:|dk�rütjd||j|ƒ n|dk�rntdt|ƒ ƒ‚|�s(dj|ƒS d S )Nú Ú
ú"ú'z"%s"z\"zRunning command %s)ÚstderrÚstdinÚstdoutÚcwdÚenvz#Error %s while executing command %sÚerrorÚdoner  z Complete output from command %s:ru   z)
----------------------------------------z,Command "%s" failed with error code %s in %sÚwarnz$Command "%s" had error code %s in %sÚignorezInvalid value: on_returncode=%s)Ú
subprocessÚPIPEr`   rÉ   r‚   rÿ   Údebugr@   rv   ÚcopyÚupdateÚPopenÚSTDOUTr~   r  r   r  ÚreadlineÚrstripÚgetEffectiveLevelÚstd_loggingÚDEBUGÚspinÚwaitÚ
returncodeÚfinishrõ   r   r   Ú
ValueErrorÚrepr)ÚcmdÚshow_stdoutr  Úon_returncodeÚcommand_descÚextra_environÚspinnerr  Ú	cmd_partsÚpartr  Úprocr
  Ú
all_outputÚliner=   r=   r>   r%   ‚  sz    
 










c             C   sx   t | dƒ�}|jƒ }W dQ R X dtjdƒdg}x4|D ],}y|j|ƒ}W n tk
r\   w4Y nX P q4W t|ƒtkstt‚|S )aR  Return the contents of *filename*.

    Try to decode the file contents with utf-8, the preferred system encoding
    (e.g., cp1252 on some Windows machines), and latin1, in that order.
    Decoding a byte string with latin1 will never raise an error. In the worst
    case, the returned string will contain some garbage characters.

    r�   Nzutf-8FÚlatin1)	rŽ   r�   ÚlocaleÚgetpreferredencodingre   ÚUnicodeDecodeErrorÚtyper…   ÚAssertionError)r�   r‘   r÷   Ú	encodingsÚencr=   r=   r>   Úread_text_fileä  s    	
rI  c             C   s   t j| ƒ t| ƒ d S )N)r@   rA   r   )Ú	build_dirr=   r=   r>   Ú_make_build_dirü  s    
rK  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>   ú	<genexpr>  s    z$FakeFile.__init__.<locals>.<genexpr>)Ú_gen)ÚselfÚlinesr=   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 )Nru   )ÚnextrO  Ú	NameErrorÚStopIteration)rP  r=   r=   r>   r+    s    
zFakeFile.readlinec             C   s   | j S )N)rO  )rP  r=   r=   r>   Ú__iter__  s    zFakeFile.__iter__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rR  r+  rV  r=   r=   r=   r>   rL    s   	rL  c               @   s$   e Zd Zedd„ ƒZedd„ ƒZdS )ÚStreamWrapperc             C   s   || _ | ƒ S )N)Úorig_stream)Úclsr\  r=   r=   r>   Úfrom_stream  s    zStreamWrapper.from_streamc             C   s   | j jS )N)r\  Úencoding)rP  r=   r=   r>   r_    s    zStreamWrapper.encodingN)rW  rX  rY  Úclassmethodr^  Úpropertyr_  r=   r=   r=   r>   r[    s   r[  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)ÚgetattrrK   Úsetattrr[  r^  )Ústream_nameÚorig_stdoutr=   r=   r>   Úcaptured_output!  s
    
rf  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.
    r  )rf  r=   r=   r=   r>   r&   0  s    	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 )NrZ  )rb  rZ  r]   )rP  r]   r=   r=   r>   rR  D  s    zcached_property.__init__c             C   s(   |d kr| S | j |ƒ }|j| j j< |S )N)r]   Ú__dict__rW  )rP  Úobjr]  Úvaluer=   r=   r>   Ú__get__H  s    zcached_property.__get__N)rW  rX  rY  rZ  rR  rk  r=   r=   r=   r>   rg  <  s   rg  c             C   s@   t jj| ƒ}|dkrt jƒ }n
t j|ƒ}|j|ƒ}|r<|jS dS )zCGet the installed version of dist_name avoiding pkg_resources cacheN)r   ÚRequirementÚparseÚ
WorkingSetr™   Úversion)Ú	dist_nameÚlookup_dirsÚreqrÃ   r±   r=   r=   r>   r*   P  s    


c             C   s   t | dd� dS )zConsume an iterable at C speed.r   )ÚmaxlenN)r   )Úiteratorr=   r=   r>   Úconsumed  s    ru  )r+   r,   )r-   r.   r/   r0   r1   )r2   r3   )r4   r5   r6   )F)rm   )T)T)TNr  NNN)N)dÚ
__future__r   Úcollectionsr   Ú
contextlibrC   ÚiorB  Úloggingr.  r‰   r@   r¢   rU   rX   r$  rK   r  ré   Úpip.exceptionsr   Ú
pip.compatr   r   r   r¬   r   r	   r
   r   r   Úpip._vendorr   Zpip._vendor.six.movesr   Zpip._vendor.sixr   Zpip._vendor.retryingr   r   r   Ú__all__Ú	getLoggerrW  rÿ   rý   rþ   r  r  r(   r)   Úbz2r8   r&  Úlzmar?   r'   r!   r   rV   r   r   r|   r   r   r   r   r   ÚDEFAULT_BUFFER_SIZEr•   r   r   r   r   r   r¯   r²   r´   rµ   r¹   rÈ   rÍ   r°   r    rä   r"   r#   r$   r%   rI  rK  ÚobjectrL  r[  Úcontextmanagerrf  r&   rg  r*   ru  r=   r=   r=   r>   Ú<module>   sÎ   
	



	
	 	
	5%
+L!   
_
