
b]c           @@  st  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/ m0 Z0 m1 Z1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 d  d l7 m8 Z8 m9 Z9 e rd  d l m: Z; n d  d l m; Z; e6 rd  d l< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH d  d lI mJ ZJ d  d lK mL ZL d  d lM mN ZN eF eO eO eO f ZP n	 d   ZH d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 g ZQ e jR eS  ZT e jR d2  ZU d3 ZV d4 ZW d ZX d ZY d< eW f ZZ d Z[ eZ eX e[ eY Z\ eZ e[ Z] y d  d l^ Z^ e] eX 7Z] Wn e_ k
 reT j` d@  n Xy d  d la Za e] eY 7Z] Wn e_ k
 reT j` dA  n XdB   Zb dC   Zc dD   Zd dE   Ze e dF dG dH dI  ef dJ   Zg dK   Zh dL   Zi dM   Zj dN dO  Zk dP   Zl dQ   Zm dR   Zn dS   Zo dT   Zp dU   Zq dV   Zr dW   Zs dX   Zt e ju dY  Zv dZ   Zw d[   Zx ey d\  Zz d]   Z{ d^   Z| d_   Z} d`   Z~ da   Z db   Z dc   Z ey e1 ey ef ef d dd  Z de   Z df   Z dg   Z ey dh  Z di   Z dj   Z dk   Z dl   Z ef d dm d d d d d dn  Z do   Z dp e f dq     YZ dr e; f ds     YZ e j dt    Z du   Z dv   Z dw e f dx     YZ d dy  Z dz   Z d{   Z d|   Z d}   Z d~   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   i    (   t   absolute_importN(   t   deque(   t   pkg_resources(   t   retry(   t   PY2t	   text_type(   t   inputt   shlex_quote(   t   parse(   t   request(   t   unquote(   t   __version__(   t   CommandErrort   InstallationError(   t   site_packagest	   user_site(   t   WINDOWSt   console_to_strt
   expandusert   stdlib_pkgst   str_to_display(   t   write_delete_marker_file(   t   MYPY_CHECK_RUNNING(   t   running_under_virtualenvt   virtualenv_no_global(   t   BytesIO(   t   StringIO(   t   Anyt   AnyStrt	   Containert   Iterablet   Listt   Mappingt   Matcht   Optionalt   Textt   Tuplet   Uniont   cast(   t   Distribution(   t   Link(   t   SpinnerInterfacec         C@  s   | S(   N(    (   t   type_t   value(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR&   =   s    t   rmtreet   display_patht
   backup_dirt   askt   splitextt   format_sizet   is_installable_dirt   is_svn_paget   file_contentst   split_leading_dirt   has_leading_dirt   normalize_patht   renamest   get_progt
   unzip_filet
   untar_filet   unpack_filet   call_subprocesst   captured_stdoutt
   ensure_dirt   ARCHIVE_EXTENSIONSt   SUPPORTED_EXTENSIONSt   WHEEL_EXTENSIONt   get_installed_versiont   remove_auth_from_urls   pip.subprocessors(   ----------------------------------------s   .whls   .tar.bz2s   .tbzs   .tar.xzs   .txzs   .tlzs   .tar.lzs	   .tar.lzmas   .zips   .tar.gzs   .tgzs   .tars   bz2 module is not availables   lzma module is not availablec          C@  sP   t  j j t  j j t  d d  }  t  j j |   }  d j t |  t j	 d   S(   Ns   ..s   pip {} from {} (python {})i   (
   t   ost   patht   joint   dirnamet   __file__t   abspatht   formatR   t   syst   version(   t   pip_pkg_dir(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   get_pip_versionj   s    $c         C@  sY   t  |   d k  r- |  d t  |   d 7}  n t  |   d k rL |  d  }  n  t d |   S(   sx  
    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).
    i   i    t   VersionInfo(   i    (   t   lenR&   (   t   py_version_info(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   normalize_version_infov   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(   RE   t   makedirst   OSErrort   errnot   EEXIST(   RF   t   e(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR?      s
    c          C@  sY   y8 t  j j t j d  }  |  d k r3 d t j S|  SWn t t t f k
 rT n Xd S(   Ni    s   __main__.pys   -cs	   %s -m pipt   pip(   s   __main__.pys   -c(	   RE   RF   t   basenameRL   t   argvt
   executablet   AttributeErrort	   TypeErrort
   IndexError(   t   prog(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR9      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   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR,      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(   RE   t   statt   st_modet   S_IREADt   chmodt   S_IWRITE(   t   funcRF   t   exc_info(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyRf      s
    
c         C@  s   |  d k r d St |  t  r# |  Sy |  j t j   d  } Wn; t k
 r| t rm t d j	 |    } q} t
 |   } n X| S(   s   
    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.
    t   stricts   b{!r}N(   t   Nonet
   isinstanceR   t   decodeRL   t   getfilesystemencodingt   UnicodeDecodeErrorR   R   RK   t   ascii(   RF   R-   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   path_to_display   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   .(   RE   RF   t   normcaseRJ   RL   t   version_infoRr   Rs   t   encodet   getdefaultencodingt
   startswitht   getcwdt   sepRQ   (   RF   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR-      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   (   RE   RF   t   existst   str(   Rg   t   extt   nt	   extension(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR.      s    
c         C@  sC   x3 t  j j d d  j   D] } | | k r | Sq Wt |  |  S(   Nt   PIP_EXISTS_ACTIONt    (   RE   t   environt   gett   splitR/   (   t   messaget   optionst   action(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   ask_path_exists   s    "c         C@  s)   t  j j d  r% t d |    n  d S(   s&   Raise an error if no input is allowed.t   PIP_NO_INPUTs7   No input was expected ($PIP_NO_INPUT set); question: %sN(   RE   R   R   t	   Exception(   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   _check_no_input   s    c         C@  s^   xW t  |   t |   } | j   j   } | | k rR d | d j |  f GHq | Sq Wd S(   s@   Ask the message interactively, with the given possible responsess<   Your response (%r) was not one of the expected responses: %ss   , N(   R   R   t   stript   lowerRG   (   R   R   t   response(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR/     s    
c         C@  s   t  |   t |   S(   s   Ask for input interactively.(   R   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt	   ask_input  s    
c         C@  s   t  |   t j |   S(   s!   Ask for a password interactively.(   R   t   getpass(   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   ask_password  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(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR1   #  s    c         C@  sp   t  j j |   s t St  j j |  d  } t  j j |  rA t St  j j |  d  } t  j j |  rl t St S(   sB   Is path is a directory containing setup.py or pyproject.toml?
    s   setup.pys   pyproject.toml(   RE   RF   t   isdirt   FalseRG   t   isfilet   True(   RF   t   setup_pyt   pyproject_toml(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR2   /  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(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR3   >  s    c         C@  s/   t  |  d   } | j   j d  SWd  QXd  S(   Nt   rbs   utf-8(   t   opent   readRr   (   t   filenamet   fp(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR4   G  s    c         c@  s/   x( t  r* |  j |  } | s" Pn  | Vq Wd S(   s7   Yield pieces of data from a file-like object until EOF.N(   R   R   (   t   filet   sizet   chunk(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   read_chunksM  s
    	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 g Sd  S(   Nt   /s   \i   R   (   t   lstript   findR   (   RF   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR5   V  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(   Rp   R5   R   R   (   t   pathst   common_prefixRF   t   prefixt   rest(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR6   b  s    	c         C@  sI   t  |   }  | r' t j j |   }  n t j j |   }  t j j |   S(   sN   
    Convert a path to its canonical, case-normalized, absolute version.

    (   R   RE   RF   t   realpathRJ   Ry   (   RF   t   resolve_symlinks(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR7   r  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	   posixpathR0   R   t   endswith(   RF   t   baseR   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR0     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(	   RE   RF   R   R   RT   Re   t   movet
   removedirsRU   (   t   oldt   newt   headt   tail(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR8     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   R   R7   R}   RL   R   (   RF   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   is_local  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(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   dist_is_local  s    	c         C@  s%   t  t |    } | j t  t   S(   sF   
    Return True if given Distribution is installed in user site.
    (   R7   R   R}   R   (   R   t	   norm_path(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   dist_in_usersite  s    c         C@  s   t  t |    j t  t   S(   s[   
    Return True if given Distribution is installed in
    sysconfig.get_python_lib().
    (   R7   R   R}   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   dist_in_site_packages  s    c         C@  sJ   xC t  j D]8 } t j j | |  j d  } t j j |  r
 t Sq
 Wt S(   sC   
    Return True if given Distribution is an editable install.
    s	   .egg-link(   RL   RF   RE   RG   t   project_nameR   R   R   (   R   t	   path_itemt   egg_link(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   dist_is_editable  s
    c         C@  s   | r t  j |  } n	 t  j } |  r0 t } n	 d   } | rK d   } n	 d   } | rf d   }	 n	 d   }	 | r~ t }
 n	 d   }
 g  | D]K } | |  r | j | k r | |  r |	 |  r |
 |  r | ^ q 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 ``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   t  S(   N(   R   (   t   d(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt
   local_test  s    c         S@  s   t  S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   editable_test  s    c         S@  s   t  |   S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR      s    c         S@  s
   t  |   S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   editables_only_test  s    c         S@  s   t  S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR     s    c         S@  s   t  S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt	   user_test  s    (   R   t
   WorkingSett   working_setR   R   t   key(   t
   local_onlyt   skipt   include_editablest   editables_onlyt	   user_onlyR   R   R   R   R   R   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   get_installed_distributions  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   RE   RF   RG   R   R   Rp   (   R   t   sitest   sitet   egglink(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.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   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR   A  s    	c          C@  s    t  j d  }  t  j |   |  S(   sB   Get the current umask which involves having to set it temporarily.i    (   RE   t   umask(   t   mask(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   current_umaskP  s    c         C@  s  t  |  t |  d  } z_t j | d t } t | j    oF | } x+| j   D]} | j } | } | r t	 |  d } n  t
 j j | |  } t
 j j |  }	 | j d  s | j d  r t  |  qV t  |	  | j |  }
 z, t | d   } t j |
 |  Wd QXWd |
 j   | j d ?} | rrt j |  rr| d	 @rr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   ZipFileR   R6   t   namelistt   infolistR   R5   RE   RF   RG   RH   R   Re   t   copyfileobjt   closet   external_attrRh   t   S_ISREGRk   R   (   R   R   t   flattent   zipfpt   zipt   leadingt   infot   namet   fnRg   R   t   destfpt   mode(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR:   W  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	 g  | j
   D] } | j ^ q  } x| j
   D]y} | j } | rt |  d
 } n  t j j | |  } | j   rMt  |  q | j   ry | j | |  Wqpt k
 r} t j d |  | j |  q qpXq y | j |  }	 Wn5 t t f k
 r} t j d |  | j |  q n Xt  t j j |   t | d   }
 t j |	 |
  Wd QX|	 j   | 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   r:xzs   .tart   rs-   Cannot determine compression type for file %ss   r:*i   s/   In the tar file %s the member %s is invalid: %sR   NiI   i  (   R?   R   R   t   BZ2_EXTENSIONSt   XZ_EXTENSIONSt   loggert   warningt   tarfileR   R6   t
   getmembersR   R5   RE   RF   RG   R   t   issymt   _extract_memberR   t   extractfilet   KeyErrorR]   RH   Re   R   R   t   utimeR   Rk   R   (   R   R   R   t   tart   memberR   R   RF   t   excR   R   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR;     s\    

*				
%	

&c         C@  s1  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 |  |  n | r| j d  rt t |    rd d l m } d | j } |   j | d	 | n& t j d
 |  | |  t d |   d  S(   Ns   application/zipR   s   .whls   application/x-gzips	   text/htmli    (   t
   Subversions   svn+t   urlsZ   Cannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formats%   Cannot determine archive format of %s(   RE   RF   R   R   R   t   ZIP_EXTENSIONSR   t
   is_zipfileR:   R   t
   is_tarfilet   TAR_EXTENSIONSR   R   R;   R}   R3   R4   t   pip._internal.vcs.subversionR  R  t   unpackR   t   criticalR   (   R   R   t   content_typet   linkR  R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR<     s.    c         C@  s   d j  d   |  D  S(   s/   
    Format command arguments for display.
    t    c         s@  s   |  ] } t  |  Vq d  S(   N(   R   (   t   .0t   arg(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pys	   <genexpr>  s    (   RG   (   t   args(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   format_command_args  s    c   	      C@  ss   t  |   } t | d d } t |  } d j |  } d j d | d | d | d t |  d	 | d
 t  } | S(   s   
    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.
    t   descs   command bytesR   u   Command errored out with exit status {exit_status}:
 command: {command_display}
     cwd: {cwd_display}
Complete output ({line_count} lines):
{output}{divider}t   exit_statust   command_displayt   cwd_displayt
   line_countt   outputt   divider(   R  R   Rv   RG   RK   RQ   t   LOG_DIVIDER(	   t   cmd_argst   cwdt   linesR  t   commandR  R  R  t   msg(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   make_subprocess_output_error  s    		t   raisec	         C@  s  | d	 k r g  } n  | d	 k r* g  } n  | rE t j }	 t j }
 n t j }	 t j }
 t j   |
 k } | oy | d	 k	 } | d	 k r t |   } n  |	 d |  t	 j
 j   } | r | j |  n  x | D] } | j | d	  q WyG t j |  d t j d t j d t j d | d | } | j j   Wn) t k
 r\} t j d | |    n Xg  } xc t rt | j j    } | sPn  | j   } | j | d  |	 |  | rf| j   qfqfWz | j   Wd	 | j r| j j   n  X| j o	| j | k } | r8| r(| j d
  q8| j d  n  | r| d k r| st  d |  d | d | d | j  } t j! |  n  d j" | j |  } t# |   q| d k rt j$ d | | j |  q| d k rqt% d t& |    n  d j' |  S(   s  
    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().
    s   Running command %st   stderrt   stdint   stdoutR  t   envs#   Error %s while executing command %ss   
Nt   errort   doneR  R  R  R  sS   Command errored out with exit status {}: {} Check the logs for full command output.t   warns$   Command "%s" had error code %s in %st   ignores   Invalid value: on_returncode=%sR   ((   Rp   t   subprocess_loggerR   t   std_loggingt   INFOt   debugt   DEBUGt   getEffectiveLevelR  RE   R   t   copyt   updatet   popt
   subprocesst   Popent   STDOUTt   PIPER!  R   R   R	  R   R   R"  t   readlinet   rstripR   t   spint   waitt
   returncodet   finishR  R$  RK   R   R   t
   ValueErrort   reprRG   (   t   cmdt   show_stdoutR  t   on_returncodet   extra_ok_returncodest   command_desct   extra_environt   unset_environt   spinnert   log_subprocesst
   used_levelt   showing_subprocesst   use_spinnerR#  R   t   procR   t
   all_outputt   linet   proc_had_errorR  t   exc_msg(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR=   +  s    						
	c         C@  s   t  j |   t |   d  S(   N(   RE   RT   R   (   t	   build_dir(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.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(    (   R  t   l(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pys	   <genexpr>  s    (   t   _gen(   t   selfR  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   __init__  s    c         C@  sL   y3 y t  |  j  SWn t k
 r1 |  j j    SXWn t k
 rG d SXd  S(   NR   (   t   nextRR  t	   NameErrort   StopIteration(   RS  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR5    s    c         C@  s   |  j  S(   N(   RR  (   RS  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   __iter__  s    (   t   __name__t
   __module__t   __doc__RT  R5  RX  (    (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyRP    s   			t   StreamWrapperc           B@  s&   e  Z e d     Z e d    Z RS(   c         C@  s   | |  _  |    S(   N(   t   orig_stream(   t   clsR]  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   from_stream  s    	c         C@  s
   |  j  j S(   N(   R]  t   encoding(   RS  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR`    s    (   RY  RZ  t   classmethodR_  t   propertyR`  (    (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR\    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   getattrRL   t   setattrR\  R_  (   t   stream_namet   orig_stdout(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.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"  (   Rg  (    (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyR>     s    	c           C@  s
   t  d  S(   s    
    See captured_stdout().
    R   (   Rg  (    (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   captured_stderr  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[  (   Rc  R[  Rm   (   RS  Rm   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyRT     s    c         C@  s4   | d  k r |  S|  j |  } | j |  j j <| S(   N(   Rp   Rm   t   __dict__RY  (   RS  t   objR^  R+   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   __get__  s     (   RY  RZ  R[  RT  Rl  (    (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyRi    s   	c         C@  sM   t  j j |   } | d k r- t  j   } n  | j |  } | rI | j Sd S(   sC   Get the installed version of dist_name avoiding pkg_resources cacheN(   R   t   RequirementR   Rp   R   R   RM   (   t	   dist_nameR   t   reqR   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyRC     s
    c         C@  s   t  |  d d d S(   s   Consume an iterable at C speed.t   maxleni    N(   R   (   t   iterator(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   consume  s    c          O@  sT   t  t |  t t |     |  } d   | j   D } | | d <t d d |  S(   Nc         S@  s   i  |  ] \ } } | |  q S(    (    (   R  R   R+   (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pys
   <dictcomp>&  s   	 t   reverse_mappingt   Enum(    (   t   dictR   t   rangeRQ   t   itemst   type(   t
   sequentialt   namedt   enumst   reverse(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   enum$  s    $
c         C@  s=   t  j j t  j j |    }  t j d t j |    } | S(   sh   
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    s   file:(   RE   RF   t   normpathRJ   t   urllib_parset   urljoint   urllib_requestt   pathname2url(   RF   R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   path_to_url+  s    c         C@  s{   d |  k r |  d f S|  j d d  \ } }  d | k rO | j d d  } n | d f } t d   | D  } |  | f S(   sp   
    Parse out and remove the auth information from a netloc.

    Returns: (netloc, (username, password)).
    t   @i   t   :c         s@  s-   |  ]# } | d  k r d  n	 t |  Vq d  S(   N(   Rp   t   urllib_unquote(   R  t   x(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pys	   <genexpr>L  s    N(   NN(   Rp   t   rsplitR   t   tuple(   t   netloct   autht	   user_pass(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   split_auth_from_netloc6  s    
c         C@  se   t  |   \ }  \ } } | d k r( |  S| d k r: d n d } d j d t j |  d | d |   S(   s   
    Replace the password in a netloc with "****", if it exists.

    For example, "user:pass@example.com" returns "user:****@example.com".
    R   s   :****s   {user}{password}@{netloc}t   usert   passwordR  N(   R  Rp   RK   R  t   quote(   R  R  R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   redact_netlocR  s    c         C@  s\   t  j |   } | | j  } | j | d | j | j | j f } t  j |  } | | f S(   sR  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.
    i    (   R  t   urlsplitR  t   schemeRF   t   queryt   fragmentt
   urlunsplit(   R  t   transform_netloct   purlt   netloc_tuplet
   url_piecest   surl(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   _transform_urlb  s
    
%c         C@  s
   t  |   S(   N(   R  (   R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   _get_netlocv  s    c         C@  s   t  |   f S(   N(   R  (   R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   _redact_netlocz  s    c         C@  s(   t  |  t  \ } \ } } | | | f S(   s   
    Parse a url into separate netloc, auth, and url with no auth.

    Returns: (url_without_auth, netloc, (username, password))
    (   R  R  (   R  t   url_without_authR  R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   split_auth_netloc_from_url~  s    c         C@  s   t  |  t  d S(   s7   Return a copy of url with 'username:password@' removed.i    (   R  R  (   R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyRD     s    c         C@  s   t  |  t  d S(   s.   Replace the password in a given url with ****.i    (   R  R  (   R  (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   redact_password_from_url  s    c         C@  s   d d j  t j d  d j  t j d    g } |  oW t oW t j j t j d  | k } | r t j d d g t j d } t	 d	 j  d
 j
 |     n  d S(   s   Protection of pip.exe from modification on Windows

    On Windows, any operation modifying pip should be run as:
        python -m pip ...
    s   pip.exes	   pip{}.exei    s   pip{}.{}.exei   s   -mRY   i   s3   To modify pip, please run the following command:
{}R  N(   RK   RL   Rz   R   RE   RF   RZ   R[   R\   R   RG   (   t   modifying_pipt	   pip_namest   should_show_use_python_msgt   new_command(    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt(   protect_pip_from_modification_on_windows  s    (   s   .tar.bz2s   .tbz(   s   .tar.xzs   .txzs   .tlzs   .tar.lzs	   .tar.lzma(   s   .tar.gzs   .tgzs   .tar(   t
   __future__R    t
   contextlibRV   R   t   iot   loggingR)  RE   R   R   Re   Rh   R1  RL   R   R   t   collectionsR   t   pip._vendorR   t   pip._vendor.retryingR   t   pip._vendor.sixR   R   t   pip._vendor.six.movesR   R   t   pip._vendor.six.moves.urllibR   R  R	   R  t"   pip._vendor.six.moves.urllib.parseR
   R  RY   R   t   pip._internal.exceptionsR   R   t   pip._internal.locationsR   R   t   pip._internal.utils.compatR   R   R   R   R   t    pip._internal.utils.marker_filesR   t   pip._internal.utils.typingR   t   pip._internal.utils.virtualenvR   R   R   R   t   typingR   R   R   R   R   R    R!   R"   R#   R$   R%   R&   t   pip._vendor.pkg_resourcesR'   t   pip._internal.models.linkR(   t   pip._internal.utils.uiR)   t   intRP   t   __all__t	   getLoggerRY  R   R(  R  RB   R   R   R  R  R@   RA   t   bz2t   ImportErrorR+  t   lzmaRO   RS   R?   R9   R   R,   Rf   Rv   R-   R.   R   R   R/   R   R   R1   R2   R3   R4   t   DEFAULT_BUFFER_SIZER   R5   R6   R   R7   R0   R8   R   R   R   R   R   Rp   R   R   R   R   R:   R;   R<   R  R  R=   RO  t   objectRP  R\  t   contextmanagerRg  R>   Rh  Ri  RC   Rr  R}  R  R  R  R  R  R  R  RD   R  R  (    (    (    s7   lib/python2.7/site-packages/pip/_internal/utils/misc.pyt   <module>   s  (R			
			
			"			
												
							?	'		.	L	(		,}														