summaryrefslogtreecommitdiff
path: root/oslo_serialization
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_serialization')
-rw-r--r--oslo_serialization/base64.py5
-rw-r--r--oslo_serialization/tests/test_base64.py7
-rw-r--r--oslo_serialization/tests/test_msgpackutils.py4
3 files changed, 13 insertions, 3 deletions
diff --git a/oslo_serialization/base64.py b/oslo_serialization/base64.py
index 34c8e4e..7ff6e57 100644
--- a/oslo_serialization/base64.py
+++ b/oslo_serialization/base64.py
@@ -67,7 +67,10 @@ def decode_as_bytes(encoded):
"""
if isinstance(encoded, bytes):
encoded = encoded.decode('ascii')
- return base64.b64decode(encoded)
+ if six.PY2:
+ return base64.decodestring(encoded)
+ else:
+ return base64.b64decode(encoded)
def decode_as_text(encoded, encoding='utf-8'):
diff --git a/oslo_serialization/tests/test_base64.py b/oslo_serialization/tests/test_base64.py
index 292c214..8b29d70 100644
--- a/oslo_serialization/tests/test_base64.py
+++ b/oslo_serialization/tests/test_base64.py
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import binascii
+
from oslo_serialization import base64
from oslotest import base as test_base
@@ -45,6 +47,11 @@ class Base64Tests(test_base.BaseTestCase):
self.assertEqual(b'text',
base64.decode_as_bytes(u'dGV4dA=='))
+ def test_decode_as_bytes__error(self):
+ self.assertRaises(binascii.Error,
+ base64.decode_as_bytes,
+ 'hello world')
+
def test_decode_as_text(self):
self.assertEqual(u'text',
base64.decode_as_text(b'dGV4dA=='))
diff --git a/oslo_serialization/tests/test_msgpackutils.py b/oslo_serialization/tests/test_msgpackutils.py
index 7aceb44..649ebc9 100644
--- a/oslo_serialization/tests/test_msgpackutils.py
+++ b/oslo_serialization/tests/test_msgpackutils.py
@@ -14,7 +14,6 @@
import datetime
import itertools
-import uuid
import netaddr
from oslotest import base as test_base
@@ -23,6 +22,7 @@ import six
import six.moves.xmlrpc_client as xmlrpclib
from oslo_serialization import msgpackutils
+from oslo_utils import uuidutils
_TZ_FMT = '%Y-%m-%d %H:%M:%S %Z%z'
@@ -94,7 +94,7 @@ class MsgPackUtilsTest(test_base.BaseTestCase):
'b': 2.0,
'c': [],
'd': set([1, 2, 3]),
- 'zzz': uuid.uuid4(),
+ 'zzz': uuidutils.generate_uuid(),
'yyy': 'yyy',
'ddd': b'bbb',
'today': datetime.date.today(),