Replace dict.iteritems() with six.iteritems()

dict.iteritems() was replaced with dict.items() in Python 3. Use the
six.iteritems() function to get code compatible with Python 2 and Python 3.

Change-Id: I0c8ecc3ae540ffaf4c6b159e09ca16ccf365973d
This commit is contained in:
Victor Stinner 2013-12-18 14:58:31 +01:00
parent 64f91d30a8
commit 062c8ac7dd
6 changed files with 14 additions and 10 deletions

View File

@ -29,6 +29,7 @@ import threading
import uuid import uuid
from oslo.config import cfg from oslo.config import cfg
import six
from oslo.messaging._drivers import common as rpc_common from oslo.messaging._drivers import common as rpc_common
from oslo.messaging._drivers import pool from oslo.messaging._drivers import pool
@ -293,13 +294,12 @@ def pack_context(msg, context):
""" """
if isinstance(context, dict): if isinstance(context, dict):
context_d = dict([('_context_%s' % key, value) context_d = six.iteritems(context)
for (key, value) in context.iteritems()])
else: else:
context_d = dict([('_context_%s' % key, value) context_d = six.iteritems(context.to_dict())
for (key, value) in context.to_dict().iteritems()])
msg.update(context_d) msg.update(('_context_%s' % key, value)
for (key, value) in context_d)
class _MsgIdCache(object): class _MsgIdCache(object):

View File

@ -97,7 +97,7 @@ class RPCException(Exception):
# kwargs doesn't match a variable in the message # kwargs doesn't match a variable in the message
# log the issue and the kwargs # log the issue and the kwargs
LOG.exception(_('Exception in string format operation')) LOG.exception(_('Exception in string format operation'))
for name, value in kwargs.iteritems(): for name, value in six.iteritems(kwargs):
LOG.error("%s: %s" % (name, value)) LOG.error("%s: %s" % (name, value))
# at least get the core message out if something happened # at least get the core message out if something happened
message = self.msg_fmt message = self.msg_fmt

View File

@ -440,7 +440,7 @@ class Connection(object):
'virtual_host': self.conf.rabbit_virtual_host, 'virtual_host': self.conf.rabbit_virtual_host,
} }
for sp_key, value in server_params.iteritems(): for sp_key, value in six.iteritems(server_params):
p_key = server_params_to_kombu_params.get(sp_key, sp_key) p_key = server_params_to_kombu_params.get(sp_key, sp_key)
params[p_key] = value params[p_key] = value

View File

@ -24,6 +24,7 @@ __all__ = [
] ]
from oslo.config import cfg from oslo.config import cfg
import six
from oslo.messaging._drivers import base as driver_base from oslo.messaging._drivers import base as driver_base
from oslo.messaging import _utils as utils from oslo.messaging import _utils as utils
@ -98,7 +99,7 @@ class _CallContext(object):
msg = dict(method=method) msg = dict(method=method)
msg['args'] = dict() msg['args'] = dict()
for argname, arg in args.iteritems(): for argname, arg in six.iteritems(args):
msg['args'][argname] = self.serializer.serialize_entity(ctxt, arg) msg['args'][argname] = self.serializer.serialize_entity(ctxt, arg)
if self.target.namespace is not None: if self.target.namespace is not None:

View File

@ -23,6 +23,8 @@ __all__ = [
'UnsupportedVersion', 'UnsupportedVersion',
] ]
import six
from oslo.messaging import _utils as utils from oslo.messaging import _utils as utils
from oslo.messaging import localcontext from oslo.messaging import localcontext
from oslo.messaging import serializer as msg_serializer from oslo.messaging import serializer as msg_serializer
@ -85,7 +87,7 @@ class RPCDispatcher(object):
def _dispatch(self, endpoint, method, ctxt, args): def _dispatch(self, endpoint, method, ctxt, args):
ctxt = self.serializer.deserialize_context(ctxt) ctxt = self.serializer.deserialize_context(ctxt)
new_args = dict() new_args = dict()
for argname, arg in args.iteritems(): for argname, arg in six.iteritems(args):
new_args[argname] = self.serializer.deserialize_entity(ctxt, arg) new_args[argname] = self.serializer.deserialize_entity(ctxt, arg)
result = getattr(endpoint, method)(ctxt, **new_args) result = getattr(endpoint, method)(ctxt, **new_args)
return self.serializer.serialize_entity(ctxt, result) return self.serializer.serialize_entity(ctxt, result)

View File

@ -25,6 +25,7 @@ import os
import fixtures import fixtures
from oslo.config import cfg from oslo.config import cfg
import six
import testtools import testtools
from oslo.messaging.openstack.common.fixture import moxstubout from oslo.messaging.openstack.common.fixture import moxstubout
@ -79,5 +80,5 @@ class BaseTestCase(testtools.TestCase):
test by the tearDown() method. test by the tearDown() method.
""" """
group = kw.pop('group', None) group = kw.pop('group', None)
for k, v in kw.iteritems(): for k, v in six.iteritems(kw):
self.conf.set_override(k, v, group) self.conf.set_override(k, v, group)