utils/web.py: Fix compatibility with Python 3.

This commit is contained in:
Valentin Lorentz 2013-06-17 04:10:29 +00:00
parent cca1e6dba5
commit 774158f2ec
1 changed files with 7 additions and 1 deletions

View File

@ -117,8 +117,13 @@ def getUrlFd(url, headers=None, data=None):
url = scheme + '://' + url
request = urllib2.Request(url, headers=headers, data=data)
if 'auth' in locals():
if sys.version_info[0] >= 3 and isinstance(auth, str):
auth = auth.encode()
auth = base64.b64encode(auth)
if sys.version_info[0] >= 3:
auth = auth.decode()
request.add_header('Authorization',
'Basic ' + base64.b64encode(auth))
'Basic ' + auth)
else:
request = url
request.add_data(data)
@ -212,3 +217,4 @@ def mungeEmail(s):
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: