
Rc            @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k	 Z	 d  d k
 Z
 d  d k Z d  d k Z d  d k l Z l Z l Z l Z l Z l Z l Z l Z d  d k l Z l Z d  d k l Z l Z l Z l Z l Z l Z l  Z  l! Z! l" Z" d  d k# l$ Z$ d  d k% l& Z& d  d k' l( Z( d d	 d
 d d d d d d d d d d g Z) d   Z* d d  Z, e i- d e i.  Z/ e i- d e i.  Z0 d e i1 f d     YZ2 d e i3 f d     YZ4 d e5 f d     YZ6 e6   Z7 d   Z8 d    Z9 e i- d! e i.  Z: e i- d" e i.  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 d/   ZI d d0  ZJ d1   ZK d2 e iL f d3     YZM d S(4   iN(   t   urllibt   urllib2t   httplibt   urlparset   string_typest   get_http_message_paramt   match_hostnamet   CertificateError(   t   InstallationErrort   HashMismatch(	   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   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  i   }  |  d j o t  i   } n |  d j o[ d t i i t i i t i i f } t i i d j o d i	 | t i i g  } q nA |  d j o t  i   } n$ |  d j o t  i   } n d } y t  i
   } t  i   } Wn t j
 o d } d } n Xd	 i	 d
 t i d |  | f d | | f g  S(   s,   Return a string representing the user agent.t   CPythont   PyPys   %s.%s.%st   finalt    t   Jythont
   IronPythont   Unknownt    s   pip/%ss   %s/%s(   t   platformt   python_implementationt   python_versiont   syst   pypy_version_infot   majort   minort   microt   releaselevelt   joint   systemt   releaset   IOErrort   pipt   __version__(   t   _implementationt   _implementation_versiont   p_systemt	   p_release(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   build_user_agent!   s.    	#c   
      C   s  t  i |   } | oM| i d  i   } | d j o1 | o* | i d  o t d | |  f   n | d j o |  i d d  d } | i d d  } t i	 |  } | o+ | i d  d | i d d  d } n t
 i |  } | i d  o d | i d  } n | }  qct |   } t | i d	 d
  } t |  | i   i |  f Sn y t |   } | i   } Wn9 t j
 o- t i   d }	 t d t |	    n X| i   |  | 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.i   t   filet   https6   Requirements file %s references URL %s, which is localt   :s   \t   /t   |t   charsets   utf-8s$   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   headersR   t   readt   decodet   openR7   R.   t   exc_infot   strt   close(
   t   urlt
   comes_fromRM   t   schemet   patht   respt   encodingt   ft   contentt   e(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   @   s:    +
#
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   sK  h  |  _  t |  d  o |  i  i d |  i  n t |  d  o |  i  i d |  i  n t i |  i |  i f |  i   } t	 |  d d   o | |  _ |  i   n t i i d d  p t } t i | |  i |  i d t i d | |  _ y t |  i i   |  i  Wn6 t j
 o* |  i i t i  |  i i     n Xd  S(   Nt   timeoutt   source_addresst   _tunnel_hostt   PIP_CERTR&   t	   cert_reqst   ca_certs(   t   connection_kwargst   hasattrt   updateRa   Rb   t   sockett   create_connectiont   hostt   portt   getattrt   Nonet   sockt   _tunnelt   ost   environt   getR   t   sslt   wrap_sockett   key_filet	   cert_filet   CERT_REQUIREDR   t   getpeercertR   t   shutdownt	   SHUT_RDWRRV   (   t   selfRp   t	   cert_path(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   connectl   s*    	!				(   t   __name__t
   __module__t   __doc__R   (    (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR`   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 i i |   d  S(   N(   t   specialized_conn_classR   t   HTTPSHandlert   __init__(   R}   t   connection_class(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      s    	c         C   s   |  i  |  i |  S(   N(   t   do_openR   (   R}   t   req(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt
   https_open   s    (   R   R   R   R`   R   R   (    (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      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  i   |  _ d  |  _ d  S(   N(   R   t   HTTPPasswordMgrWithDefaultRealmt   passmanRo   t   proxy_handler(   R}   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      s    c         C   s   |  i  |  \ } } } } | d j or y |  i d |  i |  } Wq t i j
 o= t i   d } | i d j o   n |  i	 |  } q Xn |  i	 | | |  } | 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.

        RY   i   i  N(
   t   extract_credentialsRo   t
   get_openerRS   R   t	   HTTPErrorR.   RT   t   codet   get_response(   R}   RW   t   usernamet   passwordRY   t   responseR_   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   __call__   s    c         C   s4   t  | t  o  t i | d h d d 6} n | S(   s   
        Wraps the URL to retrieve to protects against "creative"
        interpretation of the RFC: http://bugs.python.org/issue8732
        RP   t   identitys   Accept-encoding(   t
   isinstanceR   R   t   Request(   R}   RW   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   get_request   s     c         C   s  t  i |  \ } } } } } |  i |  }	 |  i i d |  \ }
 } |
 d j o | d j o? |  i o5 t i t	 d |   } t i t
 i
 d   } n | o$ | o |  i i d | | |  n |  i i d |  \ }
 } n t i |  i  } |  i | d | } | i |	  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: RY   N(   R   t   urlsplitR   R   t   find_user_passwordRo   t	   promptingR    t   quotet	   raw_inputt   getpasst   add_passwordR   t   HTTPBasicAuthHandlerR   RS   (   R}   RW   R   R   RY   t   netlocRZ   t   queryt   fragR   t   stored_usernamet   stored_passwordt   authhandlert   opener(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      s    c   	      O   s  t  |  } |  i o | i |  i t i g  n | i d  d j oZ t   } t i | |  } xK | i D]- } t	 | t i
  o | i i |  qn qn Wn t i |   } g  } | i D]( } | d i   d j o | | q q ~ } | i d t   f  | | _ | S(   sW   
        Build an OpenerDirector instance based on the scheme and proxy option
        RY   t   httpsi    s
   user-agents
   User-agent(   t   listR   t   extendR   t   CacheFTPHandlerRt   R   t   build_openert   handlersR   t   HTTPHandlert   removet
   addheadersRH   t   appendR>   (	   R}   t   argst   kwargst   https_handlert   directort   handlert   _[1]t   xRP   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      s    
	
 ?	R&   c         C   sN   | |  _  |  i |  } | o+ t i h | d 6| d 6| d 6 |  _ 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   (   R}   t   proxystrR   t   proxy(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   setup   s    	c         C   sP   d | j o? | i  d d  d } d | j o | i d d  S| d  f Sd S(   Nt   @i   i    RA   (   NN(   t   rsplitRJ   Ro   (   R}   R   t   userinfo(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   parse_credentials   s    c         C   s,  t  | t i  o t i | i    } n t i |  } | \ } } } } } |  i |  \ } }	 | d j o | d d | f S|	 d j oO |  i oE | i	 d | d d  } d | | f }
 t
 i t i |
   }	 n  | i	 d | |	 f d d  } t i | | | | | f  } | | |	 | f S(   s   
        Extracts user/password from a url.

        Returns a tuple:
            (url-without-auth, username, password)
        s   %s@R&   i   s   Password for %s@%s: s   %s:%s@N(   R   R   R   R   R   t   get_full_urlR   Ro   R   RK   R    R   R   t
   urlunsplit(   R}   RW   t   resultRY   R   RZ   R   R   R   R   t   promptt
   target_url(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR     s    c         C   s   | p t  i i d d  } n | o d | j o | i d d  \ } } d | j o | i d d  \ } } n/ | } d | | f } t i t i |   } 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_PROXYR&   R   i   RA   s   Password for %s@%s: s   %s:%s@%sN(   Rr   Rs   Rt   RJ   R    R   R   Ro   (   R}   R   t   user_passwordt   server_portt   userR   R   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   #  s    N(   R   R   R   R   R   R   Ro   R   R   t   TrueR   R   R   R   (    (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      s   							c         C   sK   d |  j o t  S|  i d d  d i   } | d d d d g t i j S(   s)   Returns true if the name looks like a URLRA   i   i    R@   R   R?   R   (   t   FalseRJ   RH   R   t   all_schemes(   t   nameRY   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   =  s    c         C   s~   |  i  d  p t d |   |  t d  i d  } t i |  } t i |  o | 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)RB   i    RA   i   (   RI   t   AssertionErrort   lenRO   R    RN   t   _url_drive_reRM   (   RW   RZ   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   E  s    
s	   ^([a-z]):s   ^([a-z])[:|]c         C   s   t  i i t  i i |    }  t i |   o |  d d |  d }  n t i |   } | i t  i i	 d  } | i
 d  } d | S(   sI   
    Convert a path to a file: URL.  The path will be made absolute.
    i    RC   i   RB   s   file:///(   Rr   RZ   t   normcaset   abspatht	   _drive_reRM   R    R   RK   t   sepRO   (   RZ   RW   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   X  s    c         C   s   t  i i t  i i |    }  t  i i |   \ } }  |  i t  i i  } d i g  } | D] } | t i	 |  q\ ~  } | p | i
 d  } n d | | S(   sh   
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    RB   s   file:///(   Rr   RZ   t   normpathR   t
   splitdriveRJ   R   R4   R    R   RO   (   RZ   t   drivet   filepathR   t   partRW   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   e  s    3c         C   sK   |  i    } | i d d  \ } } | i d  o | Sd | | 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
    RA   i   s   //s   %s://%sN(   R   RJ   RI   (   t   urllib2_respRW   RY   t   rest(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR   s  s
    c         C   s2   d	 } t  |   d i   } | | j o t St S(
   s9   Return True if `name` is a considered as an archive file.s   .zips   .tar.gzs   .tar.bz2s   .tgzs   .tars	   .pybundles   .whli   (   s   .zips   .tar.gzs   .tar.bz2s   .tgzs   .tars	   .pybundles   .whl(   R
   RH   R   R   (   R   t   archivest   ext(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR     s     c         C   s5   t  |   } | o | i |  n | i |  d  S(   N(   t   _get_used_vcs_backendt   exportt   unpack(   t   linkt   locationt   only_downloadt   vcs_backend(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR     s    c         C   s   t  |  i  } t i |  d } t i i |  o5 t i i |  o t |  n t i	 | |  n t
 | | | |   d  S(   Ni    (   R   RW   t	   mimetypest
   guess_typeRr   RZ   t   isdirR   t   shutilt   copytreeR   (   R   R   t   sourcet   content_type(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR     s    c         C   s?   x8 t  i D]- } |  i | i j o | |  i  } | Sq
 Wd  S(   N(   R   t   backendsRY   t   schemesRW   (   R   t   backendR   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR     s
    
 c         C   s   t  t |    S(   N(   t   boolR   (   R   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR      s    c         C   s   |  i  i   i d  S(   Ns   file:(   RW   RH   RI   (   R   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR!     s    c         C   s   |  i  t i | i  i  j o4 t i d |  i  | | i f  t d |   n |  i   | i j o@ t i d | |  i   | i f  t d | i | 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   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   _check_hash  s    		c         C   s   y t  i | i  } Wn4 t t f j
 o" t i d | i | f  d  SXt |  d  } x4 t	 o, | i
 d  } | p Pn | i |  q_ W| i   | S(   Ns'   Unsupported hash name %s for package %st   rbi   (   R   R   R   t
   ValueErrort	   TypeErrorR   t   warnRo   RS   R   RQ   Ri   RV   (   t   target_fileR   R   t   fpt   chunk(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   _get_hash_from_file  s     
c   
      C   s*  t  | d  } d  } | i oT | i oJ y t i | i  } Wqs t j
 o! t i d | i | f  qs Xn y t	 |  i
   d  } Wn" t t t f j
 o d } n Xd } | d j p | } | i } z+| o= | o! t i d | t |  f  q-t i d |  n t i d	 |  t i
 d
 |  x t o |  i d  }	 |	 p Pn | t |	  7} | oK | p t i d t |   qt i d d | | t |  f  n | d  j	 o | i |	  n | i |	  qAW| i   Wd  | o t i 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@  (   RS   Ro   R   R   R   R   R   R   R  t   intt   infot   KeyErrorR   t   show_urlt   start_progressR   t   notifyR   RQ   R   t   show_progressRi   t   writeRV   t   end_progress(
   R[   R   t   temp_locationR  R   t   total_lengtht
   downloadedR  R
  R  (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   _download_url  sL    #	! )c         C   s/  t  } t i i | | i  } t i i |  o t d t |  d	  } | d j o
 t } q | d j o( t	 i
 d t |   t i |  q | d j oC t |  } t	 i
 d t |  t |  f  t i | |  q n | o: t i |  |  t	 i d 8_ t	 i 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   Rr   RZ   R4   t   filenamet   existsR   R   R   R   R  R   R   R   t   movet   copyt   indentR  (   R  R   R   R   R  t   download_locationR   t	   dest_file(    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt
   _copy_file  s(    
	c         C   s  t  i d d  } d  } |  i i d d  d } t } d  } d  }	 d  }
 | ou t i i | t	 i
 | d   } | d }	 t i i |  o t i i |	  } t i i |  p t |  q n d  } | o9 t i i | |  i  } t i i |  p
 d  } qn | o | } t i |  d } t i d |  |  i od t | |   }
 y t |
 |   Wqt j
 o1 t i d	 |  d  } t i |  d  } qXqn | o | o t |	  i i   } z | ~ } | i   i   } Wd  QX| } t i d
 |  |  i o{ |  i oq t | |   }
 y t |
 |   Wqt j
 o> t i d |  d  } t i |  t i |	  t } qXqn | p]t | |   } | i    i! d d  } |  i } | i    i! d  } | o/ t" i# |  \ } } | i! d  p | } n t$ |  d } | p( t i% |  } | o | | 7} qYn | oK |  i t& |  j o5 t i i$ t& |   d } | o | | 7} qn t i i | |  } t' | |  |  }
 |  i o |  i o t |
 |   qn | o | o t( | | | |   n t) | | | |   | o | o t* | | |  n | p | p t i |  n t i+ |  d  S(   Ns   -unpacks   pip-t   #i   i    R&   s   .content-types   File was already downloaded %ss;   Previously-downloaded file %s has bad hash, re-downloading.s   Using download cache from %ss,   Cached file %s has bad hash, re-downloading.s   content-types   content-dispositionR  (,   t   tempfilet   mkdtempRo   RW   RJ   R   Rr   RZ   R4   R    R   R  R   R   R  R   R   R   R  R   R  R   R	   R  t   unlinkRS   t   __exit__t	   __enter__RQ   t   stripR   t   _get_response_from_urlR  Rt   t   cgit   parse_headerR
   t   guess_extensionR   R  R  R   R   t   rmdir(   R   R   t   download_cachet   download_dirt   temp_dirR  R   t   already_cachedt
   cache_filet   cache_content_type_fileR   t   already_downloadedR   R   R  R[   R  t   content_dispositiont   typet   paramsR   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR"     s    

#	c         C   s   y t  |   } Wn t i j
 o4 t i   d } t i d | i | f    n> t j
 o1 t i   d } t i d | | f    n X| S(   Ni   s   HTTP error %s while getting %ss   Error %s while getting %s(	   R   R   R   R.   RT   R   R   R   R7   (   R   R   R[   R_   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR&  |  s    t   Urllib2HeadRequestc           B   s   e  Z d    Z RS(   c         C   s   d S(   Nt   HEAD(    (   R}   (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt
   get_method  s    (   R   R   R7  (    (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyR5    s   (N   R'  R   R   R   Rr   R+   t   reR   Rj   Ru   R.   R   R8   t   pip.backwardcompatR    R   R   R   R   R   R   R   t   pip.exceptionsR   R	   t   pip.utilR
   R   R   R   R   R   R   R   R   t   pip.vcsR   t   pip.logR   t   pip.locationsR   t   __all__R>   Ro   R   t   compilet   IRE   RL   t   HTTPSConnectionR`   R   R   t   objectR   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R   R  R  R  R"   R&  R   R5  (    (    (    sH   /var/www/html/kasc-wg8/erics/lib/python2.6/site-packages/pip/download.pyt   <module>   sd   :@		%+							
							.	c	