
b]c           @@  sa  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 m Z 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 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* Z* d  d l+ m, Z, m- Z- d  d l. m/ Z/ d  d l0 m1 Z1 m2 Z2 d  d l3 m4 Z4 d  d l5 m6 Z6 d  d l7 m8 Z8 d  d l9 m: Z: d  d l; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI mJ ZJ mK ZK d  d lL mM ZM d  d lN mO ZO d  d lP mQ ZQ d  d lR mS ZS eO r"d  d lT mU ZU mV ZV mW ZW mX ZX mY ZY mZ ZZ d  d l[ m\ Z\ d  d l] m^ Z^ d  d l_ m` Z` d  d la mb Zb mc Zc eV ed ed ed f Ze n  d  d! d" d# d$ d% d& d' d( d) d* d+ d, g Zf e jg eh  Zi y d  d lj Zj WnE ek k
 rd Zj n/ em k
 rZn ei jo d- ed en   d Zj n XdW Zp d2   Zq d3   Zr d4   Zs d5 e f d6     YZt d7 e f d8     YZu d9 e f d:     YZv d; e f d<     YZw d= e jx f d>     YZy d d d?  Zz e
 j{ d@ e
 j|  Z} e
 j{ dA e
 j|  Z~ dB   Z dC   Z dD   Z dE   Z dF   Z dG   Z dH   Z dI   Z dJ   Z dK   Z dL   Z d d d dM dN  Z d d dO  Z dP e$ j f dQ     YZ d e d d dM dR  Z dS   Z dT   Z dU   Z dV   Z d S(X   i    (   t   absolute_importN(   t   requestst   urllib3(   t   CacheControlAdapter(   t	   FileCache(   t	   LockError(   t   BaseAdaptert   HTTPAdapter(   t   AuthBaset   HTTPBasicAuth(   t   CONTENT_CHUNK_SIZEt   Response(   t   CaseInsensitiveDict(   t   get_netrc_auth(   t   xmlrpc_client(   t   parse(   t   request(   t   HashMismatcht   InstallationError(   t   PyPI(   t   HAS_TLSt   ssl(   t   auto_decode(   t   check_path_owner(   t   libc_ver(   t   write_delete_marker_file(   t   ARCHIVE_EXTENSIONSt   askt	   ask_inputt   ask_passwordt   ask_path_existst
   backup_dirt   consumet   display_patht   format_sizet   get_installed_versiont   path_to_urlt   remove_auth_from_urlt   rmtreet   split_auth_netloc_from_urlt   splitextt   unpack_file(   t   TempDirectory(   t   MYPY_CHECK_RUNNING(   t   DownloadProgressProvider(   t   vcs(   t   Optionalt   Tuplet   Dictt   IOt   Textt   Union(   t   Values(   t   Link(   t   Hashes(   t   AuthInfot   VersionControlt   get_file_contentt   is_urlt   url_to_pathR$   t   is_archive_filet   unpack_vcs_linkt   unpack_file_urlt
   is_vcs_urlt   is_file_urlt   unpack_http_urlt
   unpack_urlt   parse_content_dispositiont   sanitize_content_filenames*   Keyring is skipped due to an exception: %st   BUILD_BUILDIDt   BUILD_IDt   CIt	   PIP_IS_CIc           C@  s   t  d   t D  S(   s?   
    Return whether it looks like pip is running under CI.
    c         s@  s   |  ] } | t  j k Vq d  S(   N(   t   ost   environ(   t   .0t   name(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pys	   <genexpr>l   s    (   t   anyt   CI_ENVIRONMENT_VARIABLES(    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   looks_like_cid   s    c       
   C@  s=  i i d d 6t  j d 6d 6t j   d 6i t j   d 6d 6}  |  d d d k rj t j   |  d d <n |  d d d k r t j j d	 k r t j d
  } n	 t j } d j g  | D] } t	 |  ^ q  |  d d <nV |  d d d k rt j   |  d d <n+ |  d d d k r2t j   |  d d <n  t j j
 d  rd d l m } t t d   t d d d g | j      } t t d   t d d g t      } | r| | d <n  | r| |  d <qn  t j j
 d  rt j   d ri d d 6t j   d d 6|  d <n  t j   rIt j   |  j d i   d <n  t j   rtt j   |  j d i   d <n  t j   rt j   |  d <n  t rt j |  d <n  t d  } | d) k	 r| |  d <n  t   rt n d) |  d <t j j  d   } | d) k	 r| |  d! <n  d" j! d# |  d$ t" j# |  d% d* d( t  S(+   s6   
    Return a string representing the user agent.
    t   pipRL   t   versiont	   installert   pythont   implementationt   CPythont   PyPyt   finali   t   .t   Jythont
   IronPythont   linuxi    (   t   distroc         S@  s   |  d S(   Ni   (    (   t   x(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   <lambda>   t    t   idc         S@  s   |  d S(   Ni   (    (   R]   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR^      R_   t   libt   libcR\   t   darwint   macOSt   systemt   releaset   cput   openssl_versiont
   setuptoolst   setuptools_versiont   cit   PIP_USER_AGENT_USER_DATAt	   user_datas9   {data[installer][name]}/{data[installer][version]} {json}t   datat   jsont
   separatorst   ,t   :t	   sort_keysN(   Rq   Rr   ($   RP   t   __version__t   platformt   python_versiont   python_implementationt   syst   pypy_version_infot   releaselevelt   joint   strt
   startswitht   pip._vendorR\   t   dictt   filtert   zipt   linux_distributionR   t   mac_verRe   t
   setdefaultRf   t   machineR   R   t   OPENSSL_VERSIONR#   t   NoneRO   t   TrueRI   RJ   t   gett   formatRo   t   dumps(   Rn   Ry   R]   R\   t   distro_infosRb   Rj   Rm   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt
   user_agento   sb    	-$"%	c         C@  s   |  s t  r d Sy y t  j } Wn t k
 r5 n@ Xt j d |   | |  |  } | d k	 rq | j | j f Sd S| r t j d |   t  j |  |  } | r | | f Sn  Wn) t	 k
 r } t j
 d t |   n Xd S(   s3   Return the tuple auth for a given url from keyring.s'   Getting credentials from keyring for %ss$   Getting password from keyring for %ss*   Keyring is skipped due to an exception: %sN(   t   keyringR   t   get_credentialt   AttributeErrort   loggert   debugt   usernamet   passwordt   get_passwordt	   Exceptiont   warningR|   (   t   urlR   R   t   credR   t   exc(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _get_keyring_auth   s(    	t   MultiDomainBasicAuthc           B@  sn   e  Z e d
 d   Z d   Z e e d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(   c         C@  s(   | |  _  | |  _ i  |  _ d  |  _ d  S(   N(   t	   promptingt
   index_urlst	   passwordsR   t   _credentials_to_save(   t   selfR   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   __init__   s    			c         C@  sY   | s |  j  r d Sx= |  j  D]2 } t |  j d  d } | j |  r | Sq Wd S(   s  Return the original index URL matching the requested URL.

        Cached or dynamically generated credentials may work against
        the original index URL rather than just the netloc.

        The provided url should have had its username and password
        removed already. If the original index url had credentials then
        they will be included in the return value.

        Returns None if no matching index was found, or if --no-index
        was specified by the user.
        t   /N(   R   R   R%   t   rstripR}   (   R   R   t   ut   prefix(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _get_index_url   s    c         C@  sd  t  |  \ } } } | \ } } | d k	 rM | d k	 rM t j d |  | S|  j |  }	 |	 r t  |	  }
 |
 r |
 \ }	 } } t j d |	  q n  |	 r | d d k	 r | \ } } | d k	 r | d k	 r t j d |  | Sn  | rt |  } | rt j d |  | Sn  | rZt |	 |  p:t | |  } | rZt j d |  | Sn  | | f S(   s2   Find and return credentials for the specified URL.s   Found credentials in url for %ss   Found index url %si    s%   Found credentials in index url for %ss!   Found credentials in netrc for %ss#   Found credentials in keyring for %sN(   R'   R   R   R   R   R   R   (   R   t   original_urlt   allow_netrct   allow_keyringR   t   netloct   url_user_passwordR   R   t	   index_urlt
   index_infot   _t   index_url_user_passwordt
   netrc_autht   kr_auth(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _get_new_credentials   s:    c         C@  s   t  |  \ } } } |  j j | d  \ } } | d k r` | d k r` |  j |  \ } } n  | d k	 sx | d k	 r | p d } | p d } | | f |  j | <n  | d k	 r | d k	 s | d k r | d k s t d j |    | | | f S(   s_  Return the credentials to use for the provided URL.

        If allowed, netrc and keyring may be used to obtain the
        correct credentials.

        Returns (url_without_credentials, username, password). Note
        that even if the original URL contains credentials, this
        function may return a different username and password.
        R_   s'   Could not load credentials from url: {}N(   NN(   R'   R   R   R   R   t   AssertionErrorR   (   R   R   R   R   R   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _get_url_and_credentials,  s    
c         C@  sk   |  j  | j  \ } } } | | _ | d  k	 rT | d  k	 rT t | |  |  } n  | j d |  j  | S(   Nt   response(   R   R   R   R	   t   register_hookt
   handle_401(   R   t   reqR   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   __call__T  s    	c         C@  s]   t  d |  } | s d St | |  } | rD | d | d t f St d  } | | t f S(   Ns   User for %s: i    i   s
   Password: (   NN(   R   R   R   t   FalseR   R   (   R   R   R   t   authR   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _prompt_for_passworde  s    c         C@  s#   t  s
 t St d d d g  d k S(   Ns#   Save credentials to keyring [y/N]: t   yt   n(   R   R   R   (   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt    _should_save_password_to_keyringp  s    c   	      K@  sD  | j  d k r | S|  j s  | St j | j  } |  j | j  \ } } } d  |  _ | d  k	 r | d  k	 r | | f |  j	 | j <| r |  j
   r | j | | f |  _ q n  | j | j j   t | p d | p d  | j  } | j d |  j  |  j r| j d |  j  n  | j j | |  } | j j |  | S(   Ni  R_   R   (   t   status_codeR   t   urllib_parset   urlparseR   R   R   R   R   R   R   t   contentt   rawt   release_connR	   R   R   t   warn_on_401t   save_credentialst
   connectiont   sendt   historyt   append(	   R   t   respt   kwargst   parsedR   R   t   saveR   t   new_resp(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR   u  s(    		$	c         K@  s,   | j  d k r( t j d | j j  n  d S(   s6   Response callback to warn about incorrect credentials.i  s)   401 Error, Credentials not correct for %sN(   R   R   R   R   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    	c         K@  s   t  d k	 s t d   t  s" d S|  j } d |  _ | r | j d k  r y t j d  t  j |   Wq t k
 r t j	 d  q Xn  d S(   s1   Response callback to save credentials on success.s'   should never reach here without keyringNi  s   Saving credentials to keyrings   Failed to save credentials(
   R   R   R   R   R   R   t   infot   set_passwordR   t	   exception(   R   R   R   t   creds(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    		N(   t   __name__t
   __module__R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR      s   	.	(				-	t   LocalFSAdapterc           B@  s)   e  Z d d d d d d   Z d   Z RS(   c         C@  s   t  | j  } t   } d | _ | j | _ y t j |  }	 Wn% t k
 rg }
 d | _ |
 | _ n} Xt j	 j
 |	 j d t } t j |  d p d } t i | d 6|	 j d 6| d 6 | _ t | d	  | _ | j j | _ | S(
   Ni   i  t   usegmti    s
   text/plains   Content-Types   Content-Lengths   Last-Modifiedt   rb(   R;   R   R   R   RI   t   statt   OSErrorR   t   emailt   utilst
   formatdatet   st_mtimeR   t	   mimetypest
   guess_typeR   t   st_sizet   headerst   opent   close(   R   R   t   streamt   timeoutt   verifyt   certt   proxiest   pathnameR   t   statsR   t   modifiedt   content_type(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s$    			
c         C@  s   d  S(   N(    (   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    N(   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s   t   SafeFileCachec           B@  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sw   
    A file based cache which is safe to use even when the target directory may
    not be accessible or writable.
    c         O@  sK   t  t |   j | |   t |  j  sG t j d |  j  d  |  _ n  d  S(   Ns   The directory '%s' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.(   t   superR   R   R   t	   directoryR   R   R   (   R   t   argsR   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    
c         O@  sQ   |  j  d  k r d  Sy t t |   j | |   SWn t t t f k
 rL n Xd  S(   N(   R   R   R   R   R   R   R   t   IOError(   R   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    c         O@  sQ   |  j  d  k r d  Sy t t |   j | |   SWn t t t f k
 rL n Xd  S(   N(   R   R   R   R   t   setR   R   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR      s    c         O@  sQ   |  j  d  k r d  Sy t t |   j | |   SWn t t t f k
 rL n Xd  S(   N(   R   R   R   R   t   deleteR   R   R   (   R   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    (   R   R   t   __doc__R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s
   			t   InsecureHTTPAdapterc           B@  s   e  Z d    Z RS(   c         C@  s   d | _  d  | _ d  S(   Nt	   CERT_NONE(   t	   cert_reqsR   t   ca_certs(   R   t   connR   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   cert_verify  s    	(   R   R   R   (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s   t
   PipSessionc           B@  s)   e  Z d Z d    Z d   Z d   Z RS(   c   
      O@  sS  | j  d d  } | j  d d   } | j  d g   } | j  d d   } t t |   j | |   t   |  j d <t d |  |  _ t	 j
 d | d d	 d
 d d g d d  } | r t d t | d t d |  } n t d |  } t d |  } | |  _ |  j d |  |  j d |  |  j d t    x | D] }	 |  j |	  q8Wd  S(   Nt   retriesi    t   cachet   insecure_hostsR   s
   User-Agentt   totalt   status_forcelisti  i  i  i  t   backoff_factorg      ?t   use_dir_lockt   max_retriess   https://s   http://s   file://(   t   popR   R   R   R   R   R   R   R   R   t   RetryR   R   R   R   R   t   _insecure_adaptert   mountR   t   add_insecure_host(
   R   R   R   R   R   R  R   t   secure_adaptert   insecure_adaptert   host(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR   &  s.    			c         C@  s    |  j  d j |  |  j  d  S(   Ns   https://{}/(   R
  R   R	  (   R   R  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR  g  s    c         O@  s2   | j  d |  j  t t |   j | | | |  S(   NR   (   R   R   R   R   R   (   R   t   methodR   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR   k  s    N(   R   R   R   R   R   R  R   (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR   "  s   	A	c   
      C@  s  | d k r t d   n  t j |   } | r[| j d  j   } | d k r | r | j d  r t d | |  f   n  | d k r/|  j d d  d } | j	 d d  } t
 j |  } | r | j d  d | j d	 d  d } n  t j |  } | j d  r&d | j d  } n  | }  q[| j |   } | j   | j | j f Sn  y. t |  d
   } t | j    } Wd QXWn) t k
 r}	 t d t |	    n X|  | f S(   s*  Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.

    :param url:         File path or url.
    :param comes_from:  Origin description of requirements.
    :param session:     Instance of pip.download.PipSession.
    sA   get_file_content() missing 1 required keyword argument: 'session'i   t   filet   https6   Requirements file %s references URL %s, which is localRr   s   \R   t   |R   Ns$   Could not open requirements file: %s(   R   t	   TypeErrort
   _scheme_ret   searcht   groupt   lowerR}   R   t   splitt   replacet   _url_slash_drive_ret   matchR   t   unquotet   lstripR   t   raise_for_statusR   t   textR   R   t   readR   R|   (
   R   t
   comes_fromt   sessionR  t   schemet   pathR   t   fR   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR9   s  s>    	*	
s   ^(http|https|file):s   /*([a-z])\|c         C@  sI   d |  k r t  S|  j d d  d j   } | d d d d g t j k S(   s)   Returns true if the name looks like a URLRr   i   i    R  t   httpsR  t   ftp(   R   R  R  R-   t   all_schemes(   RL   R#  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR:     s    c         C@  s   |  j  d  s t d |    t j |   \ } } } } } | sP | d k rY d } n, t j d k ru d | } n t d |    t j | |  } | S(   s(   
    Convert a file: URL to a path.
    s   file:s4   You can only turn file: urls into filenames (not %r)t	   localhostR_   t   win32s   \\s:   non-local file URIs are not supported on this platform: %r(	   R}   R   R   t   urlsplitRx   Ru   t
   ValueErrort   urllib_requestt   url2pathname(   R   R   R   R$  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR;     s    	
c         C@  s*   t  |   d j   } | t k r& t St S(   s9   Return True if `name` is a considered as an archive file.i   (   R(   R  R   R   R   (   RL   t   ext(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR<     s    c         C@  s&   t  |   } | j | d |  j d  S(   NR   (   t   _get_used_vcs_backendt   unpackR   (   t   linkt   locationt   vcs_backend(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR=     s    c         C@  s.   x' t  j D] } |  j | j k r
 | Sq
 Wd S(   s1   
    Return a VersionControl object or None.
    N(   R-   t   backendsR#  t   schemesR   (   R2  R4  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR0    s    c         C@  s   t  t |    S(   N(   t   boolR0  (   R2  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR?     s    c         C@  s   |  j  j   j d  S(   Ns   file:(   R   R  R}   (   R2  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR@     s    c         C@  s   t  |  j  } t j j |  S(   s   Return whether a file:// Link points to a directory.

    ``link`` must not have any other scheme but file://. Call is_file_url()
    first.

    (   R;   t   url_without_fragmentRI   R$  t   isdir(   R2  t	   link_path(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt
   is_dir_url  s    c         O@  s   |  S(   N(    (   t   iterableR   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _progress_indicator  s    c         @  s  y t   j d  } Wn  t t t f k
 r9 d } n Xt  d t  } t j   t	 j
 k rj t } n9 | ry t } n* | d k r t } n | s t } n t } | j }  f d   }	   f d   }
 t } | j t j k r | } n	 | j } | rAt | d | } | r.t j d	 | t |   qjt j d
 |  n) | rZt j d |  n t j d
 |  t j d |  |
 | |	 t  t   } | r| j |  n
 t |  d  S(   Ns   content-lengthi    t
   from_cachei(   i  c         3@  sr   y, x%   j  j |  d t D] } | Vq WWn? t k
 rm x/ t ri   j  j |   } | sa Pn  | Vq? Wn Xd  S(   Nt   decode_content(   R   R   R   R   R   R   (   t
   chunk_sizet   chunk(   R   (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt	   resp_read  s    	c         3@  s'   x  |  D] }   j  |  | Vq Wd  S(   N(   t   write(   t   chunksRA  (   t   content_file(    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   written_chunks<  s    t   maxs   Downloading %s (%s)s   Downloading %ss   Using cached %ss   Downloading from URL %si@  (   t   intR   R,  t   KeyErrorR  t   getattrR   R   t   getEffectiveLevelt   loggingt   INFOR   t   show_urlR=  R   R   R8  R,   R   R"   R   R
   t   check_against_chunksR    (   R   R2  RE  t   hashest   progress_bart   total_lengtht   cached_respt   show_progressRN  RB  RF  t   progress_indicatorR   t   downloaded_chunks(    (   RE  R   s5   lib/python2.7/site-packages/pip/_internal/download.pyt   _download_url  sL    
					%					c         C@  s,  t  } t j j | | j  } t j j |  r t d t |  d
  } | d k r^ t } q | d k r t	 j
 d t |   t j |  q | d k r t |  } t	 j
 d t |  t |   t j | |  q | d k r t j d  q n  | r(t j |  |  t	 j d	 t |   n  d  S(   Ns8   The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abortt   it   wt   bt   as   Deleting %ss   Backing up %s to %sis   Saved %s(   RX  RY  RZ  R[  (   R   RI   R$  R{   t   filenamet   existsR   R!   R   R   R   t   removeR   t   shutilt   moveRx   t   exitt   copyR   (   R\  R3  R2  Rb  t   download_locationR   t	   dest_file(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt
   _copy_fileb  s.    		t   onc   
   
   C@  s   | d  k r t d   n  t d d   } d  } | rN t |  | |  } n  | rp | } t j |  d }	 n! t |  | | j | |  \ } }	 t | | |	 |   | r | r t	 | | |   n  | s t
 j |  n  Wd  QXd  S(   Ns@   unpack_http_url() missing 1 required keyword argument: 'session't   kindR1  i    (   R   R  R*   t   _check_download_dirR   R   t   _download_http_urlR$  R)   Re  RI   t   unlink(
   R2  R3  t   download_dirR"  RP  RQ  t   temp_dirt   already_downloaded_patht	   from_pathR   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRA   }  s,    	c         C@  s   t  |  j  } t |   rj t j j |  r: t |  n  t j | | d t	 | rf t
 j d  n  d S| r | j |  n  d } | r t |  | |  } n  | r | } n | } t j |  d } t | | | |   | r | r t | | |   n  d S(   s   Unpack link into location.

    If download_dir is provided and link points to a file, make a copy
    of the link file inside download_dir.
    t   symlinkss*   Link is a directory, ignoring download_dirNi    (   R;   R8  R;  RI   R$  R9  R&   R_  t   copytreeR   R   R   t   check_against_pathR   Rh  R   R   R)   Re  (   R2  R3  Rk  RP  R:  Rm  Rn  R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR>     s,    	t   PipXmlrpcTransportc           B@  s&   e  Z d  Z e d  Z e d  Z RS(   sR   Provide a `xmlrpclib.Transport` implementation via a `PipSession`
    object.
    c         C@  s;   t  j j |  |  t j |  } | j |  _ | |  _ d  S(   N(   R   t	   TransportR   R   R   R#  t   _schemet   _session(   R   R   R"  t   use_datetimet   index_parts(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    c   
      C@  s   |  j  | | d  d  d  f } t j |  } yX i d d 6} |  j j | d | d | d t } | j   | |  _ |  j	 | j
  SWn2 t j k
 r }	 t j d |	 j j |    n Xd  S(   Ns   text/xmls   Content-TypeRn   R   R   s   HTTP error %s while getting %s(   Rt  R   R   t
   urlunparseRu  t   postR   R  t   verboset   parse_responseR   R   t	   HTTPErrorR   t   criticalR   R   (
   R   R  t   handlert   request_bodyRz  t   partsR   R   R   R   (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyR     s    
	(   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRr    s   c      	   C@  s   t  |   r t |  |  n\ t |   rA t |  | | d | n7 | d k rY t   } n  t |  | | | d | d | | r t |  n  d S(   sv  Unpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    RP  RQ  N(   R?   R=   R@   R>   R   R   RA   R   (   R2  R3  Rk  t   only_downloadR"  RP  RQ  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRB     s    c         C@  s   t  j j |   S(   sJ   
    Sanitize the "filename" value from a Content-Disposition header.
    (   RI   R$  t   basename(   R\  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRD   .  s    c         C@  sC   t  j |   \ } } | j d  } | r9 t |  } n  | pB | S(   s   
    Parse the "filename" value from a Content-Disposition header, and
    return the default filename if the result is empty.
    R\  (   t   cgit   parse_headerR   RD   (   t   content_dispositiont   default_filenamet   _typet   paramsR\  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRC   6  s
    c      
   C@  s  |  j  j d d  d } y0 | j | d i d d 6d t } | j   Wn2 t j k
 r} } t j d | j	 j
 |     n X| j j d	 d
  } |  j }	 | j j d  }
 |
 r t |
 |	  }	 n  t |	  d } | st j |  } | r|	 | 7}	 qn  | rI|  j  | j  k rIt j j | j   d } | rI|	 | 7}	 qIn  t j j | |	  } t | d   } t | |  | | |  Wd QX| | f S(   s6   Download link url into temp_dir using provided sessiont   #i   i    R   t   identitys   Accept-EncodingR   s   HTTP error %s while getting %ss   content-typeR_   s   content-dispositiont   wbN(   R   R  R   R   R  R   R|  R   R}  R   R   R   R\  RC   R(   R   t   guess_extensionRI   R$  R{   R   RW  (   R2  R"  Rl  RP  RQ  t
   target_urlR   R   R   R\  R  R/  t	   file_pathRE  (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRi  E  s:    			c         C@  s   t  j j | |  j  } t  j j |  r t j d |  | r y | j |  Wq t k
 r t j	 d |  t  j
 |  d SXn  | Sd S(   s    Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    s   File was already downloaded %ss;   Previously-downloaded file %s has bad hash. Re-downloading.N(   RI   R$  R{   R\  R]  R   R   Rq  R   R   Rj  R   (   R2  Rk  RP  t   download_path(    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyRh    s    (   RE   RF   RG   RH   (   t
   __future__R    R  t   email.utilsR   Ro   RL  R   RI   Ru   t   reR_  Rx   R~   R   R   t   pip._vendor.cachecontrolR   t   pip._vendor.cachecontrol.cachesR   t   pip._vendor.lockfileR   t   pip._vendor.requests.adaptersR   R   t   pip._vendor.requests.authR   R	   t   pip._vendor.requests.modelsR
   R   t   pip._vendor.requests.structuresR   t   pip._vendor.requests.utilsR   t   pip._vendor.six.movesR   t   pip._vendor.six.moves.urllibR   R   R   R-  RP   t   pip._internal.exceptionsR   R   t   pip._internal.models.indexR   t   pip._internal.utils.compatR   R   t   pip._internal.utils.encodingR   t   pip._internal.utils.filesystemR   t   pip._internal.utils.glibcR   t    pip._internal.utils.marker_filesR   t   pip._internal.utils.miscR   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   t   pip._internal.utils.temp_dirR*   t   pip._internal.utils.typingR+   t   pip._internal.utils.uiR,   t   pip._internal.vcsR-   t   typingR.   R/   R0   R1   R2   R3   t   optparseR4   t   pip._internal.models.linkR5   t   pip._internal.utils.hashesR6   t    pip._internal.vcs.versioncontrolR7   R8   R|   t   Credentialst   __all__t	   getLoggerR   R   R   t   ImportErrorR   R   R   R   RN   RO   R   R   R   R   R   R   t   SessionR   R9   t   compilet   IR  R  R:   R;   R<   R=   R0  R?   R@   R;  R=  RW  Re  RA   R>   Rs  Rr  R   RB   RD   RC   Ri  Rh  (    (    (    s5   lib/python2.7/site-packages/pip/_internal/download.pyt   <module>   s   j.				
   		O	!BQ/												f	*2 *			?