Use dict.items() dirrectly instead of six.iteritems

Replacing dict.iteritems()/.itervalues() with
six.iteritems(dict)/six.itervalues(dict) was preferred in the past,
but there was a discussion suggesting to avoid six for this.

ref:
http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: I63b1e51597307862968f37803ffdbba63306d8c6
This commit is contained in:
ting.wang
2016-01-14 14:02:36 +08:00
parent dc6b8aad7e
commit 08fc69cfc4
6 changed files with 8 additions and 12 deletions

View File

@@ -42,7 +42,7 @@ CONF.register_opts(exc_log_opts)
def _cleanse_dict(original): def _cleanse_dict(original):
"""Strip all admin_password, new_pass, rescue_pass keys from a dict""" """Strip all admin_password, new_pass, rescue_pass keys from a dict"""
return dict((k, v) for k, v in six.iteritems(original) if "_pass" not in k) return dict((k, v) for k, v in original.items() if "_pass" not in k)
class WatcherException(Exception): class WatcherException(Exception):
@@ -75,7 +75,7 @@ class WatcherException(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(_LE('Exception in string format operation')) LOG.exception(_LE('Exception in string format operation'))
for name, value in six.iteritems(kwargs): for name, value in kwargs.items():
LOG.error("%s: %s", name, value) LOG.error("%s: %s", name, value)
if CONF.fatal_exception_format_errors: if CONF.fatal_exception_format_errors:

View File

@@ -11,7 +11,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
from tempest_lib import exceptions as lib_exc from tempest_lib import exceptions as lib_exc
@@ -29,7 +28,7 @@ class TestAuditTemplate(base.BaseInfraOptimTest):
def _assertExpected(self, expected, actual): def _assertExpected(self, expected, actual):
# Check if not expected keys/values exists in actual response body # Check if not expected keys/values exists in actual response body
for key, value in six.iteritems(expected): for key, value in expected.items():
if key not in ('created_at', 'updated_at', 'deleted_at'): if key not in ('created_at', 'updated_at', 'deleted_at'):
self.assertIn(key, actual) self.assertIn(key, actual)
self.assertEqual(value, actual[key]) self.assertEqual(value, actual[key])

View File

@@ -14,7 +14,6 @@ import functools
import json import json
import urllib import urllib
import six
from tempest.common import service_client from tempest.common import service_client
@@ -79,7 +78,7 @@ class InfraOptimClient(service_client.ServiceClient):
""" """
def get_change(kw, path='/'): def get_change(kw, path='/'):
for name, value in six.iteritems(kw): for name, value in kw.items():
if isinstance(value, dict): if isinstance(value, dict):
for ch in get_change(value, path + '%s/' % name): for ch in get_change(value, path + '%s/' % name):
yield ch yield ch

View File

@@ -53,7 +53,7 @@ def make_class_properties(cls):
for name, field in supercls.fields.items(): for name, field in supercls.fields.items():
if name not in cls.fields: if name not in cls.fields:
cls.fields[name] = field cls.fields[name] = field
for name, typefn in six.iteritems(cls.fields): for name, typefn in cls.fields.items():
def getter(self, name=name): def getter(self, name=name):
attrname = get_attrname(name) attrname = get_attrname(name)
@@ -541,7 +541,7 @@ def obj_to_primitive(obj):
return [obj_to_primitive(x) for x in obj] return [obj_to_primitive(x) for x in obj]
elif isinstance(obj, WatcherObject): elif isinstance(obj, WatcherObject):
result = {} result = {}
for key, value in six.iteritems(obj): for key, value in obj.items():
result[key] = obj_to_primitive(value) result[key] = obj_to_primitive(value)
return result return result
else: else:

View File

@@ -18,7 +18,6 @@ Utils for testing the API service.
import datetime import datetime
import json import json
import six
from watcher.api.controllers.v1 import action as action_ctrl from watcher.api.controllers.v1 import action as action_ctrl
from watcher.api.controllers.v1 import action_plan as action_plan_ctrl from watcher.api.controllers.v1 import action_plan as action_plan_ctrl
from watcher.api.controllers.v1 import audit as audit_ctrl from watcher.api.controllers.v1 import audit as audit_ctrl
@@ -78,7 +77,7 @@ def remove_internal(values, internal):
# NOTE(yuriyz): internal attributes should not be posted, except uuid # NOTE(yuriyz): internal attributes should not be posted, except uuid
int_attr = [attr.lstrip('/') for attr in internal if attr != '/uuid'] int_attr = [attr.lstrip('/') for attr in internal if attr != '/uuid']
return dict( return dict(
(k, v) for (k, v) in six.iteritems(values) if k not in int_attr (k, v) for (k, v) in values.items() if k not in int_attr
) )

View File

@@ -24,7 +24,6 @@ from oslo_log import log
from oslotest import base from oslotest import base
import pecan import pecan
from pecan import testing from pecan import testing
import six
import testscenarios import testscenarios
from watcher.common import context as watcher_context from watcher.common import context as watcher_context
@@ -102,7 +101,7 @@ class TestCase(BaseTestCase):
def config(self, **kw): def config(self, **kw):
"""Override config options for a test.""" """Override config options for a test."""
group = kw.pop('group', None) group = kw.pop('group', None)
for k, v in six.iteritems(kw): for k, v in kw.items():
CONF.set_override(k, v, group, enforce_type=True) CONF.set_override(k, v, group, enforce_type=True)
def path_get(self, project_file=None): def path_get(self, project_file=None):