
§|j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$ ru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, dy Z- dz Z. d{ Z/ d| Z0 e/ e- e0 e. Z1 e/ e0 Z2 y d  d l3 Z3 e2 e- 7Z2 Wn e4 k
 rQe, j5 d1 ƒ Yn Xy d  d l6 Z6 e2 e. 7Z2 Wn e4 k
 r�e, j5 d2 ƒ Yn Xd3 d4 „  Z7 d5 d! „  Z8 d6 d „  Z9 e& d7 d8 d9 d: ƒ d; d< d „ ƒ Z: d= d> „  Z; d? d „  Z< d@ dA d „ Z= dB dC „  Z> dD d „  Z? dE d „  Z@ dF d „  ZA dG d „  ZB dH d „  ZC e jD dI dJ „ ZE dK d „  ZF dL d „  ZG dM dN d „ ZH dO d „  ZI dP d „  ZJ dQ dR „  ZK dS dT „  ZL dU dV „  ZM dW dX „  ZN dY dZ „  ZO dM e dM d; d; d[ d\ „ ZP d] d^ „  ZQ d_ d` „  ZR da d „  ZS db dc „  ZT dM dd d „ ZU de d „  ZV df d „  ZW dM d dg d d d dh d „ ZX di dj „  ZY dk dl „  ZZ Gdm dn „  dn e[ ƒ Z\ Gdo dp „  dp e( ƒ Z] e j^ dq dr „  ƒ Z_ ds d  „  Z` Gdt du „  du e[ ƒ Za d dv d$ „ Zb dw dx „  Zc d 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   s6   y t  |  ƒ SWn! t k
 r1 | | | Ž  ‚ Yn Xd  S)N)Ú
__import__ÚImportError)Úpkg_or_module_stringÚExceptionTypeÚargsÚkwargs© r=   ú1/tmp/pip-build-5c7ija6t/pip/pip/utils/__init__.pyÚimport_or_raiseI   s    r?   c             C   sR   y t  j |  ƒ Wn: t k
 rM } z | j t j k r; ‚  WYd d } ~ Xn Xd S)z os.path.makedirs without EEXIST.N)ÚosÚmakedirsÚOSErrorÚerrnoÚEEXIST)ÚpathÚer=   r=   r>   r'   P   s
    c               C   sP   y. t  j j t j d ƒ d k r- d t j SWn t t t f k
 rK Yn Xd 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    Ústop_max_delayi¸  Ú
wait_fixediô  Fc             C   s   t  j |  d | d t ƒd  S)NÚignore_errorsÚonerror)Úshutilr   Úrmtree_errorhandler)ÚdirrS   r=   r=   r>   r   c   s    c             C   sA   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   s¤   t  j j t  j j |  ƒ ƒ }  t j d d k ra |  j t j ƒ  d ƒ }  |  j t j	 ƒ  d ƒ }  |  j
 t  j ƒ  t  j j ƒ r  d |  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     z.bakc             C   sK   d } | } x4 t  j j |  | ƒ rB | 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   sC   x3 t  j j d d ƒ j ƒ  D] } | | k r | Sq Wt |  | ƒ S)NÚPIP_EXISTS_ACTIONÚ )r@   ÚenvironÚgetÚsplitr   )ÚmessageÚoptionsÚactionr=   r=   r>   Úask_path_exists�   s    "r{   c             C   s{   xt t  j j d ƒ r% t d |  ƒ ‚ t |  ƒ } | j ƒ  j ƒ  } | | k ro t d | d j | ƒ f ƒ q | Sq Wd 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@   ru   rv   Ú	Exceptionr   ÚstripÚlowerÚprintÚjoin)rx   ry   Úresponser=   r=   r>   r   –   s    
