From 2dc32d7d861bb532e0bda20dbe64e8c4c8b9b1e3 Mon Sep 17 00:00:00 2001 From: Nick Tarleton Date: Sat, 2 Apr 2011 11:37:55 -0700 Subject: fix base64.encode{bytes,string} Python 2 regression --- boto/auth.py | 4 +++- boto/connection.py | 4 +++- boto/s3/key.py | 6 ++++-- boto/sdb/db/manager/xmlmanager.py | 7 +++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/boto/auth.py b/boto/auth.py index 91440524..17280f77 100644 --- a/boto/auth.py +++ b/boto/auth.py @@ -42,9 +42,11 @@ from boto.exception import BotoClientError 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 @@ class HmacKeys(object): 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.""" diff --git a/boto/connection.py b/boto/connection.py index a8fb6562..e6ae5187 100644 --- a/boto/connection.py +++ b/boto/connection.py @@ -64,11 +64,13 @@ try: 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 @@ class AWSAuthConnection(object): 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, diff --git a/boto/s3/key.py b/boto/s3/key.py index 12e604ef..440930b6 100644 --- a/boto/s3/key.py +++ b/boto/s3/key.py @@ -35,10 +35,12 @@ try: # 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 @@ class Key(object): """ 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 @@ class Key(object): 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() diff --git a/boto/sdb/db/manager/xmlmanager.py b/boto/sdb/db/manager/xmlmanager.py index 666eef7f..9c2909a8 100644 --- a/boto/sdb/db/manager/xmlmanager.py +++ b/boto/sdb/db/manager/xmlmanager.py @@ -24,10 +24,14 @@ from boto.sdb.db.key import Key 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 @@ class XMLManager(object): 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 -- cgit v1.2.1