Permalink
Browse files

fix base64.encode{bytes,string} Python 2 regression

  • Loading branch information...
1 parent 63bf4e8 commit 2dc32d7d861bb532e0bda20dbe64e8c4c8b9b1e3 Nick Tarleton committed with garnaat Apr 2, 2011
Showing with 15 additions and 6 deletions.
  1. +3 −1 boto/auth.py
  2. +3 −1 boto/connection.py
  3. +4 −2 boto/s3/key.py
  4. +5 −2 boto/sdb/db/manager/xmlmanager.py
View
@@ -42,9 +42,11 @@
try:
# Python 3.x
from urllib.parse import quote
+ base64_encodestring = base64.encodebytes
except ImportError:
# Python 2.x
from urllib import quote
+ base64_encodestring = base64.encodestring
#
# the following is necessary because of the incompatibilities
@@ -101,7 +103,7 @@ def sign_string(self, string_to_sign):
else:
hmac = self._hmac.copy()
hmac.update(string_to_sign.encode('utf-8'))
- return base64.encodebytes(hmac.digest()).strip().decode('utf-8')
+ return base64_encodestring(hmac.digest()).strip().decode('utf-8')
class HmacAuthV1Handler(AuthHandler, HmacKeys):
""" Implements the HMAC request signing used by S3 and GS."""
View
@@ -64,11 +64,13 @@
import http.client as httplib
import urllib.parse as urllib
unicode = str
+ base64_encodestring = base64.encodebytes
except ImportError:
# Python 2.x
import Queue
import httplib
import urllib
+ base64_encodestring = base64.encodestring
PORTS_BY_SECURITY = { True: 443, False: 80 }
@@ -409,7 +411,7 @@ def prefix_proxy_to_path(self, path, host=None):
return path
def get_proxy_auth_header(self):
- auth = base64.encodebytes(self.proxy_user + ':' + self.proxy_pass)
+ auth = base64_encodestring(self.proxy_user + ':' + self.proxy_pass)
return {'Proxy-Authorization': 'Basic %s' % auth}
def _mexe(self, method, path, data, headers, host=None, sender=None,
View
@@ -35,10 +35,12 @@
# Python 3.x
from io import StringIO
import email.utils as rfc822
+ base64_encodestring = base64.encodebytes
except ImportError:
# Python 2.x
import rfc822
import StringIO
+ base64_encodestring = base64.encodestring
class Key(object):
@@ -104,7 +106,7 @@ def get_md5_from_hexdigest(self, md5_hexdigest):
"""
import binascii
digest = binascii.unhexlify(md5_hexdigest)
- base64md5 = base64.encodebytes(digest)
+ base64md5 = base64_encodestring(digest)
if base64md5[-1] == '\n':
base64md5 = base64md5[0:-1]
return (md5_hexdigest, base64md5)
@@ -540,7 +542,7 @@ def compute_md5(self, fp):
m.update(s)
s = fp.read(self.BufferSize)
hex_md5 = m.hexdigest()
- base64md5 = base64.encodebytes(m.digest())
+ base64md5 = base64_encodestring(m.digest())
if base64md5[-1] == '\n':
base64md5 = base64md5[0:-1]
self.size = fp.tell()
@@ -24,10 +24,14 @@
from boto.sdb.db.model import Model
from datetime import datetime
from xml.dom.minidom import getDOMImplementation, parse, parseString, Node
+import base64
import sys
if sys.version_info.major >= 3:
basestring = str
+ base64_encodestring = base64.encodebytes
+else:
+ base64_encodestring = base64.encodestring
ISO8601 = '%Y-%m-%dT%H:%M:%SZ'
@@ -205,8 +209,7 @@ def __init__(self, cls, db_name, db_user, db_passwd,
self.enable_ssl = enable_ssl
self.auth_header = None
if self.db_user:
- import base64
- base64string = base64.encodebytes('%s:%s' % (self.db_user, self.db_passwd))[:-1]
+ base64string = base64_encodestring('%s:%s' % (self.db_user, self.db_passwd))[:-1]
authheader = "Basic %s" % base64string
self.auth_header = authheader

0 comments on commit 2dc32d7

Please sign in to comment.