c             C   sX   |  d k r d |  d d S|  d	 k r4 d |  d S|  d k rL d |  d Sd |  Sd  S)
Niè  z%.1fMBg     @�@é
   z%ikBz%.1fkBz%ibytesi@B i'  r=   )Úbytesr=   r=   r>   r   ©   s    c             C   sE   t  j j |  ƒ s d St  j j |  d ƒ } t  j j | ƒ rA d Sd 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   s0   t  |  d ƒ � } | j ƒ  j d ƒ SWd  QRXd  S)NÚrbzutf-8)ÚopenÚreadre   )ÚfilenameÚfpr=   r=   r>   r   Æ   s    c             c   s&   x |  j  | ƒ } | s P| Vq Wd 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   s”   |  j  d ƒ j  d ƒ }  d |  k rj d |  k rN |  j d ƒ |  j d ƒ k  sZ d |  k rj |  j d d ƒ Sd |  k r† |  j d d ƒ S|  d f Sd  S)Nú/ú\rm   rt   )ÚlstripÚfindrw   )rE   r=   r=   r>   r   Ô   s    6c             C   s\   d } xO |  D]G } t  | ƒ \ } } | s/ d S| d k rD | } q | | k r d Sq Wd 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   sI   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   sX   t  j |  ƒ \ } } | j ƒ  j d ƒ rN | d d … | } | d d … } | | f S)z,Like os.path.splitext, but take off .tar tooz.taré   Néüÿÿÿr    )Ú	posixpathr   r   Úendswith)rE   Úbaserp   r=   r=   r>   r   û   s
    c             C   s¢   t  j j | ƒ \ } } | rD | rD t  j j | ƒ rD t  j | ƒ t j |  | ƒ t  j j |  ƒ \ } } | rž | rž y t  j | ƒ Wn t k
 r� Yn Xd S)z7Like os.renames(), but handles renaming across devices.N)	r@   rE   rw   rn   rA   rU   ÚmoveÚ
