[Python-checkins] CVS: python/dist/src/Lib urllib.py,1.98,1.99

Fred L. Drake python-dev@python.org
Mon, 21 Aug 2000 14:42:46 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv15482

Modified Files:
	urllib.py 
Log Message:
Patch from Paul Schreiber <paul@commerceflow.com>: 

Patch description 
----------------- 
This addresses four issues: 

(1) usernames and passwords in urls with special characters are now
    decoded properly. i.e. http://foo%2C:bar@www.whatever.com/

(2) Basic Auth support has been added to HTTPS, like it was in HTTP. 

(3) Version 1.92 sent the POSTed data, but did not deal with errors 
    (HTTP responses other than 200) properly. HTTPS now behaves the
    same way HTTP does.

(4) made URL-checking beahve the same way with HTTPS as it does with 
    HTTP (changed == to !=).


Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.98
retrieving revision 1.99
diff -C2 -r1.98 -r1.99
*** urllib.py	2000/07/26 07:04:38	1.98
--- urllib.py	2000/08/21 21:42:42	1.99
***************
*** 303,315 ****
              """Use HTTPS protocol."""
              import httplib
              if type(url) is type(""):
                  host, selector = splithost(url)
!                 user_passwd, host = splituser(host)
              else:
                  host, selector = url
                  urltype, rest = splittype(selector)
!                 if string.lower(urltype) == 'https':
                      realhost, rest = splithost(rest)
!                     user_passwd, realhost = splituser(realhost)
                      if user_passwd:
                          selector = "%s://%s%s" % (urltype, realhost, rest)
--- 303,324 ----
              """Use HTTPS protocol."""
              import httplib
+             user_passwd = None
              if type(url) is type(""):
                  host, selector = splithost(url)
!                 if host:
!                     user_passwd, host = splituser(host)
!                     host = unquote(host)
!                 realhost = host
              else:
                  host, selector = url
                  urltype, rest = splittype(selector)
!                 url = rest
!                 user_passwd = None
!                 if string.lower(urltype) != 'https':
!                     realhost = None
!                 else:
                      realhost, rest = splithost(rest)
!                     if realhost:
!                         user_passwd, realhost = splituser(realhost)
                      if user_passwd:
                          selector = "%s://%s%s" % (urltype, realhost, rest)
***************
*** 332,335 ****
--- 341,345 ----
                  h.putrequest('GET', selector)
              if auth: h.putheader('Authorization: Basic %s' % auth)
+             if realhost: h.putheader('Host', realhost)
              for args in self.addheaders: apply(h.putheader, args)
              h.endheaders()
***************
*** 341,346 ****
                  return addinfourl(fp, headers, url)
              else:
!                 return self.http_error(url, fp, errcode, errmsg, headers)
!   
      def open_gopher(self, url):
          """Use Gopher protocol."""
--- 351,359 ----
                  return addinfourl(fp, headers, url)
              else:
!                 if data is None:
!                     return self.http_error(url, fp, errcode, errmsg, headers)
!                 else:
!                     return self.http_error(url, fp, errcode, errmsg, headers, data)
! 
      def open_gopher(self, url):
          """Use Gopher protocol."""
***************
*** 873,877 ****
  
      match = _userprog.match(host)
!     if match: return match.group(1, 2)
      return None, host
  
--- 886,890 ----
  
      match = _userprog.match(host)
!     if match: return map(unquote, match.group(1, 2))
      return None, host