[Python-checkins] r52481 - python/trunk/Lib/urllib.py python/trunk/Lib/urllib2.py

andrew.kuchling python-checkins at python.org
Fri Oct 27 19:11:23 CEST 2006


Author: andrew.kuchling
Date: Fri Oct 27 19:11:23 2006
New Revision: 52481
Modified:
 python/trunk/Lib/urllib.py
 python/trunk/Lib/urllib2.py
Log:
[Patch #1574068 by Scott Dial] urllib and urllib2 were using
base64.encodestring() for encoding authentication data.
encodestring() can include newlines for very long input, which
produced broken HTTP headers.
Modified: python/trunk/Lib/urllib.py
==============================================================================
--- python/trunk/Lib/urllib.py	(original)
+++ python/trunk/Lib/urllib.py	Fri Oct 27 19:11:23 2006
@@ -302,13 +302,13 @@
 
 if proxy_passwd:
 import base64
- proxy_auth = base64.encodestring(proxy_passwd).strip()
+ proxy_auth = base64.b64encode(proxy_passwd).strip()
 else:
 proxy_auth = None
 
 if user_passwd:
 import base64
- auth = base64.encodestring(user_passwd).strip()
+ auth = base64.b64encode(user_passwd).strip()
 else:
 auth = None
 h = httplib.HTTP(host)
@@ -387,12 +387,12 @@
 if not host: raise IOError, ('https error', 'no host given')
 if proxy_passwd:
 import base64
- proxy_auth = base64.encodestring(proxy_passwd).strip()
+ proxy_auth = base64.b64encode(proxy_passwd).strip()
 else:
 proxy_auth = None
 if user_passwd:
 import base64
- auth = base64.encodestring(user_passwd).strip()
+ auth = base64.b64encode(user_passwd).strip()
 else:
 auth = None
 h = httplib.HTTPS(host, 0,
Modified: python/trunk/Lib/urllib2.py
==============================================================================
--- python/trunk/Lib/urllib2.py	(original)
+++ python/trunk/Lib/urllib2.py	Fri Oct 27 19:11:23 2006
@@ -674,7 +674,7 @@
 proxy_type = orig_type
 if user and password:
 user_pass = '%s:%s' % (unquote(user), unquote(password))
- creds = base64.encodestring(user_pass).strip()
+ creds = base64.b64encode(user_pass).strip()
 req.add_header('Proxy-authorization', 'Basic ' + creds)
 hostport = unquote(hostport)
 req.set_proxy(hostport, proxy_type)
@@ -798,7 +798,7 @@
 user, pw = self.passwd.find_user_password(realm, host)
 if pw is not None:
 raw = "%s:%s" % (user, pw)
- auth = 'Basic %s' % base64.encodestring(raw).strip()
+ auth = 'Basic %s' % base64.b64encode(raw).strip()
 if req.headers.get(self.auth_header, None) == auth:
 return None
 req.add_header(self.auth_header, auth)


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /