From ea8fad47a57b1c8784a0a7c1fc435c4e38200863 Mon Sep 17 00:00:00 2001
From: Li-zhigang
Date: Wed, 23 Nov 2016 11:18:27 +0800
Subject: [PATCH] Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using six.iteritems to achieve iterators.
We can use dict.items instead, as it will return iterators in PY3 as well.
And dict.items/keys will more readable. 2.In py2, the performance about
list should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html
Change-Id: Ia235afc3532f62f265f91ca46d2306c72fc2a2a2
---
oslo_messaging/_drivers/amqp.py | 4 ++--
oslo_messaging/_drivers/common.py | 2 +-
oslo_messaging/_drivers/pika_driver/pika_message.py | 2 +-
.../_drivers/zmq_driver/server/zmq_incoming_message.py | 4 +---
oslo_messaging/_drivers/zmq_driver/server/zmq_ttl_cache.py | 4 +---
oslo_messaging/notify/_impl_routing.py | 5 ++---
oslo_messaging/notify/middleware.py | 3 +--
oslo_messaging/rpc/client.py | 2 +-
oslo_messaging/rpc/dispatcher.py | 2 +-
oslo_messaging/tests/utils.py | 4 ++--
oslo_messaging/transport.py | 2 +-
11 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/oslo_messaging/_drivers/amqp.py b/oslo_messaging/_drivers/amqp.py
index 071a00475..01eeca69a 100644
--- a/oslo_messaging/_drivers/amqp.py
+++ b/oslo_messaging/_drivers/amqp.py
@@ -89,9 +89,9 @@ def pack_context(msg, context):
"""
if isinstance(context, dict):
- context_d = six.iteritems(context)
+ context_d = context.items()
else:
- context_d = six.iteritems(context.to_dict())
+ context_d = context.to_dict().items()
msg.update(('_context_%s' % key, value)
for (key, value) in context_d)
diff --git a/oslo_messaging/_drivers/common.py b/oslo_messaging/_drivers/common.py
index a28e37c02..7b0e4028b 100644
--- a/oslo_messaging/_drivers/common.py
+++ b/oslo_messaging/_drivers/common.py
@@ -89,7 +89,7 @@ class RPCException(Exception):
# log the issue and the kwargs
LOG.exception(_LE('Exception in string format operation, '
'kwargs are:'))
- for name, value in six.iteritems(kwargs):
+ for name, value in kwargs.items():
LOG.error("%s: %s", name, value)
# at least get the core message out if something happened
message = self.msg_fmt
diff --git a/oslo_messaging/_drivers/pika_driver/pika_message.py b/oslo_messaging/_drivers/pika_driver/pika_message.py
index 959f700a0..151fecfb6 100644
--- a/oslo_messaging/_drivers/pika_driver/pika_message.py
+++ b/oslo_messaging/_drivers/pika_driver/pika_message.py
@@ -344,7 +344,7 @@ class PikaOutgoingMessage(object):
msg = self.message.copy()
if self.context:
- for key, value in six.iteritems(self.context):
+ for key, value in self.context.items():
key = six.text_type(key)
msg['_$_' + key] = value
diff --git a/oslo_messaging/_drivers/zmq_driver/server/zmq_incoming_message.py b/oslo_messaging/_drivers/zmq_driver/server/zmq_incoming_message.py
index 7ab09394a..a7ddd091c 100644
--- a/oslo_messaging/_drivers/zmq_driver/server/zmq_incoming_message.py
+++ b/oslo_messaging/_drivers/zmq_driver/server/zmq_incoming_message.py
@@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import six
-
from oslo_messaging._drivers import base
@@ -27,7 +25,7 @@ class ZmqIncomingMessage(base.RpcIncomingMessage):
super(ZmqIncomingMessage, self).__init__(context, message)
self._reply_method = kwargs.pop('reply_method',
lambda self, reply, failure: None)
- for key, value in six.iteritems(kwargs):
+ for key, value in kwargs.items():
setattr(self, key, value)
def acknowledge(self):
diff --git a/oslo_messaging/_drivers/zmq_driver/server/zmq_ttl_cache.py b/oslo_messaging/_drivers/zmq_driver/server/zmq_ttl_cache.py
index 91d5d4141..fb4ddecfd 100644
--- a/oslo_messaging/_drivers/zmq_driver/server/zmq_ttl_cache.py
+++ b/oslo_messaging/_drivers/zmq_driver/server/zmq_ttl_cache.py
@@ -16,8 +16,6 @@ import logging
import threading
import time
-import six
-
from oslo_messaging._drivers.zmq_driver import zmq_async
LOG = logging.getLogger(__name__)
@@ -77,7 +75,7 @@ class TTLCache(object):
old_size = len(self._cache)
self._cache = \
{key: (value, expiration_time) for
- key, (value, expiration_time) in six.iteritems(self._cache)
+ key, (value, expiration_time) in self._cache.items()
if not self._is_expired(expiration_time, current_time)}
new_size = len(self._cache)
LOG.debug('Updated cache: current size %(new_size)s '
diff --git a/oslo_messaging/notify/_impl_routing.py b/oslo_messaging/notify/_impl_routing.py
index c7136d088..8faf4ee37 100644
--- a/oslo_messaging/notify/_impl_routing.py
+++ b/oslo_messaging/notify/_impl_routing.py
@@ -17,7 +17,6 @@ import logging
from oslo_config import cfg
from oslo_utils import fnmatch
-import six
from stevedore import dispatch
import yaml
@@ -88,9 +87,9 @@ class RoutingDriver(notifier.Driver):
"""
accepted_drivers = set()
- for driver, rules in six.iteritems(group):
+ for driver, rules in group.items():
checks = []
- for key, patterns in six.iteritems(rules):
+ for key, patterns in rules.items():
if key == 'accepted_events':
c = [fnmatch.fnmatch(event_type, p)
for p in patterns]
diff --git a/oslo_messaging/notify/middleware.py b/oslo_messaging/notify/middleware.py
index 60aab278b..67f453f92 100644
--- a/oslo_messaging/notify/middleware.py
+++ b/oslo_messaging/notify/middleware.py
@@ -23,7 +23,6 @@ import traceback as tb
from oslo_config import cfg
from oslo_middleware import base
-import six
import webob.dec
import oslo_messaging
@@ -73,7 +72,7 @@ class RequestNotifier(base.Middleware):
include them.
"""
- return dict((k, v) for k, v in six.iteritems(environ)
+ return dict((k, v) for k, v in environ.items()
if k.isupper() and k != 'HTTP_X_AUTH_TOKEN')
@log_and_ignore_error
diff --git a/oslo_messaging/rpc/client.py b/oslo_messaging/rpc/client.py
index 5f6c64d48..b746fbeaa 100644
--- a/oslo_messaging/rpc/client.py
+++ b/oslo_messaging/rpc/client.py
@@ -105,7 +105,7 @@ class _BaseCallContext(object):
msg = dict(method=method)
msg['args'] = dict()
- for argname, arg in six.iteritems(args):
+ for argname, arg in args.items():
msg['args'][argname] = self.serializer.serialize_entity(ctxt, arg)
if self.target.namespace is not None:
diff --git a/oslo_messaging/rpc/dispatcher.py b/oslo_messaging/rpc/dispatcher.py
index 91b62a3c6..06c72a763 100644
--- a/oslo_messaging/rpc/dispatcher.py
+++ b/oslo_messaging/rpc/dispatcher.py
@@ -186,7 +186,7 @@ class RPCDispatcher(dispatcher.DispatcherBase):
def _do_dispatch(self, endpoint, method, ctxt, args):
ctxt = self.serializer.deserialize_context(ctxt)
new_args = dict()
- for argname, arg in six.iteritems(args):
+ for argname, arg in args.items():
new_args[argname] = self.serializer.deserialize_entity(ctxt, arg)
func = getattr(endpoint, method)
result = func(ctxt, **new_args)
diff --git a/oslo_messaging/tests/utils.py b/oslo_messaging/tests/utils.py
index c5fca8711..d8c0f4dba 100644
--- a/oslo_messaging/tests/utils.py
+++ b/oslo_messaging/tests/utils.py
@@ -24,7 +24,7 @@ import threading
from oslo_config import cfg
from oslotest import base
from oslotest import moxstubout
-import six
+
TRUE_VALUES = ('true', '1', 'yes')
@@ -59,7 +59,7 @@ class BaseTestCase(base.BaseTestCase):
test by the tearDown() method.
"""
group = kw.pop('group', None)
- for k, v in six.iteritems(kw):
+ for k, v in kw.items():
self.conf.set_override(k, v, group, enforce_type=True)
diff --git a/oslo_messaging/transport.py b/oslo_messaging/transport.py
index c1361e7f9..b7408201d 100644
--- a/oslo_messaging/transport.py
+++ b/oslo_messaging/transport.py
@@ -411,7 +411,7 @@ class TransportURL(object):
query = {}
if url.query:
- for key, values in six.iteritems(parse.parse_qs(url.query)):
+ for key, values in parse.parse_qs(url.query).items():
query[key] = ','.join(values)
virtual_host = None