diff --git a/oslo/messaging/_drivers/amqp.py b/oslo/messaging/_drivers/amqp.py index fcd077314..59fec2b3e 100644 --- a/oslo/messaging/_drivers/amqp.py +++ b/oslo/messaging/_drivers/amqp.py @@ -183,9 +183,7 @@ def unpack_context(conf, msg): """Unpack context from msg.""" context_dict = {} for key in list(msg.keys()): - # NOTE(vish): Some versions of Python don't like unicode keys - # in kwargs. - key = str(key) + key = six.text_type(key) if key.startswith('_context_'): value = msg.pop(key) context_dict[key[9:]] = value diff --git a/oslo/messaging/_drivers/common.py b/oslo/messaging/_drivers/common.py index 45a75f103..494bd2639 100644 --- a/oslo/messaging/_drivers/common.py +++ b/oslo/messaging/_drivers/common.py @@ -199,8 +199,8 @@ def serialize_remote_exception(failure_info, log_failure=True): # NOTE(matiu): With cells, it's possible to re-raise remote, remote # exceptions. Lets turn it back into the original exception type. - cls_name = str(failure.__class__.__name__) - mod_name = str(failure.__class__.__module__) + cls_name = six.text_type(failure.__class__.__name__) + mod_name = six.text_type(failure.__class__.__module__) if (cls_name.endswith(_REMOTE_POSTFIX) and mod_name.endswith(_REMOTE_POSTFIX)): cls_name = cls_name[:-len(_REMOTE_POSTFIX)] @@ -221,7 +221,7 @@ def serialize_remote_exception(failure_info, log_failure=True): def deserialize_remote_exception(data, allowed_remote_exmods): - failure = jsonutils.loads(str(data)) + failure = jsonutils.loads(six.text_type(data)) trace = failure.get('tb', []) message = failure.get('message', "") + "\n" + "\n".join(trace) diff --git a/oslo/messaging/_drivers/impl_qpid.py b/oslo/messaging/_drivers/impl_qpid.py index fbd5f40b0..7852cb216 100644 --- a/oslo/messaging/_drivers/impl_qpid.py +++ b/oslo/messaging/_drivers/impl_qpid.py @@ -506,10 +506,10 @@ class Connection(object): self.connection.open() def _register_consumer(self, consumer): - self.consumers[str(consumer.get_receiver())] = consumer + self.consumers[six.text_type(consumer.get_receiver())] = consumer def _lookup_consumer(self, receiver): - return self.consumers[str(receiver)] + return self.consumers[six.text_type(receiver)] def _disconnect(self): # Close the session if necessary diff --git a/oslo/messaging/_drivers/impl_rabbit.py b/oslo/messaging/_drivers/impl_rabbit.py index 4e869f4d9..84f7cbfb6 100644 --- a/oslo/messaging/_drivers/impl_rabbit.py +++ b/oslo/messaging/_drivers/impl_rabbit.py @@ -151,7 +151,7 @@ class ConsumerBase(object): passed in here as a dictionary. """ self.callback = callback - self.tag = str(tag) + self.tag = six.text_type(tag) self.kwargs = kwargs self.queue = None self.reconnect(channel) @@ -208,7 +208,7 @@ class ConsumerBase(object): self.queue.cancel(self.tag) except KeyError as e: # NOTE(comstud): Kludge to get around a amqplib bug - if str(e) != "u'%s'" % self.tag: + if six.text_type(e) != "u'%s'" % self.tag: raise self.queue = None @@ -617,7 +617,7 @@ class Connection(object): # a protocol response. (See paste link in LP888621) # So, we check all exceptions for 'timeout' in them # and try to reconnect in this case. - if 'timeout' not in str(e): + if 'timeout' not in six.text_type(e): raise log_info = {} @@ -670,7 +670,7 @@ class Connection(object): # a protocol response. (See paste link in LP888621) # So, we check all exceptions for 'timeout' in them # and try to reconnect in this case. - if 'timeout' not in str(e): + if 'timeout' not in six.text_type(e): raise if error_callback: error_callback(e) diff --git a/oslo/messaging/_drivers/impl_zmq.py b/oslo/messaging/_drivers/impl_zmq.py index 80113df92..b78c64528 100644 --- a/oslo/messaging/_drivers/impl_zmq.py +++ b/oslo/messaging/_drivers/impl_zmq.py @@ -783,7 +783,8 @@ def fanout_cast(conf, context, topic, msg, **kwargs): """Send a message to all listening and expect no reply.""" # NOTE(ewindisch): fanout~ is used because it avoid splitting on . # and acts as a non-subtle hint to the matchmaker and ZmqProxy. - _multi_send(_cast, context, 'fanout~' + str(topic), msg, **kwargs) + _multi_send(_cast, context, 'fanout~' + six.text_type(topic), + msg, **kwargs) def notify(conf, context, topic, msg, envelope): diff --git a/oslo/messaging/exceptions.py b/oslo/messaging/exceptions.py index 21d14e997..93f525abe 100644 --- a/oslo/messaging/exceptions.py +++ b/oslo/messaging/exceptions.py @@ -16,6 +16,8 @@ __all__ = ['MessagingException', 'MessagingTimeout', 'MessageDeliveryFailure', 'InvalidTarget'] +import six + class MessagingException(Exception): """Base class for exceptions.""" @@ -33,6 +35,6 @@ class InvalidTarget(MessagingException, ValueError): """Raised if a target does not meet certain pre-conditions.""" def __init__(self, msg, target): - msg = msg + ":" + str(target) + msg = msg + ":" + six.text_type(target) super(InvalidTarget, self).__init__(msg) self.target = target diff --git a/oslo/messaging/notify/notifier.py b/oslo/messaging/notify/notifier.py index d5ab9c1e9..81610a2f8 100644 --- a/oslo/messaging/notify/notifier.py +++ b/oslo/messaging/notify/notifier.py @@ -62,7 +62,7 @@ class Notifier(object): Notification messages follow the following format:: - {'message_id': str(uuid.uuid4()), + {'message_id': six.text_type(uuid.uuid4()), 'publisher_id': 'compute.host1', 'timestamp': timeutils.utcnow(), 'priority': 'WARN', @@ -163,12 +163,12 @@ class Notifier(object): payload = self._serializer.serialize_entity(ctxt, payload) ctxt = self._serializer.serialize_context(ctxt) - msg = dict(message_id=str(uuid.uuid4()), + msg = dict(message_id=six.text_type(uuid.uuid4()), publisher_id=publisher_id or self.publisher_id, event_type=event_type, priority=priority, payload=payload, - timestamp=str(timeutils.utcnow())) + timestamp=six.text_type(timeutils.utcnow())) def do_notify(ext): try: