diff --git a/coolamqp/objects.py b/coolamqp/objects.py index 22fd7962a224c8a92f2eb97d1ff75be211df5b3f..c68621cb3efd8a463287954515b9cedf3c844489 100644 --- a/coolamqp/objects.py +++ b/coolamqp/objects.py @@ -27,6 +27,8 @@ def toutf8(q): def tobytes(q): + if isinstance(q, memoryview): + return q.tobytes() return q.encode('utf-8') if isinstance(q, six.text_type) else q @@ -287,8 +289,7 @@ class Queue(object): if name is None: self.name = None else: - name = uuid.uuid4().hex if not name else name - self.name = tobytes(name) + self.name = tobytes(uuid.uuid4().hex if not name else name) self.durable = durable self.exchange = exchange diff --git a/tests/test_objects.py b/tests/test_objects.py index b7fa700ab48bb1c46b98b7d271ea7a102233ebc7..306c2e47507e7997c093692a3efcd437e9f1a968 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -1,5 +1,6 @@ # coding=UTF-8 from __future__ import print_function, absolute_import, division +import sys import logging import unittest import io @@ -26,7 +27,7 @@ class TestObjects(unittest.TestCase): with warnings.catch_warnings(record=True) as w: Queue('test', auto_delete=True, exclusive=True) Queue(auto_delete=True, exclusive=False) - self.assertEqual(len(w), 2) + self.assertEqual(len(w), 2 if sys.version.startswith('3') else 1) self.assertTrue(issubclass(w[0].category, UserWarning)) self.assertTrue(issubclass(w[1].category, DeprecationWarning))