Skip to content

Commit

Permalink
use encodebytes instead of encodestring (boto#2483)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Bulinski committed Aug 1, 2014
1 parent 07d6424 commit abb6682
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions boto/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import time
import posixpath

from boto.compat import urllib
from boto.compat import urllib, encodebytes
from boto.auth_handler import AuthHandler
from boto.exception import BotoClientError

Expand Down Expand Up @@ -89,7 +89,7 @@ def _get_hmac(self):
def sign_string(self, string_to_sign):
new_hmac = self._get_hmac()
new_hmac.update(string_to_sign.encode('utf-8'))
return base64.encodestring(new_hmac.digest()).decode('utf-8').strip()
return encodebytes(new_hmac.digest()).decode('utf-8').strip()

def __getstate__(self):
pickled_dict = copy.copy(self.__dict__)
Expand Down
7 changes: 7 additions & 0 deletions boto/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
import json


# Switch to use encodebytes, which deprecates encodestring in Python 3
try:
from base64 import encodebytes
except ImportError:
from base64 import encodestring as encodebytes


# If running in Google App Engine there is no "user" and
# os.path.expanduser() will fail. Attempt to detect this case and use a
# no-op expanduser function in this case.
Expand Down
5 changes: 2 additions & 3 deletions boto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"""
from __future__ import with_statement

import base64
from datetime import datetime
import errno
import os
Expand All @@ -64,7 +63,7 @@
import boto.cacerts

from boto import config, UserAgent
from boto.compat import six, http_client, urlparse, quote
from boto.compat import six, http_client, urlparse, quote, encodebytes
from boto.exception import AWSConnectionError
from boto.exception import BotoClientError
from boto.exception import BotoServerError
Expand Down Expand Up @@ -857,7 +856,7 @@ def prefix_proxy_to_path(self, path, host=None):
return path

def get_proxy_auth_header(self):
auth = base64.encodestring(self.proxy_user + ':' + self.proxy_pass)
auth = encodebytes(self.proxy_user + ':' + self.proxy_pass)
return {'Proxy-Authorization': 'Basic %s' % auth}

def set_host_header(self, request):
Expand Down
5 changes: 2 additions & 3 deletions boto/mws/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
# IN THE SOFTWARE.
import xml.sax
import hashlib
import base64
import string
import collections
from boto.connection import AWSQueryConnection
from boto.exception import BotoServerError
import boto.mws.exception
import boto.mws.response
from boto.handler import XmlHandler
from boto.compat import filter, map, six
from boto.compat import filter, map, six, encodebytes

__all__ = ['MWSConnection']

Expand All @@ -55,7 +54,7 @@
'OffAmazonPayments': ('2013-01-01', 'SellerId',
'/OffAmazonPayments/2013-01-01'),
}
content_md5 = lambda c: base64.encodestring(hashlib.md5(c).digest()).strip()
content_md5 = lambda c: encodebytes(hashlib.md5(c).digest()).strip()
decorated_attrs = ('action', 'response', 'section',
'quota', 'restore', 'version')
api_call_map = {}
Expand Down
4 changes: 2 additions & 2 deletions boto/s3/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import binascii
import math
import boto.utils
from boto.compat import BytesIO, six, urllib
from boto.compat import BytesIO, six, urllib, encodebytes

from boto.exception import BotoClientError
from boto.exception import StorageDataError
Expand Down Expand Up @@ -211,7 +211,7 @@ def get_md5_from_hexdigest(self, md5_hexdigest):
from just having a precalculated md5_hexdigest.
"""
digest = binascii.unhexlify(md5_hexdigest)
base64md5 = base64.encodestring(digest)
base64md5 = encodebytes(digest)
if base64md5[-1] == '\n':
base64md5 = base64md5[0:-1]
return (md5_hexdigest, base64md5)
Expand Down
5 changes: 2 additions & 3 deletions boto/sdb/db/manager/xmlmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from boto.utils import find_class, Password
from boto.sdb.db.key import Key
from boto.sdb.db.model import Model
from boto.compat import six
from boto.compat import six, encodebytes
from datetime import datetime
from xml.dom.minidom import getDOMImplementation, parse, parseString, Node

Expand Down Expand Up @@ -203,8 +203,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.encodestring('%s:%s' % (self.db_user, self.db_passwd))[:-1]
base64string = encodebytes('%s:%s' % (self.db_user, self.db_passwd))[:-1]
authheader = "Basic %s" % base64string
self.auth_header = authheader

Expand Down
5 changes: 2 additions & 3 deletions boto/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
import email.utils
import email.encoders
import gzip
import base64
import threading
import locale
from boto.compat import six, StringIO, urllib
from boto.compat import six, StringIO, urllib, encodebytes

from contextlib import contextmanager

Expand Down Expand Up @@ -1029,7 +1028,7 @@ def compute_hash(fp, buf_size=8192, size=None, hash_algorithm=md5):
else:
s = fp.read(buf_size)
hex_digest = hash_obj.hexdigest()
base64_digest = base64.encodestring(hash_obj.digest()).decode('utf-8')
base64_digest = encodebytes(hash_obj.digest()).decode('utf-8')
if base64_digest[-1] == '\n':
base64_digest = base64_digest[0:-1]
# data_size based on bytes read.
Expand Down

0 comments on commit abb6682

Please sign in to comment.