From 2506030cf11f2f9b83ff088f670413b0c600b823 Mon Sep 17 00:00:00 2001 From: LiuNanke Date: Thu, 1 Dec 2016 15:59:42 +0800 Subject: [PATCH] Replace six iteration methods with standard ones 1.As mentioned in [1], we should avoid using six.iterXXX to achieve iterators. We can use dict.XXX instead, as it will return iterators in PY3 as well. 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: If90a56fad941e4bb55da1e9f14a8133983efc027 --- murano/common/helpers/token_sanitizer.py | 2 +- murano/engine/system/yaql_functions.py | 2 +- murano/policy/congress_rules.py | 6 ++---- murano/policy/modify/actions/default_actions.py | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/murano/common/helpers/token_sanitizer.py b/murano/common/helpers/token_sanitizer.py index 100da9bf..1b5e8843 100644 --- a/murano/common/helpers/token_sanitizer.py +++ b/murano/common/helpers/token_sanitizer.py @@ -55,7 +55,7 @@ class TokenSanitizer(object): :return: Sanitized object """ if isinstance(obj, dict): - return dict([self.sanitize(item) for item in six.iteritems(obj)]) + return dict([self.sanitize(item) for item in obj.items()]) elif isinstance(obj, list): return [self.sanitize(item) for item in obj] elif isinstance(obj, tuple): diff --git a/murano/engine/system/yaql_functions.py b/murano/engine/system/yaql_functions.py index fda6dae6..54c3ae39 100644 --- a/murano/engine/system/yaql_functions.py +++ b/murano/engine/system/yaql_functions.py @@ -67,7 +67,7 @@ def bind(obj, mappings): return [bind(t, mappings) for t in obj] elif isinstance(obj, collections.Mapping): result = {} - for key, value in six.iteritems(obj): + for key, value in obj.items(): result[bind(key, mappings)] = bind(value, mappings) return result elif isinstance(obj, six.string_types) and obj.startswith('$'): diff --git a/murano/policy/congress_rules.py b/murano/policy/congress_rules.py index 0a9e83b6..5020cc69 100644 --- a/murano/policy/congress_rules.py +++ b/murano/policy/congress_rules.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from murano.dsl import helpers @@ -101,7 +99,7 @@ class CongressRulesManager(object): for v in obj: self._walk(v, new_owner, path) elif isinstance(obj, dict): - for key, value in six.iteritems(obj): + for key, value in obj.items(): self._walk(value, new_owner, path + (key, )) def _process_item(self, obj, owner_id, path): @@ -152,7 +150,7 @@ class CongressRulesManager(object): prefix.split('.')[0])) return rules - for key, value in six.iteritems(obj): + for key, value in obj.items(): if key == '?': continue diff --git a/murano/policy/modify/actions/default_actions.py b/murano/policy/modify/actions/default_actions.py index 88f2fe42..c9da091c 100644 --- a/murano/policy/modify/actions/default_actions.py +++ b/murano/policy/modify/actions/default_actions.py @@ -18,7 +18,6 @@ Default actions reside in this module. These action are available out of the box for Murano users. """ -import six import yaql.language.utils as utils import murano.dsl.exceptions as exceptions @@ -42,7 +41,7 @@ class ActionUtils(object): for item in obj: self._get_objects_by_id(item, objects) elif isinstance(obj, utils.FrozenDict): - for k, v in six.iteritems(obj): + for k, v in obj.items(): self._get_objects_by_id(k, objects) self._get_objects_by_id(v, objects) return objects