removedirsrB   )ÚoldÚnewÚheadÚtailr=   r=   r>   r     s    c             C   s›   t  |  ƒ }  t  t j ƒ } t ƒ  r: |  j t  t j ƒ ƒ Sd d l m } |  j | ƒ r“ x3 | d ƒ j ƒ  D] } |  j t  | ƒ ƒ rl d Sql Wd Sd Sd 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_schemert   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   sJ   xC t  j D]8 } t j j | |  j d ƒ } t j j | ƒ r
 d Sq
 Wd 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                sž   |  r t  ‰ n d d „  ‰ | r0 d d „  ‰  n d d „  ‰  | rQ d d „  ‰ n d d „  ‰ | rl t ‰ 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                sU   g  |  ]K } ˆ | ƒ r | j  ˆ k r ˆ  | ƒ r ˆ | ƒ r ˆ | ƒ r | ‘ q Sr=   )Ú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  ƒ  rK t ƒ  r( | j t ƒ qk | j t ƒ t rk | j t ƒ n  t r^ | j t ƒ | j t ƒ x@ | D]8 } t j j | |  j ƒ d } t j j	 | ƒ rr | Sqr Wd 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 ƒ } | sy y8 t  j t  j ƒ  t  j ƒ } |  | ƒ } t  j | ƒ Wn Yn X| s© t  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   so   yL d d  l  } d d  l } d d  l } | j d | j |  | j d ƒ ƒ } Wn d  SYn X| d k rk d  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   rm   r_   ÚLINESé   ÚCOLUMNSéP   )r@   r�   ÚctermidÚO_RDONLYÚcloseru   rv   Ú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   sx  t  | ƒ t |  d ƒ } zMt j | d d ƒ} t | j ƒ  ƒ oF | } x| j ƒ  D]} | j } | j | ƒ } | }	 | r� t	 | ƒ d }	 t
 j j | |	 ƒ }	 t
 j j |	 ƒ }
 |	 j d ƒ sÕ |	 j d ƒ râ t  |	 ƒ qV t  |
 ƒ t |	 d ƒ } z | j | ƒ Wd | j ƒ  | j d	 ?} | r`t j | ƒ r`| d
 @r`t
 j |	 d t ƒ  d
 Bƒ XqV WWd | j ƒ  Xd 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Œ   Ú
allowZip64Trm   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 ƒ s4 |  j ƒ  j d ƒ r= d } np |  j ƒ  j t ƒ r[ d } nR |  j ƒ  j t ƒ ry d } n4 |  j ƒ  j d ƒ r— d } n t j d |  ƒ d	 } t j |  | ƒ } zÛt	 d
 d „  | j
 ƒ  Dƒ ƒ } xµ| j
 ƒ  D]§} | j } | d k rqî | r"t | ƒ d } t j j | | ƒ } | j ƒ  rPt  | ƒ qî | j ƒ  r·y | j | | ƒ Wq•t k
 r³} z! t j d |  | j | ƒ wî WYd d } ~ Xq•Xqî y | j | ƒ }	 WnG t t f k
 r} z! t j d |  | j | ƒ wî WYd d } ~ Xn Xt  t j j | ƒ ƒ t | d ƒ � }
 t j |	 |
 ƒ Wd QRX|	 j ƒ  | j | | ƒ | j d @rî t j | d t ƒ  d Bƒ qî WWd | j ƒ  Xd 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ú   rm   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 sB |  j ƒ  j t ƒ sB t j |  ƒ rb t |  | d |  j d ƒ ƒnÂ | d k sš t	 j
 |  ƒ sš |  j ƒ  j t t t ƒ rª t |  | ƒ nz | rþ | j d ƒ rþ t t |  ƒ ƒ rþ d d l m } | d | j ƒ j | ƒ n& t j d	 |  | | ƒ t d
 | ƒ ‚ d  S)Nzapplication/ziprð   z.whlz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 r� g  } xa |  D]Y }	 d |	 k sg d |	 k sg d |	 k sg d |	 k r} d |	 j d d ƒ }	 | j |	 ƒ q1 Wd j | ƒ } t j d | ƒ t j j	 ƒ  }
 | rÏ |
 j
 | ƒ y4 t  j |  d t  j d	 d  d
 | d | d |
 ƒ} Wn; t k
 r@} z t j d | | ƒ ‚  WYd  d  } ~ Xn X| d  k	 rÎg  } xx t | j j ƒ  ƒ } | srP| j ƒ  } | j | d ƒ t j ƒ  t j k r´t j | ƒ qV| d  k	 rV| j ƒ  qVW| j ƒ  | d  k	 r
| j rý| j d ƒ n | j d ƒ | j rÑ| d k r„t j ƒ  t j k re| ret j d | ƒ t j d j | ƒ d ƒ t d | | j | f ƒ ‚ nM | d k r¬t j d | | j | ƒ n% | d k r»n t d t | ƒ ƒ ‚ | säd j | ƒ Sd  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:rt   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@   ru   Ú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    		0
		
c             C   s–   t  |  d ƒ � } | j ƒ  } Wd QRXd t j d ƒ d g } x: | D]2 } y | j | ƒ } Wn t k
 rt wD Yn XPqD Wt | ƒ t k s’ t ‚ | 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    	rH  c             C   s   t  j |  ƒ t |  ƒ d  S)N)r@   rA   r   )Ú	build_dirr=   r=   r>   Ú_make_build_dirü  s    rJ  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   sT   y7 y t  |  j ƒ SWn t k
 r5 |  j j  ƒ  SYn XWn t k
 rO d SYn Xd  S)Nrt   )ÚnextrN  Ú	NameErrorÚStopIteration)rO  r=   r=   r>   r*    s    zFakeFile.readlinec             C   s   |  j  S)N)rN  )rO  r=   r=   r>   Ú__iter__  s    zFakeFile.__iter__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rQ  r*  rU  r=   r=   r=   r>   rK    s   	rK  c               @   s4   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)rO  r=   r=   r>   r^    s    zStreamWrapper.encodingN)rV  rW  rX  Úclassmethodr]  Úpropertyr^  r=   r=   r=   r>   rZ    s   rZ  c             c   sR   t  t |  ƒ } t t |  t j | ƒ ƒ z t  t |  ƒ VWd t t |  | ƒ Xd 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   ÚsetattrrZ  r]  )Ústream_nameÚorig_stdoutr=   r=   r>   Úcaptured_output!  s
    re  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  )re  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)NrY  )ra  rY  r]   )rO  r]   r=   r=   r>   rQ  D  s    zcached_property.__init__c             C   s4   | d  k r |  S|  j  | ƒ } | j |  j  j <| S)N)r]   Ú__dict__rV  )rO  Úobjr\  Úvaluer=   r=   r>   Ú__get__H  s     zcached_property.__get__N)rV  rW  rX  rY  rQ  rj  r=   r=   r=   r>   rf  <  s   rf  c             C   s\   t  j j |  ƒ } | d k r- t  j ƒ  } n t  j | ƒ } | j | ƒ } | rX | j Sd 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.Úmaxlenr   N)r   )Úiteratorr=   r=   r>   Úconsumed  s    rt  )r+   r,   )r-   r.   r/   r0   r1   )r2   r3   )r4   r5   r6   )dÚ
__future__r   Úcollectionsr   Ú
contextlibrC   ÚiorA  Ú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__Ú	getLoggerrV  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%   rH  rJ  ÚobjectrK  rZ  Úcontextmanagerre  r&   rf  r*   rt  r=   r=   r=   r>   Ú<module>   sÎ   (			
	

		 	
	5%+L!_