
9Vc           @@  sh  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 m Z d  d l 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 rS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# d$ d% d& d' g Z% e j& e'  Z( df Z) dg Z* dh Z+ e* e) e+ Z, y d  d l- Z- e* e) e+ Z. Wn( e/ k
 r4e( j0 d/  e* e+ Z. n Xd0   Z1 d1   Z2 d2   Z3 e! d3 d4 d5 d6  e4 d7   Z5 d8   Z6 d9   Z7 d: d;  Z8 d<   Z9 d=   Z: d> e; f d?     YZ< e<   Z= [< e j> d@ e j?  Z@ dA   ZA dB   ZB dC   ZC dD   ZD dE   ZE dF   ZF dG   ZG dH   ZH eI dI  ZJ dJ   ZK dK   ZL dL   ZM dM   ZN dN   ZO dO   ZP dP   ZQ eI e eI e4 e4 dQ  ZR dR   ZS dS   ZT dT   ZU dU   ZV eI dV  ZW dW   ZX dX   ZY dY   ZZ eI d eI e j\ d d dZ  Z] d[   Z^ d\   Z_ d] e; f d^     YZ` d_ e$ f d`     YZa e jb da    Zc db   Zd dc e; f dd     YZe de   Zf d S(i   i    (   t   absolute_importN(   t   InstallationError(   t   console_to_strt   stdlib_pkgs(   t   site_packagest	   user_sitet   running_under_virtualenvt   virtualenv_no_globalt   write_delete_marker_file(   t   pkg_resources(   t   input(   t   PY2(   t   retry(   t   BytesIO(   t   StringIOt   rmtreet   display_patht
   backup_dirt   askt   Inft   normalize_namet   splitextt   format_sizet   is_installable_dirt   is_svn_paget   file_contentst   split_leading_dirt   has_leading_dirt   make_path_relativet   normalize_patht   renamest   get_terminal_sizet   get_progt
   unzip_filet
   untar_filet   unpack_filet   call_subprocesst   captured_stdoutt   remove_tracebackst
   ensure_dirt   ARCHIVE_EXTENSIONSt   SUPPORTED_EXTENSIONSt   get_installed_versions   .tar.bz2s   .tbzs   .zips   .whls   .tar.gzs   .tgzs   .tars   bz2 module is not availablec         O@  s5   y t  |   SWn  t k
 r0 | | |    n Xd  S(   N(   t
   __import__t   ImportError(   t   pkg_or_module_stringt   ExceptionTypet   argst   kwargs(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   import_or_raise=   s    c         C@  sC   y t  j |   Wn+ t k
 r> } | j t j k r?   q? n Xd S(   s    os.path.makedirs without EEXIST.N(   t   ost   makedirst   OSErrort   errnot   EEXIST(   t   patht   e(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR'   D   s
    c           C@  sO   y. t  j j t j d  d k r- d t j SWn t t t f k
 rJ n Xd S(   Ni    s   __main__.pys   -cs	   %s -m pipt   pip(   s   __main__.pys   -c(	   R2   R7   t   basenamet   syst   argvt
   executablet   AttributeErrort	   TypeErrort
   IndexError(    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR    M   s    t   stop_max_delayi  t
   wait_fixedi  c         C@  s   t  j |  d | d t d  S(   Nt   ignore_errorst   onerror(   t   shutilR   t   rmtree_errorhandler(   t   dirRC   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR   W   s    c         C@  sA   t  j |  j t j @r: t  j | t j  |  |  d S  d S(   s   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(   R2   t   statt   st_modet   S_IREADt   chmodt   S_IWRITE(   t   funcR7   t   exc_info(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyRF   ]   s
    
c         C@  s   t  j j t  j j |    }  t j d d k rd |  j t j   d  }  |  j t j	   d  }  n  |  j
 t  j   t  j j  r d |  t t  j    }  n  |  S(   sT   Gives the display value for a given path, making it relative to cwd
    if possible.i    i   t   replacet   .(   R2   R7   t   normcaset   abspathR;   t   version_infot   decodet   getfilesystemencodingt   encodet   getdefaultencodingt
   startswitht   getcwdt   sept   len(   R7   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR   l   s    s   .bakc         C@  sK   d } | } x4 t  j j |  |  rB | d 7} | t |  } q W|  | S(   s\   Figure out the name of a directory to back up the given dir to
    (adding .bak, .bak2, etc)i   (   R2   R7   t   existst   str(   RG   t   extt   nt	   extension(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR   x   s    
c         C@  sC   x3 t  j j d d  j   D] } | | k r | Sq Wt |  |  S(   Nt   PIP_EXISTS_ACTIONt    (   R2   t   environt   gett   splitR   (   t   messaget   optionst   action(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   ask_path_exists   s    "c         C@  sx   xq t  j j d  r( t d |    n  t |   } | j   j   } | | k rm d | d j |  f GHq | Sq d S(   s@   Ask the message interactively, with the given possible responsest   PIP_NO_INPUTs7   No input was expected ($PIP_NO_INPUT set); question: %ss<   Your response (%r) was not one of the expected responses: %ss   , N(   R2   Rc   Rd   t	   ExceptionR
   t   stript   lowert   join(   Rf   Rg   t   response(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    t   _Infc           B@  sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   I am bigger than everything!c         C@  s   |  | k r t  St Sd  S(   N(   t   Truet   False(   t   selft   other(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __eq__   s    c         C@  s   |  j  |  S(   N(   Ru   (   Rs   Rt   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __ne__   s    c         C@  s   t  S(   N(   Rr   (   Rs   Rt   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __lt__   s    c         C@  s   t  S(   N(   Rr   (   Rs   Rt   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __le__   s    c         C@  s   t  S(   N(   Rq   (   Rs   Rt   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __gt__   s    c         C@  s   t  S(   N(   Rq   (   Rs   Rt   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __ge__   s    c         C@  s   d S(   NR   (    (   Rs   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __repr__   s    (
   t   __name__t
   __module__t   __doc__Ru   Rv   Rw   Rx   Ry   Rz   R{   (    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyRp      s   						s   [^a-z]c         C@  s   t  j d |  j    S(   Nt   -(   t   _normalize_ret   subRm   (   t   name(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      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  s   %.1fMBg     @@i
   s   %ikBs   %.1fkBs   %ibytesi@B i'  (    (   t   bytes(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    c         C@  sE   t  j j |   s t St  j j |  d  } t  j j |  rA t St S(   s@   Return True if `path` is a directory containing a setup.py file.s   setup.py(   R2   R7   t   isdirRr   Rn   t   isfileRq   (   R7   t   setup_py(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    c         C@  s(   t  j d |   o' t  j d |  t  j  S(   sT   
    Returns true if the page appears to be the index page of an svn repository
    s   <title>[^<]*Revision \d+:s#   Powered by (?:<a[^>]*?>)?Subversion(   t   ret   searcht   I(   t   html(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    c         C@  s/   t  |  d   } | j   j d  SWd  QXd  S(   Nt   rbs   utf-8(   t   opent   readRT   (   t   filenamet   fp(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    c         C@  s   t  |   }  |  j d  j d  }  d |  k rv d |  k rZ |  j d  |  j d  k  sf d |  k rv |  j d d  Sd |  k r |  j d d  S|  d f Sd  S(   Nt   /s   \i   Rb   (   R]   t   lstript   findRe   (   R7   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    6c         C@  s\   d } xO |  D]G } t |  \ } } | s/ t S| d k rD | } q | | k r t Sq Wt S(   sy   Returns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)N(   t   NoneR   Rr   Rq   (   t   pathst   common_prefixR7   t   prefixt   rest(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR      s    	c         C@  s7  t  j j |   } t  j j |   }  t  j j t  j j |    }  t  j j t  j j |   } |  j t  j j  j t  j j  } | j t  j j  j t  j j  } x> | r | r | d | d k r | j	 d  | j	 d  q Wd g t
 |  | | g } | d g k r$d t  j j St  j j j |  S(   s  
    Make a filename relative, where the filename path, and it is
    relative to rel_to

        >>> make_path_relative('/usr/share/something/a-file.pth',
        ...                    '/usr/share/another-place/src/Directory')
        '../../../something/a-file.pth'
        >>> make_path_relative('/usr/share/something/a-file.pth',
        ...                    '/home/user/src/Directory')
        '../../../usr/share/something/a-file.pth'
        >>> make_path_relative('/usr/share/a-file.pth', '/usr/share/')
        'a-file.pth'
    i    s   ..Rb   RP   (   R2   R7   R:   t   dirnamet   normpathRR   Rl   RZ   Re   t   popR[   Rn   (   R7   t   rel_tot   path_filenamet
   path_partst   rel_to_partst
   full_parts(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR     s    $$#c         C@  sO   t  j j |   }  | r- t  j j |   }  n t  j j |   }  t  j j |   S(   sN   
    Convert a path to its canonical, case-normalized, absolute version.

    (   R2   R7   t
   expandusert   realpathRR   RQ   (   R7   t   resolve_symlinks(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR     s
    c         C@  sO   t  j |   \ } } | j   j d  rE | d | } | d  } n  | | f S(   s,   Like os.path.splitext, but take off .tar toos   .tari(   t	   posixpathR   Rm   t   endswith(   R7   t   baseR^   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR   +  s
    c         C@  s   t  j j |  \ } } | rG | rG t  j j |  rG t  j |  n  t j |  |  t  j j |   \ } } | r | r y t  j |  Wq t k
 r q Xn  d S(   s7   Like os.renames(), but handles renaming across devices.N(	   R2   R7   Re   R\   R3   RE   t   movet
   removedirsR4   (   t   oldt   newt   headt   tail(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR   4  s    c         C@  s)   t    s t St |   j t t j   S(   s   
    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."

    (   R   Rq   R   RX   R;   R   (   R7   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   is_localE  s    	c         C@  s   t  t |    S(   s   
    Return True if given Distribution object is installed locally
    (i.e. within current virtualenv).

    Always True if we're not in a virtualenv.

    (   R   t   dist_location(   t   dist(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   dist_is_localQ  s    c         C@  s%   t  t |    } | j t  t   S(   sF   
    Return True if given Distribution is installed in user site.
    (   R   R   RX   R   (   R   t	   norm_path(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   dist_in_usersite\  s    c         C@  s   t  t |    j t  t   S(   se   
    Return True if given Distribution is installed in
    distutils.sysconfig.get_python_lib().
    (   R   R   RX   R   (   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   dist_in_site_packagesd  s    c         C@  s)   d d l  m } | j |  g   } | j S(   s$   Is distribution an editable install?i    (   t   FrozenRequirement(   R9   R   t	   from_distt   editable(   R   R   t   req(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   dist_is_editablen  s    c   
      C@  s   |  r t  } n	 d   } | r* d   } n	 d   } | rE d   } n	 d   } | r] t } n	 d   } g  t j D]K }	 | |	  rp |	 j | k rp | |	  rp | |	  rp | |	  rp |	 ^ qp S(   s  
    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   t  S(   N(   Rq   (   t   d(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt
   local_test  s    c         S@  s   t  S(   N(   Rq   (   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   editable_test  s    c         S@  s   t  |   S(   N(   R   (   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR     s    c         S@  s
   t  |   S(   N(   R   (   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   editables_only_test  s    c         S@  s   t  S(   N(   Rq   (   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR     s    c         S@  s   t  S(   N(   Rq   (   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt	   user_test  s    (   R   R   R	   t   working_sett   key(
   t
   local_onlyt   skipt   include_editablest   editables_onlyt	   user_onlyR   R   R   R   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   get_installed_distributionsv  s$    						c         C@  s   g  } t    rN t   r( | j t  qq | j t  t rq | j t  qq n# t rd | j t  n  | j t  x@ | D]8 } t j j | |  j  d } t j j	 |  rx | Sqx Wd S(   s  
    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.
    s	   .egg-linkN(
   R   R   t   appendR   R   R2   R7   Rn   t   project_nameR   (   R   t   sitest   sitet   egglink(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   egg_link_path  s    		c         C@  s   t  |   } | r | S|  j S(   s   
    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   t   location(   R   t   egg_link(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR     s    c          C@  s   d   }  |  d  p* |  d  p* |  d  } | sx y8 t  j t  j   t  j  } |  |  } t  j |  Wqx qx Xn  | s t  j j d d  t  j j d d  f } n  t | d  t | d  f S(	   sl   Returns a tuple (x, y) representing the width(x) and the height(x)
    in characters of the terminal window.c         S@  sk   yL d d  l  } d d  l } d d  l } | j d | j |  | j d   } Wn d  SX| d k rg d  S| S(   Ni    t   hht   1234(   i    i    (   t   fcntlt   termiost   structt   unpackt   ioctlt
   TIOCGWINSZR   (   t   fdR   R   R   t   cr(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   ioctl_GWINSZ  s    i    i   i   t   LINESi   t   COLUMNSiP   (   R2   R   t   ctermidt   O_RDONLYt   closeRc   Rd   t   int(   R   R   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR     s    	$-c          C@  s    t  j d  }  t  j |   |  S(   sB   Get the current umask which involves having to set it temporarily.i    (   R2   t   umask(   t   mask(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   current_umask   s    c         C@  s~  t  |  t |  d  } zSt j | d t } t | j    oF | } x| j   D]} | j } | j	 |  } | }	 | r t
 |  d }	 n  t j j | |	  }	 t j j |	  }
 |	 j d  s |	 j d  r t  |	  qV t  |
  t |	 d  } z | j |  Wd | j   | j d ?} | rft j |  rf| d	 @rft j |	 d
 t   d	 B n  XqV WWd | j   Xd S(   s  
    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
   allowZip64i   R   s   \t   wbNi   iI   i  (   R'   R   t   zipfilet   ZipFileRq   R   t   namelistt   infolistR   R   R   R2   R7   Rn   R   R   t   writeR   t   external_attrRH   t   S_ISREGRK   R   (   R   R   t   flattent   zipfpt   zipt   leadingt   infoR   t   datat   fnRG   R   t   mode(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR!     s0    	
	

'c         C@  s  t  |  |  j   j d  s4 |  j   j d  r= d } nR |  j   j t  r[ d } n4 |  j   j d  ry d } n t j d |   d } t j |  |  } zt g  | j	   D] } | j
 d	 k r | j
 ^ q  } x| j	   D]} | j
 } | d	 k r	q n  | r"t |  d
 } n  t j j | |  } | j   rPt  |  q | j   ry | j | |  Wqlt k
 r} t j d |  | j
 |  q qlXq y | j |  }	 Wn5 t t f k
 r} t j d |  | j
 |  q n Xt  t j j |   t | d  }
 z t j |	 |
  Wd |
 j   X|	 j   | j d @r t j | d t   d B q q WWd | j   Xd S(   s  
    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.
    s   .gzs   .tgzs   r:gzs   r:bz2s   .tart   rs-   Cannot determine compression type for file %ss   r:*t   pax_global_headeri   s/   In the tar file %s the member %s is invalid: %sR   NiI   i  (   R'   Rm   R   t   BZ2_EXTENSIONSt   loggert   warningt   tarfileR   R   t
   getmembersR   R   R2   R7   Rn   R   t   issymt   _extract_memberRk   t   extractfilet   KeyErrorR>   R   RE   t   copyfileobjR   R   RK   R   (   R   R   R   t   tart   memberR   R   R7   t   excR   t   destfp(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR"   2  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  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(   Ns   application/zipR   s   .whls   application/x-gzips	   text/htmli    (   t
   Subversions   svn+sZ   Cannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formats%   Cannot determine archive format of %s(   R2   R7   R   Rm   R   t   ZIP_EXTENSIONSR   t
   is_zipfileR!   R   t
   is_tarfilet   TAR_EXTENSIONSR   R"   RX   R   R   t   pip.vcs.subversionR  t   urlR   R   t   criticalR   (   R   R   t   content_typet   linkR  (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR#   }  s*    c         C@  s8   d } t  j | d |   }  t r% |  St  j d d |   S(   NsR   (?:\W+File "(?:.*)", line (?:.*)\W+(?:.*)\W+\^\W+)?Syntax(?:Error|Warning): (?:.*)Rb   s   \*\*\* Error compiling (?:.*)(   R   R   R   (   t   outputt   pattern(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR&     s
    c         C@  sz  | d  k r g  } xd |  D]\ } d | k sO d | k sO d | k sO d | k rh d | j d d  } n  | j |  q Wd j |  } n  | r d  }	 n	 t j }	 t j | d |  t j	 j
   }
 | r |
 j |  n  y4 t j |  d t j d	 d  d
 |	 d | d |
 } Wn) t k
 r:} t j d | |    n Xg  } |	 d  k	 rxV t rt | j j    } | suPn  | j   } | j | d  t j |  qPWn  | s| j   \ } } | pd g } n  | j   | j rW| r;| rt j d |  t j d j |  d  n  t d | | j | f   qWt j d | | j |  n  |	 d  k	 rvt d j |   Sd  S(   Nt    s   
t   "t   's   "%s"s   \"s   Running command %st   stderrt   stdint   stdoutt   cwdt   envs#   Error %s while executing command %sRb   s    Complete output from command %s:s)   
----------------------------------------s,   Command "%s" failed with error code %s in %ss$   Command "%s" had error code %s in %s(   R   RO   R   Rn   t
   subprocesst   PIPER   t   logR2   Rc   t   copyt   updatet   Popent   STDOUTRk   R	  Rq   R   R  t   readlinet   rstript   debugt   communicatet   waitt
   returncodeR   R   R   R&   (   t   cmdt   show_stdoutR  t   raise_on_returncodet   command_levelt   command_desct   extra_environt	   cmd_partst   partR  R  t   procR   t
   all_outputt   linet   returned_stdoutt   returned_stderr(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR$     sf    0			
	
c         C@  s   t  |  d   } | j   } Wd QXd t j t  d g } x9 | D]1 } y | j |  } Wn t k
 rr qC n XPqC Wt |  t k s t	  | S(   sR  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   Ns   utf-8t   latin1(
   R   R   t   localet   getpreferredencodingRr   RT   t   UnicodeDecodeErrort   typeR   t   AssertionError(   R   R   R   t	   encodingst   enc(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   read_text_file  s    	c         C@  s   t  j |   t |   d  S(   N(   R2   R3   R   (   t	   build_dir(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   _make_build_dir  s    t   FakeFilec           B@  s)   e  Z d  Z d   Z d   Z d   Z RS(   sQ   Wrap a list of lines in an object with readline() to make
    ConfigParser happy.c         C@  s   d   | D |  _  d  S(   Nc         s@  s   |  ] } | Vq d  S(   N(    (   t   .0t   l(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pys	   <genexpr>  s    (   t   _gen(   Rs   t   lines(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __init__  s    c         C@  sL   y3 y t  |  j  SWn t k
 r1 |  j j    SXWn t k
 rG d SXd  S(   NRb   (   t   nextR>  t	   NameErrort   StopIteration(   Rs   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR  
  s    c         C@  s   |  j  S(   N(   R>  (   Rs   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __iter__  s    (   R|   R}   R~   R@  R  RD  (    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR;    s   			t   StreamWrapperc           B@  s&   e  Z e d     Z e d    Z RS(   c         C@  s   | |  _  |    S(   N(   t   orig_stream(   t   clsRF  (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   from_stream  s    	c         C@  s
   |  j  j S(   N(   RF  t   encoding(   Rs   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyRI    s    (   R|   R}   t   classmethodRH  t   propertyRI  (    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyRE    s   c         c@  sR   t  t |   } t t |  t j |   z t  t |   VWd t t |  |  Xd S(   s   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(   t   getattrR;   t   setattrRE  RH  (   t   stream_namet   orig_stdout(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   captured_output$  s
    c           C@  s
   t  d  S(   s   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  (   RP  (    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR%   3  s    	t   cached_propertyc           B@  s    e  Z d  Z d   Z d   Z RS(   s   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(   NR~   (   RL  R~   RM   (   Rs   RM   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR@  G  s    c         C@  s4   | d  k r |  S|  j |  } | j |  j j <| S(   N(   R   RM   t   __dict__R|   (   Rs   t   objRG  t   value(    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   __get__K  s     (   R|   R}   R~   R@  RU  (    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyRQ  ?  s   	c         C@  s>   t  j j |   } t  j   } | j |  } | r: | j Sd S(   sC   Get the installed version of dist_name avoiding pkg_resources cacheN(   R	   t   Requirementt   parset
   WorkingSetR   t   versionR   (   t	   dist_nameR   R   R   (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyR*   S  s    (   s   .tar.bz2s   .tbz(   s   .zips   .whl(   s   .tar.gzs   .tgzs   .tar(g   t
   __future__R    t
   contextlibR5   R1  t   loggingR   R2   R   RE   RH   R  R;   R   R   t   pip.exceptionsR   t
   pip.compatR   R   t   pip.locationsR   R   R   R   R   t   pip._vendorR	   t   pip._vendor.six.movesR
   t   pip._vendor.sixR   t   pip._vendor.retryingR   t   ioR   R   t   __all__t	   getLoggerR|   R   R   R  R  R(   t   bz2R)   R,   R  R1   R'   R    Rr   R   RF   R   R   Ri   R   t   objectRp   R   t   compileR   R   R   R   R   R   R   R   R   R   Rq   R   R   R   R   R   R   R   R   R   R   R   R   R   R!   R"   R#   R&   R   t   DEBUGR$   R8  R:  R;  RE  t   contextmanagerRP  R%   RQ  R*   (    (    (    s/   /tmp/pip-build-5Z5nTX/pip/pip/utils/__init__.pyt   <module>   s   (								
								
												
	5	%			+	K	 		<			