
_Tc           @   s  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
 m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l  m! Z! d d d	 d
 d d d d d d d d d d g Z" e j#   Z$ d d  Z& e j' d e j(  Z) e j' d e j(  Z* d e+ f d     YZ, e,   Z- d   Z. d   Z/ e j' d e j(  Z0 e j' d e j(  Z1 d   Z2 d   Z3 d    Z4 d!   Z5 e6 d"  Z7 d#   Z8 d$   Z9 d%   Z: d&   Z; d'   Z< d(   Z= d)   Z> d*   Z? d d+  Z@ d,   ZA d- e jB f d.     YZC d S(/   iN(   t   md5t   copytreet	   xmlrpclibt   urllibt   urllib2t   urlparset   string_typest	   HTTPError(   t   InstallationError(
   t   splitextt   rmtreet   format_sizet   display_patht
   backup_dirt   askt   ask_path_existst   unpack_filet   create_download_cache_foldert   cache_download(   t   vcs(   t   loggert   xmlrpclib_transportt   get_file_contentt   urlopent   is_urlt   url_to_patht   path_to_urlt   path_to_url2t   geturlt   is_archive_filet   unpack_vcs_linkt   unpack_file_urlt
   is_vcs_urlt   is_file_urlt   unpack_http_urlc   	      C   s  t  j |   } | r9| j d  j   } | d k rd | rd | j d  rd 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  | }  q9t |   } t |  | j   f Sn  y t |   } | j   } Wn7 t k
 rt j   d } t d	 t |    n X| j   |  | f S(
   sk   Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content)i   t   filet   https6   Requirements file %s references URL %s, which is localt   :s   \t   /t   |s$   Could not open requirements file: %s(   t
   _scheme_ret   searcht   groupt   lowert
   startswithR   t   splitt   replacet   _url_slash_drive_ret   matchR   t   unquotet   lstripR   R   t   readt   opent   IOErrort   syst   exc_infot   strt   close(	   t   urlt
   comes_fromR0   t   schemet   patht   respt   ft   contentt   e(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR      s8    *	
s   ^(http|https|file):s   /*([a-z])\|t	   URLOpenerc           B   se   e  Z d  Z d   Z d   Z d   Z d
 d
 d  Z d e d  Z	 d   Z
 d   Z d d	  Z RS(   sD   
    pip's own URL helper that adds HTTP auth and proxy support
    c         C   s   t  j   |  _ d  S(   N(   R   t   HTTPPasswordMgrWithDefaultRealmt   passman(   t   self(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   __init__H   s    c         C   s   |  j  |  \ } } } | d k r y t j |  j |   } Wq t j k
 r t j   d } | j d k rx   n  |  j	 |  } q Xn |  j	 | | |  } | S(   s   
        If the given url contains auth info or if a normal request gets a 401
        response, an attempt is made to fetch the resource using basic HTTP
        auth.

        i   i  N(
   t   extract_credentialst   NoneR   R   t   get_requestR   R6   R7   t   codet   get_response(   RE   R:   t   usernamet   passwordt   responseRA   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   __call__K   s    c         C   s2   t  | t  r. t j | d i d d 6} n  | S(   s   
        Wraps the URL to retrieve to protects against "creative"
        interpretation of the RFC: http://bugs.python.org/issue8732
        t   headerst   identitys   Accept-encoding(   t
   isinstanceR   R   t   Request(   RE   R:   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyRI   _   s    c         C   s  t  j |  \ } } } } } |  j |  }	 |  j j d |  \ }
 } |
 d k r | d k r |  j r t j t	 d |   } t j t
 j
 d   } n  | r | r |  j j d | | |  n  |  j j d |  \ }
 } n  t j |  j  } t j |  } | j |	  S(   s~   
        does the dirty work of actually getting the rsponse object using urllib2
        and its HTTP auth builtins.
        s   User for %s: s
   Password: N(   R   t   urlsplitRI   RD   t   find_user_passwordRH   t	   promptingR   t   quotet	   raw_inputt   getpasst   add_passwordR   t   HTTPBasicAuthHandlert   build_openerR4   (   RE   R:   RL   RM   R<   t   netlocR=   t   queryt   fragt   reqt   stored_usernamet   stored_passwordt   authhandlert   opener(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyRK   h   s    t    c         C   sk   | |  _  |  j |  } | rg t j i | d 6| d 6| d 6 } t j | t j  } t j |  n  d S(   s   
        Sets the proxy handler given the option passed on the command
        line.  If an empty string is passed it looks at the HTTP_PROXY
        environment variable.
        R$   t   ftpt   httpsN(   RV   t	   get_proxyR   t   ProxyHandlerR\   t   CacheFTPHandlert   install_opener(   RE   t   proxystrRV   t   proxyt   proxy_supportRd   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   setup~   s    	$c         C   sL   d | k rH | j  d d  d } d | k r> | j d d  S| d  f Sd S(   Nt   @i   i    R%   (   NN(   t   rsplitR-   RH   (   RE   R]   t   userinfo(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   parse_credentials   s    
c         C   s  t  | t j  r* t j | j    } n t j |  } | \ } } } } } |  j |  \ } }	 | d k r| | d d f S|	 d k r |  j r | j	 d | d d  } d | | f }
 t
 j t j |
   }	 n | j	 d | |	 f d d  } t j | | | | | f  } | | |	 f S(   s   
        Extracts user/password from a url.

        Returns a tuple:
            (url-without-auth, username, password)
        s   %s@Re   i   s   Password for %s@%s: s   %s:%s@N(   RR   R   RS   R   RT   t   get_full_urlRs   RH   RV   R.   R   RW   RY   t
   urlunsplit(   RE   R:   t   resultR<   R]   R=   R^   R_   RL   RM   t   promptt
   target_url(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyRG      s    c         C   s   | s t  j j d d  } n  | r d | k r | j d d  \ } } d | k ro | j d d  \ } } n. | } d | | f } t j t j |   } d | | | f S| Sn d Sd S(	   s   
        Get the proxy given the option passed on the command line.
        If an empty string is passed it looks at the HTTP_PROXY
        environment variable.
        t
   HTTP_PROXYRe   Rp   i   R%   s   Password for %s@%s: s   %s:%s@%sN(   t   ost   environt   getR-   R   RW   RY   RH   (   RE   Rl   t   user_passwordt   server_portt   userRM   Rw   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyRh      s    N(   t   __name__t
   __module__t   __doc__RF   RO   RI   RH   RK   t   TrueRo   Rs   RG   Rh   (    (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyRB   D   s   						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 URLR%   i   i    R$   Rg   R#   Rf   (   t   FalseR-   R+   R   t   all_schemes(   t   nameR<   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR      s    c         C   s}   |  j  d  s t d |    |  t d  j d  } t j |  } t j |  ro | d d | d } n
 d | } | S(   s(   
    Convert a file: URL to a path.
    s   file:s4   You can only turn file: urls into filenames (not %r)R&   i    R%   i   (   R,   t   AssertionErrort   lenR2   R   R1   t   _url_drive_reR0   (   R:   R=   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR      s    
s	   ^([a-z]):s   ^([a-z])[:|]c         C   s   t  j j t  j j |    }  t j |   rF |  d d |  d }  n  t j |   } | j t  j j	 d  } | j
 d  } d | S(   sI   
    Convert a path to a file: URL.  The path will be made absolute.
    i    R'   i   R&   s   file:///(   Rz   R=   t   normcaset   abspatht	   _drive_reR0   R   RW   R.   t   sepR2   (   R=   R:   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR      s    c         C   s   t  j j t  j j |    }  t  j j |   \ } }  |  j t  j j  } d j g  | D] } t j	 |  ^ qX  } | s | j
 d  } n  d | | S(   sh   
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    R&   s   file:///(   Rz   R=   t   normpathR   t
   splitdriveR-   R   t   joinR   RW   R2   (   R=   t   drivet   filepatht   partR:   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR      s    +c         C   sI   |  j    } | j d d  \ } } | j d  r7 | Sd | | f Sd S(   s6  
    Use instead of urllib.addinfourl.geturl(), which appears to have
    some issues with dropping the double slash for certain schemes
    (e.g. file://).  This implementation is probably over-eager, as it
    always restores '://' if it is missing, and it appears some url
    schemata aren't always followed by '//' after the colon, but as
    far as I know pip doesn't need any of those.
    The URI RFC can be found at: http://tools.ietf.org/html/rfc1630

    This function assumes that
        scheme:/foo/bar
    is the same as
        scheme:///foo/bar
    R%   i   s   //s   %s://%sN(   R   R-   R,   (   t   urllib2_respR:   R<   t   rest(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR      s
    c         C   s0   d } t  |   d j   } | | k r, t St S(	   s9   Return True if `name` is a considered as an archive file.s   .zips   .tar.gzs   .tar.bz2s   .tgzs   .tars	   .pybundlei   (   s   .zips   .tar.gzs   .tar.bz2s   .tgzs   .tars	   .pybundle(   R	   R+   R   R   (   R   t   archivest   ext(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR     s
    c         C   s3   t  |   } | r" | j |  n | j |  d  S(   N(   t   _get_used_vcs_backendt   exportt   unpack(   t   linkt   locationt   only_downloadt   vcs_backend(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR   !  s    c         C   sz   t  |  j  } t j |  d } t j j |  rc t j j |  rS t |  n  t | |  n t	 | | | |   d  S(   Ni    (
   R   R:   t	   mimetypest
   guess_typeRz   R=   t   isdirR
   R   R   (   R   R   t   sourcet   content_type(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR   )  s    c         C   s=   x6 t  j D]+ } |  j | j k r
 | |  j  } | Sq
 Wd  S(   N(   R   t   backendsR<   t   schemesR:   (   R   t   backendR   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR   5  s    c         C   s   t  t |    S(   N(   t   boolR   (   R   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR    <  s    c         C   s   |  j  j   j d  S(   Ns   file:(   R:   R+   R,   (   R   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR!   @  s    c         C   sO   |  j    }  |  | j k rK t j d | |  | j f  t d |   n  d  S(   NsC   MD5 hash of the package %s (%s) doesn't match the expected hash %s!s   Bad MD5 hash for package %s(   t	   hexdigestt   md5_hashR   t   fatalR   (   t   download_hashR   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt
   _check_md5D  s
    	c         C   sY   t    } t |  d  } x0 t rJ | j d  } | s: Pn  | j |  q W| j   | S(   Nt   rbi   (   R    R4   R   R3   t   updateR9   (   t   target_fileR   R   t   fpt   chunk(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   _get_md5_from_fileL  s    		
c   
      C   s  t  | d  } d  } | j r* t   } n  y t |  j   d  } Wn  t t t f k
 rf d } n Xd } | d k p} | } | j	 } z| r | r t
 j d | t |  f  q t
 j d |  n t
 j d |  t
 j d	 |  x t r|  j d
  }	 |	 sPn  | t |	  7} | rn| sFt
 j d t |   qnt
 j d d | | t |  f  n  | j r| j |	  n  | j |	  q W| j   Wd  | rt
 j d t |   n  X| S(   Nt   wbs   content-lengthi    i(   i  s   Downloading %s (%s): s   Downloading %s (unknown size): s   Downloading %ss   Downloading from URL %si   s   %ss	   %3i%%  %sid   s   %s downloadedi@  (   R4   RH   R   R    t   intt   infot
   ValueErrort   KeyErrort	   TypeErrort   show_urlR   t   start_progressR   t   notifyt   debugR   R3   R   t   show_progressR   t   writeR9   t   end_progress(
   R>   R   t   temp_locationR   R   t   total_lengtht
   downloadedR   R   R   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   _download_urlX  sD    	
	 	(	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 |  f  t j | |  q n  | r!t j |  |  t	 j d 8_ t	 j d t |   n  d  S(
   Ns/   The file %s exists. (i)gnore, (w)ipe, (b)ackup t   it   wt   bs   Deleting %ss   Backing up %s to %si   s   Saved %s(   R   R   R   (   R   Rz   R=   R   t   filenamet   existsR   R   R   R   t   warnt   removeR   t   shutilt   movet   copyt   indentR   (   R   R   R   R   R   t   download_locationRN   t	   dest_file(    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt
   _copy_file  s(    		c      	   C   s  t  j d d  } |  j j d d  d } d  } d  } | r t j j | t j	 | d   } t j j
 |  s t |  q n  | rt j j |  rt j j | d  rt | d  } | j   j   }	 | j   |  j r t | |   } n  | }
 t j d |  n t | |   } | j   d	 }	 |  j } | j   j d
  } | rt j |  \ } } | j d  py| } n  t |  d } | st j |	  } | r| | 7} qn  | r|  j t |  k rt j j t |   d } | r| | 7} qn  t j j | |  }
 t | |  |
  } |  j rHt  | |   n  | rdt! |
 | |	 |   n  t" |
 | |	 |   | r| |
 k rt# | |
 |	  n  | d  k rt j$ |
  n  t j% |  d  S(   Ns   -unpacks   pip-t   #i   i    Re   s   .content-types   Using download cache from %ss   content-types   content-dispositionR   (&   t   tempfilet   mkdtempR:   R-   RH   Rz   R=   R   R   RW   R   R   R   R4   R3   t   stripR9   R   R   R   R   t   _get_response_from_urlR   R   R|   t   cgit   parse_headerR	   R   t   guess_extensionR   R   R   R   R   R   t   unlinkt   rmdir(   R   R   t   download_cachet   download_dirt   temp_dirRx   R   R   R   R   R   R>   R   t   content_dispositiont   typet   paramsR   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR"     s^    
			c         C   s   y t  |   } Wn{ t j k
 rS t j   d } t j d | j | f    n; t k
 r t j   d } t j d | | f    n X| S(   Ni   s   HTTP error %s while getting %ss   Error %s while getting %s(	   R   R   R   R6   R7   R   R   RJ   R5   (   Rx   R   R>   RA   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR     s    t   Urllib2HeadRequestc           B   s   e  Z d    Z RS(   c         C   s   d S(   Nt   HEAD(    (   RE   (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt
   get_method  s    (   R   R   R   (    (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyR     s   (D   R   RY   R   Rz   t   reR   R6   R   t   pip.backwardcompatR    R   R   R   R   R   R   R   t   pip.exceptionsR   t   pip.utilR	   R
   R   R   R   R   R   R   R   R   t   pip.vcsR   t   pip.logR   t   __all__t	   TransportR   RH   R   t   compilet   IR(   R/   t   objectRB   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R   R   R   R   R"   R   RS   R   (    (    (    sd   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.pyt   <module>   sT   :F		$															+	6	