Browse Source

Replace usage of str() with six.text_type

Replace using of str with six.text_type as it's able to
handle unicode data.

Change-Id: I38e4378c490d1dad8020312308dd3b6dad8772c0
changes/62/97362/3
Aaron Rosen 8 years ago
parent
commit
0102aa96e6
  1. 4
      oslo/messaging/_drivers/amqp.py
  2. 6
      oslo/messaging/_drivers/common.py
  3. 4
      oslo/messaging/_drivers/impl_qpid.py
  4. 8
      oslo/messaging/_drivers/impl_rabbit.py
  5. 3
      oslo/messaging/_drivers/impl_zmq.py
  6. 4
      oslo/messaging/exceptions.py
  7. 6
      oslo/messaging/notify/notifier.py

4
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

6
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)

4
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

8
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)

3
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):

4
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

6
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:

Loading…
Cancel
Save