Skip to content

Commit

Permalink
fix base64.encode{bytes,string} Python 2 regression
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Tarleton authored and garnaat committed Apr 2, 2011
1 parent 63bf4e8 commit 2dc32d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion boto/auth.py
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 3 additions & 1 deletion boto/connection.py
Expand Up @@ -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 }

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions boto/s3/key.py
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions boto/sdb/db/manager/xmlmanager.py
Expand Up @@ -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'

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2dc32d7

Please sign in to comment.