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
This commit is contained in:
parent
301ecb4bd8
commit
a00b8d844d
|
@ -21,8 +21,6 @@
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from keystoneauth1.exceptions import base
|
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 contains all the classes that have http_status attribute.
|
||||||
_code_map = dict(
|
_code_map = dict(
|
||||||
(getattr(obj, 'http_status', None), obj)
|
(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)
|
if inspect.isclass(obj) and getattr(obj, 'http_status', False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -357,7 +357,7 @@ class BaseIdentityPlugin(plugin.BaseAuthPlugin):
|
||||||
|
|
||||||
hasher = hashlib.sha256()
|
hasher = hashlib.sha256()
|
||||||
|
|
||||||
for k, v in sorted(six.iteritems(elements)):
|
for k, v in sorted(elements.items()):
|
||||||
if v is not None:
|
if v is not None:
|
||||||
# NOTE(jamielennox): in python3 you need to pass bytes to hash
|
# NOTE(jamielennox): in python3 you need to pass bytes to hash
|
||||||
if isinstance(k, six.string_types):
|
if isinstance(k, six.string_types):
|
||||||
|
|
|
@ -326,7 +326,7 @@ class Session(object):
|
||||||
string_parts.append(url)
|
string_parts.append(url)
|
||||||
|
|
||||||
if headers:
|
if headers:
|
||||||
for header in six.iteritems(headers):
|
for header in headers.items():
|
||||||
string_parts.append('-H "%s: %s"'
|
string_parts.append('-H "%s: %s"'
|
||||||
% self._process_header(header))
|
% self._process_header(header))
|
||||||
if json:
|
if json:
|
||||||
|
@ -363,7 +363,7 @@ class Session(object):
|
||||||
if status_code:
|
if status_code:
|
||||||
string_parts.append('[%s]' % status_code)
|
string_parts.append('[%s]' % status_code)
|
||||||
if headers:
|
if headers:
|
||||||
for header in six.iteritems(headers):
|
for header in headers.items():
|
||||||
string_parts.append('%s: %s' % self._process_header(header))
|
string_parts.append('%s: %s' % self._process_header(header))
|
||||||
if text:
|
if text:
|
||||||
string_parts.append('\nRESP BODY: %s\n' % text)
|
string_parts.append('\nRESP BODY: %s\n' % text)
|
||||||
|
|
|
@ -613,7 +613,7 @@ class GenericAuthPluginTests(utils.TestCase):
|
||||||
|
|
||||||
self.assertEqual(text, resp.text)
|
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.assertRequestHeaderEqual(k, v)
|
||||||
|
|
||||||
self.assertIsNone(self.session.get_token())
|
self.assertIsNone(self.session.get_token())
|
||||||
|
|
|
@ -14,7 +14,6 @@ import functools
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
|
||||||
|
|
||||||
from keystoneauth1 import loading
|
from keystoneauth1 import loading
|
||||||
from keystoneauth1.loading import base
|
from keystoneauth1.loading import base
|
||||||
|
@ -37,7 +36,7 @@ class TestCase(utils.TestCase):
|
||||||
'a_bool': a_bool}
|
'a_bool': a_bool}
|
||||||
|
|
||||||
def assertTestVals(self, plugin, vals=TEST_VALS):
|
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])
|
self.assertEqual(v, plugin[k])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from keystoneauth1 import fixture
|
from keystoneauth1 import fixture
|
||||||
from keystoneauth1.tests.unit import utils
|
from keystoneauth1.tests.unit import utils
|
||||||
|
|
||||||
|
@ -287,7 +285,7 @@ class V3TokenTests(utils.TestCase):
|
||||||
# the endpoint content below easier.
|
# the endpoint content below easier.
|
||||||
self.assertTrue(endpoint.pop('id'))
|
self.assertTrue(endpoint.pop('id'))
|
||||||
|
|
||||||
for interface, url in six.iteritems(endpoints):
|
for interface, url in endpoints.items():
|
||||||
endpoint = {'interface': interface, 'url': url,
|
endpoint = {'interface': interface, 'url': url,
|
||||||
'region': region, 'region_id': region}
|
'region': region, 'region_id': region}
|
||||||
self.assertIn(endpoint, service['endpoints'])
|
self.assertIn(endpoint, service['endpoints'])
|
||||||
|
|
|
@ -206,13 +206,13 @@ class SessionTests(utils.TestCase):
|
||||||
self.assertIn(body, self.logger.output)
|
self.assertIn(body, self.logger.output)
|
||||||
self.assertIn("'%s'" % data, 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(k, self.logger.output)
|
||||||
self.assertIn(v, self.logger.output)
|
self.assertIn(v, self.logger.output)
|
||||||
|
|
||||||
# Assert that response headers contains actual values and
|
# Assert that response headers contains actual values and
|
||||||
# only debug logs has been masked
|
# 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.assertIn('%s: {SHA1}' % k, self.logger.output)
|
||||||
self.assertEqual(v, resp.headers[k])
|
self.assertEqual(v, resp.headers[k])
|
||||||
self.assertNotIn(v, self.logger.output)
|
self.assertNotIn(v, self.logger.output)
|
||||||
|
|
|
@ -18,7 +18,6 @@ import uuid
|
||||||
import fixtures
|
import fixtures
|
||||||
import requests
|
import requests
|
||||||
from requests_mock.contrib import fixture
|
from requests_mock.contrib import fixture
|
||||||
import six
|
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ class TestCase(testtools.TestCase):
|
||||||
parts = urlparse.urlparse(self.requests_mock.last_request.url)
|
parts = urlparse.urlparse(self.requests_mock.last_request.url)
|
||||||
qs = urlparse.parse_qs(parts.query, keep_blank_values=True)
|
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(k, qs)
|
||||||
self.assertIn(v, qs[k])
|
self.assertIn(v, qs[k])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue