

\c           @   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 Z d  d l	 Z	 d  d l
 m Z m Z m Z m Z m Z m Z m Z e r d  d l
 m Z m Z n  d  d l m Z m Z m Z d  d l 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 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.  Z0 d e j1 f d     YZ2 d e j3 f d     YZ4 d e5 f d     YZ6 e6   Z7 d    Z8 d!   Z9 e j- d" e j.  Z: e j- d# e j.  Z; d$   Z< d%   Z= d&   Z> d'   Z? e@ d(  ZA d)   ZB d*   ZC d+   ZD d,   ZE d-   ZF d.   ZG d/   ZH d0   ZI d d1  ZJ d2   ZK d3 e jL f d4     YZM d S(5   iN(   t	   xmlrpclibt   urllibt   urllib2t   httplibt   urlparset   string_typest   ssl(   t   match_hostnamet   CertificateError(   t   InstallationErrort   PipErrort
   NoSSLError(	   t   splitextt   rmtreet   format_sizet   display_patht
   backup_dirt   ask_path_existst   unpack_filet   create_download_cache_foldert   cache_download(   t   vcs(   t   logger(   t   default_cert_patht   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_fromR3   t   schemet   patht   respt   ft   contentt   e(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR   !   s8    *	
s   ^(http|https|file):s   /*([a-z])\|t   VerifiedHTTPSConnectionc           B   s   e  Z d  Z d   Z RS(   sP   
    A connection that wraps connections with ssl certificate verification.
    c      	   C   sB  i  |  _  t |  d  r1 |  j  j d |  j  n  t |  d  rY |  j  j d |  j  n  t j |  j |  j f |  j   } t	 |  d d   r | |  _ |  j   n  t j j d d  p t } t j | |  j |  j d t j d | |  _ y t |  j j   |  j  Wn4 t k
 r=|  j j t j  |  j j     n Xd  S(   Nt   timeoutt   source_addresst   _tunnel_hostt   PIP_CERTt    t	   cert_reqst   ca_certs(   t   connection_kwargst   hasattrt   updateRF   RG   t   sockett   create_connectiont   hostt   portt   getattrt   Nonet   sockt   _tunnelt   ost   environt   getR   R   t   wrap_sockett   key_filet	   cert_filet   CERT_REQUIREDR   t   getpeercertR   t   shutdownt	   SHUT_RDWRR<   (   t   selfRV   t	   cert_path(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   connectL   s*    	!				(   t   __name__t
   __module__t   __doc__Rd   (    (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRE   H   s   t   VerifiedHTTPSHandlerc           B   s#   e  Z d  Z e d  Z d   Z RS(   sC   
    A HTTPSHandler that uses our own VerifiedHTTPSConnection.
    c         C   s   | |  _  t j j |   d  S(   N(   t   specialized_conn_classR   t   HTTPSHandlert   __init__(   Rb   t   connection_class(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRk   w   s    	c         C   s   |  j  |  j |  S(   N(   t   do_openRi   (   Rb   t   req(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt
   https_openz   s    (   Re   Rf   Rg   RE   Rk   Ro   (    (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRh   s   s   t	   URLOpenerc           B   sn   e  Z d  Z d   Z d   Z d   Z d d d  Z 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(   Rb   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRk      s    c         C   s   |  j  |  \ } } } } | d k r y |  j d |  j |  } Wq t j k
 r t j   d } | j d k r~   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.

        R?   i   i  N(
   t   extract_credentialsRU   t
   get_openerR7   R   t	   HTTPErrorR9   R:   t   codet   get_response(   Rb   R=   t   usernamet   passwordR?   t   responseRD   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   __call__   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(   Rb   R=   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   get_request   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  } |  j | d | } | 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: R?   N(   R   t   urlsplitR   Rr   t   find_user_passwordRU   t	   promptingR   t   quotet	   raw_inputt   getpasst   add_passwordR   t   HTTPBasicAuthHandlerRt   R7   (   Rb   R=   Rx   Ry   R?   t   netlocR@   t   queryt   fragRn   t   stored_usernamet   stored_passwordt   authhandlert   opener(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRw      s    c         O   s   | j  d  d k r t rs t   } t j | |  } x6 | j D]+ } t | t j  r@ | j j |  q@ q@ W| St	 j
 j  d d  d k r t j |   St    n t j |   Sd S(   s   
        Build an OpenerDirector instance based on the scheme, whether ssl is
        importable and the --insecure parameter.
        R?   t   httpst   PIP_INSECURERJ   t   1N(   RZ   R   Rh   R   t   build_openert   handlersR~   t   HTTPHandlert   removeRX   RY   R   (   Rb   t   argst   kwargst   https_handlert   directort   handler(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRt      s    	RJ   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   ftpR   N(   R   t	   get_proxyR   t   ProxyHandlerR   t   CacheFTPHandlert   install_opener(   Rb   t   proxystrR   t   proxyt   proxy_supportR   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-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   rsplitR0   RU   (   Rb   R   t   userinfo(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-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@RJ   i   s   Password for %s@%s: s   %s:%s@N(   R~   R   R   R   R   t   get_full_urlR   RU   R   R1   R   R   R   t
   urlunsplit(   Rb   R=   t   resultR?   R   R@   R   R   Rx   Ry   t   promptt
   target_url(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRs      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_PROXYRJ   R   i   R(   s   Password for %s@%s: s   %s:%s@%sN(   RX   RY   RZ   R0   R   R   R   RU   (   Rb   R   t   user_passwordt   server_portt   userRy   R   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR      s    N(   Re   Rf   Rg   Rk   R{   R   RU   Rw   Rt   t   TrueR   R   Rs   R   (    (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyRp   ~   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'   R   R&   R   (   t   FalseR0   R.   R   t   all_schemes(   t   nameR?   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-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   lenR5   R   R4   t   _url_drive_reR3   (   R=   R@   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-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:///(   RX   R@   t   normcaset   abspatht	   _drive_reR3   R   R   R1   t   sepR5   (   R@   R=   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR   4  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:///(   RX   R@   t   normpathR   t
   splitdriveR0   R   t   joinR   R   R5   (   R@   t   drivet   filepatht   partR=   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR   A  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   R0   R/   (   t   urllib2_respR=   R?   t   rest(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR   O  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(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR    g  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(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR!   p  s    c         C   s}   t  |  j  } t j |  d } t j j |  rf t j j |  rS t |  n  t j	 | |  n t
 | | | |   d  S(   Ni    (   R   R=   t	   mimetypest
   guess_typeRX   R@   t   isdirR   t   shutilt   copytreeR   (   R   R   t   sourcet   content_type(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR"   x  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   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR     s    c         C   s   t  t |    S(   N(   t   boolR   (   R   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR#     s    c         C   s   |  j  j   j d  S(   Ns   file:(   R=   R.   R/   (   R   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR$     s    c         C   s   |  j  t j | j  j  k rQ t j d |  j  | | j f  t d |   n  |  j   | j k r t j d | |  | j f  t d | j | f   n  d  S(   NsP   Hash digest size of the package %d (%s) doesn't match the expected hash name %s!s!   Hash name mismatch for package %ss?   Hash of the package %s (%s) doesn't match the expected hash %s!s   Bad %s hash for package %s(	   t   digest_sizet   hashlibt   newt	   hash_nameR   t   fatalR	   t	   hexdigestt   hash(   t   download_hashR   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   _check_hash  s    		c         C   s   y t  j | j  } Wn2 t t f k
 rJ t j d | j | f  d  SXt |  d  } x0 t	 r | j
 d  } | s| Pn  | j |  q] W| j   | S(   Ns'   Unsupported hash name %s for package %st   rbi   (   R   R   R   t
   ValueErrort	   TypeErrorR   t   warnRU   R7   R   R6   RO   R<   (   t   target_fileR   R   t   fpt   chunk(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   _get_hash_from_file  s    	
c   
   	   C   s  t  | d  } d  } | j rn | j rn y t j | j  } Wqn t k
 rj t j d | j | f  qn Xn  y t	 |  j
   d  } Wn  t t t f k
 r 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  }	 |	 sTPn  | t |	  7} | r| st j d t |   qt j d d | | t |  f  n  | d  k	 r| j |	  n  | j |	  q5W| j   Wd  | rt j d t |   n  X| S(   Nt   wbs'   Unsupported hash name %s for package %ss   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@  (   R7   RU   R   R   R   R   R   R   R   t   intt   infot   KeyErrorR   t   show_urlt   start_progressR   t   notifyR   R6   R   t   show_progressRO   t   writeR<   t   end_progress(
   RA   R   t   temp_locationR   R   t   total_lengtht
   downloadedR   R   R   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   _download_url  sJ    !
	 	(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   RX   R@   R   t   filenamet   existsR   R   R   R   R   R   R   R   t   movet   copyt   indentR   (   R   R   R   R   R   t   download_locationRz   t	   dest_file(    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt
   _copy_file  s(    		c         C   su  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  d  } | r t j j | |  j  } t j j |  s d  } q n  | rZt j j |  rZt j j | d  rZt | d  }	 |	 j   j   }
 |	 j   |  j r@|  j r@t | |   } n  | } t j d |  nj| r| } t j |  }
 |  j rt | |   } n  t j d	 |  n t | |   } | j   d
 }
 |  j } | j   j d  } | rt j |  \ } } | j d  p| } n  t |  d } | sOt j |
  } | rO| | 7} qOn  | r|  j t  |  k rt j j t  |   d } | r| | 7} qn  t j j | |  } t! | |  |  } |  j r|  j rt" | |   n  | r	| r	t# | | |
 |   n  t$ | | |
 |   | rA| | k rAt% | | |
  n  | d  k rd| rdt j& |  n  t j' |  d  S(   Ns   -unpacks   pip-t   #i   i    RJ   s   .content-types   Using download cache from %ss   File was already downloaded %ss   content-types   content-dispositionR   ((   t   tempfilet   mkdtempR=   R0   RU   RX   R@   R   R   R   R   R   R   R   R7   R6   t   stripR<   R   R   R   R   R   R   R   t   _get_response_from_urlR   RZ   t   cgit   parse_headerR   t   guess_extensionR   R   R   R  R   R   t   unlinkt   rmdir(   R   R   t   download_cachet   download_dirt   temp_dirR   R   R   t   already_downloadedR   R   R   RA   R   t   content_dispositiont   typet   paramsR   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR%     st    
		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   Ru   R9   R:   R   R   Rv   R8   (   R   R   RA   RD   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR  7  s    t   Urllib2HeadRequestc           B   s   e  Z d    Z RS(   c         C   s   d S(   Nt   HEAD(    (   Rb   (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt
   get_methodG  s    (   Re   Rf   R  (    (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyR  F  s   (N   R  R   R   R   RX   t   reR   RP   R9   R  t   pip.backwardcompatR    R   R   R   R   R   R   R   R   t   pip.exceptionsR	   R
   R   t   pip.utilR   R   R   R   R   R   R   R   R   t   pip.vcsR   t   pip.logR   t   pip.locationsR   t   __all__t	   TransportR   RU   R   t   compilet   IR+   R2   t   HTTPSConnectionRE   Rj   Rh   t   objectRp   R   R   R   R   R   R   R   R   R    R   R!   R"   R   R#   R$   R   R   R   R  R%   R  R   R  (    (    (    sS   /data/av2000/b2b/venv/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/download.pyt   <module>   sb   4@		$+															.	C	