From 0de0c4f2c85452085f500010cc305e56e37d5f23 Mon Sep 17 00:00:00 2001 From: M V P Nitesh Date: Thu, 30 Mar 2017 13:54:07 +0530 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: Ifac571e10ee48b119bc4bbb6a5d92200d0c7e482 --- moganclient/common/base.py | 2 +- moganclient/common/exceptions.py | 2 +- moganclient/osc/v1/flavor.py | 5 ++--- moganclient/osc/v1/server.py | 7 +++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/moganclient/common/base.py b/moganclient/common/base.py index 88708f1..7d28ee8 100644 --- a/moganclient/common/base.py +++ b/moganclient/common/base.py @@ -264,7 +264,7 @@ class Resource(RequestIdMixin): self.append_request_ids(resp) def _add_details(self, info): - for (k, v) in six.iteritems(info): + for (k, v) in info.items(): try: setattr(self, k, v) self._info[k] = v diff --git a/moganclient/common/exceptions.py b/moganclient/common/exceptions.py index 8208c6e..8e9450c 100644 --- a/moganclient/common/exceptions.py +++ b/moganclient/common/exceptions.py @@ -406,7 +406,7 @@ class HttpVersionNotSupported(HttpServerError): # _code_map contains all the classes that have status_code attribute. _code_map = dict( (getattr(obj, 'status_code', None), obj) - for name, obj in six.iteritems(vars(sys.modules[__name__])) + for name, obj in vars(sys.modules[__name__]).items() if inspect.isclass(obj) and getattr(obj, 'status_code', False) ) diff --git a/moganclient/osc/v1/flavor.py b/moganclient/osc/v1/flavor.py index 34f18fa..27d0ea8 100644 --- a/moganclient/osc/v1/flavor.py +++ b/moganclient/osc/v1/flavor.py @@ -23,7 +23,6 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils -import six from moganclient.common import base from moganclient.common.i18n import _ @@ -88,7 +87,7 @@ class CreateFlavor(command.ShowOne): extra_specs = bc_client.flavor.get_extra_specs(data) info.update(extra_specs) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class DeleteFlavor(command.Command): @@ -260,7 +259,7 @@ class ShowFlavor(command.ShowOne): info = {} info.update(data._info) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class UnsetFlavor(command.Command): diff --git a/moganclient/osc/v1/server.py b/moganclient/osc/v1/server.py index 6186b7e..72c4fe0 100644 --- a/moganclient/osc/v1/server.py +++ b/moganclient/osc/v1/server.py @@ -23,7 +23,6 @@ from osc_lib.cli import parseractions from osc_lib.command import command from osc_lib import exceptions from osc_lib import utils -import six from moganclient.common.i18n import _ @@ -157,7 +156,7 @@ class CreateServer(command.ShowOne): ) info = {} info.update(data._info) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class DeleteServer(command.Command): @@ -295,7 +294,7 @@ class ShowServer(command.ShowOne): info = {} info.update(data._info) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class UpdateServer(command.ShowOne): @@ -381,7 +380,7 @@ class UpdateServer(command.ShowOne): updates=updates) info = {} info.update(data._info) - return zip(*sorted(six.iteritems(info))) + return zip(*sorted(info.items())) class StartServer(ServersActionBase):