From e1ee66b24c10615f25dce1e2293fbec9cc00a1f4 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 14 Jul 2017 08:09:06 +0300 Subject: Convert mechanisms to bytes if it is a string --- amqp/connection.py | 4 +++- t/unit/test_connection.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/amqp/connection.py b/amqp/connection.py index f0c4540..2ed89fb 100644 --- a/amqp/connection.py +++ b/amqp/connection.py @@ -33,7 +33,7 @@ from .exceptions import ( ConnectionForced, ConnectionError, error_for_code, RecoverableConnectionError, RecoverableChannelError, ) -from .five import array, items, monotonic, range, values +from .five import array, items, monotonic, range, values, string from .method_framing import frame_handler, frame_writer from .transport import Transport @@ -344,6 +344,8 @@ class Connection(AbstractChannel): self.version_major = version_major self.version_minor = version_minor self.server_properties = server_properties + if isinstance(mechanisms, string): + mechanisms = mechanisms.encode('utf-8') self.mechanisms = mechanisms.split(b' ') self.locales = locales.split(' ') AMQP_LOGGER.debug( diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index 3a94475..621bb72 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -104,6 +104,23 @@ class test_Connection: ), ) + + def test_on_start_string_mechanisms(self): + self.conn._on_start(3, 4, {'foo': 'bar'}, 'x y z AMQPLAIN PLAIN', + 'en_US en_GB') + assert self.conn.version_major == 3 + assert self.conn.version_minor == 4 + assert self.conn.server_properties == {'foo': 'bar'} + assert self.conn.mechanisms == [b'x', b'y', b'z', + b'AMQPLAIN', b'PLAIN'] + assert self.conn.locales == ['en_US', 'en_GB'] + self.conn.send_method.assert_called_with( + spec.Connection.StartOk, 'FsSs', ( + self.conn.client_properties, b'AMQPLAIN', + self.conn.authentication[0].start(self.conn), self.conn.locale, + ), + ) + def test_missing_credentials(self): with pytest.raises(ValueError): self.conn = Connection(userid=None, password=None) -- cgit v1.2.1