
'^c           @@  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l 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! d  d l" m# Z# m$ Z$ m% Z% d  d l& m' Z' m( Z( m) Z) m* Z* d  d l+ m, Z, m- Z- d  d l. m/ Z/ m0 Z0 e rd  d l m1 Z2 n d  d l m2 Z2 e, r)d  d l3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 m: Z: m; Z; m< Z< d  d l= m> Z> e; e? e? e? f Z@ n  d d d d d d d d d d d d d  d! g ZA e jB eC  ZD d"   ZE d#   ZF d$   ZG d%   ZH e d& d' d( d)  eI d*   ZJ d+   ZK d,   ZL d-   ZM d. d/  ZN d0   ZO d1   ZP d2   ZQ d3   ZR d4   ZS d5   ZT d6   ZU e jV d7  ZW eX d8  ZY d9   ZZ d:   Z[ d;   Z\ d<   Z] d=   Z^ d>   Z_ d?   Z` eX e) eX eI eI d d@  Zb dA   Zc dB   Zd dC   Ze dD ef f dE     YZg dF e2 f dG     YZh e ji dH    Zj dI   Zk dJ   Zl dK ef f dL     YZm d dM  Zn dN   Zo dO   Zp dP   Zq dQ dR  Zr dS   Zs dT   Zt dU   Zu dV   Zv dW   Zw dX   Zx dY   Zy dZ   Zz d[   Z{ d\ ef f d]     YZ| d^   Z} d_   Z~ d`   Z da   Z df dd  Z de   Z d S(g   i    (   t   absolute_importN(   t   deque(   t   pkg_resources(   t   retry(   t   PY2t	   text_type(   t   input(   t   parse(   t   unquote(   t   __version__(   t   CommandError(   t   get_major_minor_versiont   site_packagest	   user_site(   t   WINDOWSt
   expandusert   stdlib_pkgst   str_to_display(   t   MYPY_CHECK_RUNNINGt   cast(   t   running_under_virtualenvt   virtualenv_no_global(   t   BytesIO(   t   StringIO(	   t   Anyt   AnyStrt	   Containert   Iterablet   Listt   Optionalt   Textt   Tuplet   Union(   t   Distributiont   rmtreet   display_patht
   backup_dirt   askt   splitextt   format_sizet   is_installable_dirt   normalize_patht   renamest   get_progt   captured_stdoutt
   ensure_dirt   get_installed_versiont   remove_auth_from_urlc          C@  sL   t  j j t  j j t  d d  }  t  j j |   }  d j t |  t    S(   Ns   ..s   pip {} from {} (python {})(	   t   ost   patht   joint   dirnamet   __file__t   abspatht   formatR	   R   (   t   pip_pkg_dir(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   get_pip_versionK   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(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   normalize_version_infoW   s
    c         C@  sU   y t  j |   Wn= t k
 rP } | j t j k rQ | j t j k rQ   qQ n Xd S(   s    os.path.makedirs without EEXIST.N(   R0   t   makedirst   OSErrort   errnot   EEXISTt	   ENOTEMPTY(   R1   t   e(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR-   k   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(	   R0   R1   t   basenamet   syst   argvt
   executablet   AttributeErrort	   TypeErrort
   IndexError(   t   prog(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR+   v   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   dirRN   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR"      s    c         C@  sg   y t  j |  j t j @} Wn t t f k
 r8 d SX| 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(   R0   t   statt   st_modet   S_IWRITEt   IOErrorR>   t   chmod(   t   funcR1   t   exc_infot   has_attr_readonly(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyRQ      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   decodeRE   t   getfilesystemencodingt   UnicodeDecodeErrorR   R   R6   t   ascii(   R1   R#   (    (    s5   /tmp/pip-build-eiI0Wo/pip/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   .(   R0   R1   t   normcaseR5   RE   t   version_infoR^   R_   t   encodet   getdefaultencodingt
   startswitht   getcwdt   sepR:   (   R1   (    (    s5   /tmp/pip-build-eiI0Wo/pip/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   (   R0   R1   t   existst   str(   RR   t   extt   nt	   extension(    (    s5   /tmp/pip-build-eiI0Wo/pip/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    (   R0   t   environt   gett   splitR%   (   t   messaget   optionst   action(    (    s5   /tmp/pip-build-eiI0Wo/pip/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(   R0   Rs   Rt   t	   Exception(   Rv   (    (    s5   /tmp/pip-build-eiI0Wo/pip/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   lowerR2   (   Rv   Rw   t   response(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR%      s    
c         C@  s   t  |   t |   S(   s   Ask for input interactively.(   R|   R   (   Rv   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt	   ask_input   s    
c         C@  s   t  |   t j |   S(   s!   Ask for a password interactively.(   R|   t   getpass(   Rv   (    (    s5   /tmp/pip-build-eiI0Wo/pip/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   %.1f MBg     @@i
   s   %i kBs   %.1f kBs   %i bytesi@B i'  (    (   t   bytes(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR'   
  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(   R0   R1   t   isdirt   FalseR2   t   isfilet   True(   R1   t   setup_pyt   pyproject_toml(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR(     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   t   read(   t   filet   sizet   chunk(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   read_chunks%  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   R0   R1   t   realpathR5   Re   (   R1   t   resolve_symlinks(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.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&   R~   t   endswith(   R1   t   baseRn   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.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(	   R0   R1   Ru   Rl   R=   RP   t   movet
   removedirsR>   (   t   oldt   newt   headt   tail(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR*   F  s    c         C@  s#   t    s t S|  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."

    Caution: this function assumes the head of path has been normalized
    with normalize_path.
    (   R   R   Ri   R)   RE   t   prefix(   R1   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   is_localX  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(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   dist_is_localg  s    	c         C@  s   t  |   j t t   S(   sF   
    Return True if given Distribution is installed in user site.
    (   R   Ri   R)   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   dist_in_usersites  s    c         C@  s   t  |   j t t   S(   s[   
    Return True if given Distribution is installed in
    sysconfig.get_python_lib().
    (   R   Ri   R)   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/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(   RE   R1   R0   R2   t   project_nameR   R   R   (   R   t	   path_itemt   egg_link(    (    s5   /tmp/pip-build-eiI0Wo/pip/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(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt
   local_test  s    c         S@  s   t  S(   N(   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   editable_test  s    c         S@  s   t  |   S(   N(   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR     s    c         S@  s
   t  |   S(   N(   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   editables_only_test  s    c         S@  s   t  S(   N(   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR     s    c         S@  s   t  S(   N(   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/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_onlyt   pathsR   R   R   R   R   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   get_installed_distributions  s*    							c         C@  s   g  } t    r? | j t  t   rb t rb | j t  qb n# t rU | j t  n  | j t  x@ | D]8 } t j j | |  j  d } t j j	 |  ri | Sqi 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   t   appendR   R   R   R0   R1   R2   R   R   R\   (   R   t   sitest   sitet   egglink(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   egg_link_path  s    	c         C@  s)   t  |   } | r t |  St |  j  S(   sO  
    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.

    The returned location is normalized (in particular, with symlinks removed).
    (   R   R)   t   location(   R   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR     s    

c         G@  s   t  j |  |  d  S(   N(   t   loggert   info(   t   msgt   args(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   write_output  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(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pys	   <genexpr>  s    (   t   _gen(   t   selft   lines(    (    s5   /tmp/pip-build-eiI0Wo/pip/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(   NRr   (   t   nextR   t	   NameErrort   StopIteration(   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   readline  s    c         C@  s   |  j  S(   N(   R   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   __iter__  s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR     s   			t   StreamWrapperc           B@  s&   e  Z e d     Z e d    Z RS(   c         C@  s   | |  _  |    S(   N(   t   orig_stream(   t   clsR   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   from_stream"  s    	c         C@  s
   |  j  j S(   N(   R   t   encoding(   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR   (  s    (   R   R   t   classmethodR   t   propertyR   (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/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   getattrRE   t   setattrR   R   (   t   stream_namet   orig_stdout(    (    s5   /tmp/pip-build-eiI0Wo/pip/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.
    t   stdout(   R   (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR,   <  s    	c           C@  s
   t  d  S(   s    
    See captured_stdout().
    t   stderr(   R   (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   captured_stderrH  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   (   R   R   RX   (   R   RX   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR   W  s    c         C@  s4   | d  k r |  S|  j |  } | j |  j j <| S(   N(   R\   RX   t   __dict__R   (   R   t   objR   t   value(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   __get__[  s     (   R   R   R   R   R   (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR   O  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   R\   R   t   findt   version(   t	   dist_nameR   t   reqR   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR.   c  s
    c         C@  s   t  |  d d d S(   s   Consume an iterable at C speed.t   maxleni    N(   R   (   t   iterator(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   consumeu  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   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pys
   <dictcomp>}  s   	 t   reverse_mappingt   Enum(    (   t   dictt   zipt   rangeR:   t   itemst   type(   t
   sequentialt   namedt   enumst   reverse(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   enum{  s    $
c         C@  s>   | d k r |  Sd |  k r. d j |   }  n  d j |  |  S(   s.   
    Build a netloc from a host-port pair
    t   :s   [{}]s   {}:{}N(   R\   R6   (   t   hostt   port(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   build_netloc  s
    t   httpsc         C@  sO   |  j  d  d k r? d |  k r? d |  k r? d j |   }  n  d j | |   S(   s)   
    Build a full URL from a netloc.
    R   i   t   @t   [s   [{}]s   {}://{}(   t   countR6   (   t   netloct   scheme(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   build_url_from_netloc  s    -c         C@  s+   t  |   } t j |  } | j | j f S(   s2   
    Return the host-port pair from a netloc.
    (   R   t   urllib_parset   urlparset   hostnameR   (   R   t   urlt   parsed(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   parse_netloc  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)).
    R   i   R   c         s@  s-   |  ]# } | d  k r d  n	 t |  Vq d  S(   N(   R\   t   urllib_unquote(   R   t   x(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pys	   <genexpr>  s    N(   NN(   R\   t   rsplitRu   t   tuple(   R   t   autht	   user_pass(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   split_auth_from_netloc  s    
c         C@  st   t  |   \ }  \ } } | d k r( |  S| d k rC d } d } n t j |  } d } d j d | d | d |   S(	   s   
    Replace the sensitive data in a netloc with "****", if it exists.

    For example:
        - "user:pass@example.com" returns "user:****@example.com"
        - "accesstoken@example.com" returns "****@example.com"
    s   ****Rr   s   :****s   {user}{password}@{netloc}t   usert   passwordR   N(   R  R\   R  t   quoteR6   (   R   R  R  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   redact_netloc  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   R   R1   t   queryt   fragmentt
   urlunsplit(   R  t   transform_netloct   purlt   netloc_tuplet
   url_piecest   surl(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   _transform_url  s
    
%c         C@  s
   t  |   S(   N(   R  (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   _get_netloc  s    c         C@  s   t  |   f S(   N(   R  (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   _redact_netloc  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  (    (    s5   /tmp/pip-build-eiI0Wo/pip/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  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR/     s    c         C@  s   t  |  t  d S(   s.   Replace the password in a given url with ****.i    (   R  R  (   R  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   redact_auth_from_url  s    t
   HiddenTextc           B@  s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C@  s   | |  _  | |  _ d  S(   N(   t   secrett   redacted(   R   R"  R#  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR     s    	c         C@  s   d j  t |    S(   Ns   <HiddenText {!r}>(   R6   Rm   (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   __repr__  s    c         C@  s   |  j  S(   N(   R#  (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   __str__  s    c         C@  s,   t  |   t  |  k r t S|  j | j k S(   N(   R   R   R"  (   R   t   other(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   __eq__  s    c         C@  s   |  | k S(   N(    (   R   R&  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   __ne__*  s    (   R   R   R   R$  R%  R'  R(  (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyR!    s
   					c         C@  s   t  |  d d S(   NR#  s   ****(   R!  (   R   (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt
   hide_value/  s    c         C@  s   t  |   } t |  d | S(   NR#  (   R   R!  (   R  R#  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   hide_url4  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   -mRC   i   s3   To modify pip, please run the following command:
{}t    N(   R6   RE   Rf   R   R0   R1   RD   RF   RG   R
   R2   (   t   modifying_pipt	   pip_namest   should_show_use_python_msgt   new_command(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt(   protect_pip_from_modification_on_windows:  s    c           C@  s   t  j d k	 o t  j j   S(   s!   Is this console interactive?
    N(   RE   t   stdinR\   t   isatty(    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   is_console_interactiveX  s    i   i   c         C@  sn   t  j   } d } t |  d  A } x7 t | d | D]# } | t |  7} | j |  q7 WWd QX| | f S(   s:   Return (hash, length) for path using hashlib.sha256()
    i    t   rbR   N(   t   hashlibt   sha256t   openR   R:   t   update(   R1   t	   blocksizet   ht   lengtht   ft   block(    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt	   hash_file_  s    c          C@  s)   y d d l  }  Wn t k
 r$ t SXt S(   s8   
    Return whether the wheel package is installed.
    i    N(   t   wheelt   ImportErrorR   R   (   R?  (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   is_wheel_installedm  s
    i   (   t
   __future__R    t
   contextlibR?   R   R5  t   iot   loggingR0   R   RP   RS   RE   t   collectionsR   t   pip._vendorR   t   pip._vendor.retryingR   t   pip._vendor.sixR   R   t   pip._vendor.six.movesR   t   pip._vendor.six.moves.urllibR   R  t"   pip._vendor.six.moves.urllib.parseR   R  RC   R	   t   pip._internal.exceptionsR
   t   pip._internal.locationsR   R   R   t   pip._internal.utils.compatR   R   R   R   t   pip._internal.utils.typingR   R   t   pip._internal.utils.virtualenvR   R   R   R   t   typingR   R   R   R   R   R   R   R   R    t   pip._vendor.pkg_resourcesR!   t   intR9   t   __all__t	   getLoggerR   R   R8   R<   R-   R+   R   R"   RQ   Rb   R#   R$   Ry   R|   R%   R   R   R'   R(   t   DEFAULT_BUFFER_SIZER   R   R)   R&   R*   R   R   R   R   R   R\   R   R   R   R   t   objectR   R   t   contextmanagerR   R,   R   R   R.   R   R   R   R   R  R  R  R  R  R  R  R/   R   R!  R)  R*  R0  R3  R>  RA  (    (    (    s5   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/misc.pyt   <module>   s   "@							"			
							
							>	$								
								#				