From a00b8d844da46184ee20898dbc311cee8291411e Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Fri, 9 Dec 2016 10:59:00 +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: I9f8f2c35f0d45d866076507a3a167aaafb8382e5 --- keystoneauth1/exceptions/http.py | 4 +--- keystoneauth1/identity/base.py | 2 +- keystoneauth1/session.py | 4 ++-- keystoneauth1/tests/unit/identity/test_identity_common.py | 2 +- keystoneauth1/tests/unit/loading/utils.py | 3 +-- keystoneauth1/tests/unit/test_fixtures.py | 4 +--- keystoneauth1/tests/unit/test_session.py | 4 ++-- keystoneauth1/tests/unit/utils.py | 3 +-- 8 files changed, 10 insertions(+), 16 deletions(-) diff --git a/keystoneauth1/exceptions/http.py b/keystoneauth1/exceptions/http.py index 6f725ed7..f76afc24 100644 --- a/keystoneauth1/exceptions/http.py +++ b/keystoneauth1/exceptions/http.py @@ -21,8 +21,6 @@ import inspect import sys -import six - from keystoneauth1.exceptions import base @@ -380,7 +378,7 @@ class HttpVersionNotSupported(HttpServerError): # _code_map contains all the classes that have http_status attribute. _code_map = dict( (getattr(obj, 'http_status', 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, 'http_status', False) ) diff --git a/keystoneauth1/identity/base.py b/keystoneauth1/identity/base.py index bfe253fc..11bdff2b 100644 --- a/keystoneauth1/identity/base.py +++ b/keystoneauth1/identity/base.py @@ -357,7 +357,7 @@ class BaseIdentityPlugin(plugin.BaseAuthPlugin): hasher = hashlib.sha256() - for k, v in sorted(six.iteritems(elements)): + for k, v in sorted(elements.items()): if v is not None: # NOTE(jamielennox): in python3 you need to pass bytes to hash if isinstance(k, six.string_types): diff --git a/keystoneauth1/session.py b/keystoneauth1/session.py index 087a34b1..4b38018c 100644 --- a/keystoneauth1/session.py +++ b/keystoneauth1/session.py @@ -326,7 +326,7 @@ class Session(object): string_parts.append(url) if headers: - for header in six.iteritems(headers): + for header in headers.items(): string_parts.append('-H "%s: %s"' % self._process_header(header)) if json: @@ -363,7 +363,7 @@ class Session(object): if status_code: string_parts.append('[%s]' % status_code) if headers: - for header in six.iteritems(headers): + for header in headers.items(): string_parts.append('%s: %s' % self._process_header(header)) if text: string_parts.append('\nRESP BODY: %s\n' % text) diff --git a/keystoneauth1/tests/unit/identity/test_identity_common.py b/keystoneauth1/tests/unit/identity/test_identity_common.py index a71565d1..42741cd6 100644 --- a/keystoneauth1/tests/unit/identity/test_identity_common.py +++ b/keystoneauth1/tests/unit/identity/test_identity_common.py @@ -613,7 +613,7 @@ class GenericAuthPluginTests(utils.TestCase): self.assertEqual(text, resp.text) - for k, v in six.iteritems(self.auth.headers): + for k, v in self.auth.headers.items(): self.assertRequestHeaderEqual(k, v) self.assertIsNone(self.session.get_token()) diff --git a/keystoneauth1/tests/unit/loading/utils.py b/keystoneauth1/tests/unit/loading/utils.py index e8958085..04b94efe 100644 --- a/keystoneauth1/tests/unit/loading/utils.py +++ b/keystoneauth1/tests/unit/loading/utils.py @@ -14,7 +14,6 @@ import functools import uuid import mock -import six from keystoneauth1 import loading from keystoneauth1.loading import base @@ -37,7 +36,7 @@ class TestCase(utils.TestCase): 'a_bool': a_bool} def assertTestVals(self, plugin, vals=TEST_VALS): - for k, v in six.iteritems(vals): + for k, v in vals.items(): self.assertEqual(v, plugin[k]) diff --git a/keystoneauth1/tests/unit/test_fixtures.py b/keystoneauth1/tests/unit/test_fixtures.py index 81996698..cded4caa 100644 --- a/keystoneauth1/tests/unit/test_fixtures.py +++ b/keystoneauth1/tests/unit/test_fixtures.py @@ -12,8 +12,6 @@ import uuid -import six - from keystoneauth1 import fixture from keystoneauth1.tests.unit import utils @@ -287,7 +285,7 @@ class V3TokenTests(utils.TestCase): # the endpoint content below easier. self.assertTrue(endpoint.pop('id')) - for interface, url in six.iteritems(endpoints): + for interface, url in endpoints.items(): endpoint = {'interface': interface, 'url': url, 'region': region, 'region_id': region} self.assertIn(endpoint, service['endpoints']) diff --git a/keystoneauth1/tests/unit/test_session.py b/keystoneauth1/tests/unit/test_session.py index de4c564a..70e49875 100644 --- a/keystoneauth1/tests/unit/test_session.py +++ b/keystoneauth1/tests/unit/test_session.py @@ -206,13 +206,13 @@ class SessionTests(utils.TestCase): self.assertIn(body, self.logger.output) self.assertIn("'%s'" % data, self.logger.output) - for k, v in six.iteritems(headers): + for k, v in headers.items(): self.assertIn(k, self.logger.output) self.assertIn(v, self.logger.output) # Assert that response headers contains actual values and # only debug logs has been masked - for k, v in six.iteritems(security_headers): + for k, v in security_headers.items(): self.assertIn('%s: {SHA1}' % k, self.logger.output) self.assertEqual(v, resp.headers[k]) self.assertNotIn(v, self.logger.output) diff --git a/keystoneauth1/tests/unit/utils.py b/keystoneauth1/tests/unit/utils.py index 1aef9da3..76e6b9c3 100644 --- a/keystoneauth1/tests/unit/utils.py +++ b/keystoneauth1/tests/unit/utils.py @@ -18,7 +18,6 @@ import uuid import fixtures import requests from requests_mock.contrib import fixture -import six from six.moves.urllib import parse as urlparse import testtools @@ -98,7 +97,7 @@ class TestCase(testtools.TestCase): parts = urlparse.urlparse(self.requests_mock.last_request.url) qs = urlparse.parse_qs(parts.query, keep_blank_values=True) - for k, v in six.iteritems(kwargs): + for k, v in kwargs.items(): self.assertIn(k, qs) self.assertIn(v, qs[k])