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: I18a6890935ebdbb589269379f21a0dd47d07eb3a
This commit is contained in:
parent
cfd3373086
commit
46b9e429a2
|
@ -52,14 +52,14 @@ def getid(obj):
|
|||
|
||||
def filter_none(**kwargs):
|
||||
"""Remove any entries from a dictionary where the value is None."""
|
||||
return dict((k, v) for k, v in six.iteritems(kwargs) if v is not None)
|
||||
return dict((k, v) for k, v in kwargs.items() if v is not None)
|
||||
|
||||
|
||||
def filter_kwargs(f):
|
||||
@functools.wraps(f)
|
||||
def func(*args, **kwargs):
|
||||
new_kwargs = {}
|
||||
for key, ref in six.iteritems(kwargs):
|
||||
for key, ref in kwargs.items():
|
||||
if ref is None:
|
||||
# drop null values
|
||||
continue
|
||||
|
@ -481,7 +481,7 @@ class Resource(object):
|
|||
return None
|
||||
|
||||
def _add_details(self, info):
|
||||
for (k, v) in six.iteritems(info):
|
||||
for (k, v) in info.items():
|
||||
try:
|
||||
try:
|
||||
setattr(self, k, v)
|
||||
|
|
|
@ -218,7 +218,7 @@ class Ec2Signer(object):
|
|||
# - the Authorization header (SignedHeaders key)
|
||||
# - the X-Amz-SignedHeaders query parameter
|
||||
headers_lower = dict((k.lower().strip(), v.strip())
|
||||
for (k, v) in six.iteritems(headers))
|
||||
for (k, v) in headers.items())
|
||||
|
||||
# Boto versions < 2.9.3 strip the port component of the host:port
|
||||
# header, so detect the user-agent via the header and strip the
|
||||
|
|
|
@ -16,7 +16,6 @@ import warnings
|
|||
from debtcollector import removals
|
||||
from keystoneauth1 import plugin
|
||||
from positional import positional
|
||||
import six
|
||||
|
||||
from keystoneclient import _discover
|
||||
from keystoneclient import exceptions
|
||||
|
@ -300,7 +299,7 @@ class Discover(_discover.Discover):
|
|||
raise exceptions.DiscoveryFailure(msg)
|
||||
|
||||
# kwargs should take priority over stored kwargs.
|
||||
for k, v in six.iteritems(self._client_kwargs):
|
||||
for k, v in self._client_kwargs.items():
|
||||
kwargs.setdefault(k, v)
|
||||
|
||||
# restore the url to either auth_url or endpoint depending on what
|
||||
|
|
|
@ -201,7 +201,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))
|
||||
|
||||
|
@ -249,7 +249,7 @@ class Session(object):
|
|||
'RESP:',
|
||||
'[%s]' % response.status_code
|
||||
]
|
||||
for header in six.iteritems(response.headers):
|
||||
for header in response.headers.items():
|
||||
string_parts.append('%s: %s' % self._process_header(header))
|
||||
string_parts.append('\nRESP BODY: %s\n' % strutils.mask_password(text))
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient.tests.unit import utils
|
||||
|
||||
|
@ -23,7 +21,7 @@ class FakeResponse(object):
|
|||
json_data = {}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
for key, value in six.iteritems(kwargs):
|
||||
for key, value in kwargs.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
def json(self):
|
||||
|
|
|
@ -461,7 +461,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)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from keystoneclient.tests.unit.auth import utils
|
||||
|
||||
|
@ -39,7 +38,7 @@ class TestOtherLoading(utils.TestCase):
|
|||
|
||||
self.assertEqual(set(vals), set(called_opts))
|
||||
|
||||
for k, v in six.iteritems(vals):
|
||||
for k, v in vals.items():
|
||||
# replace - to _ because it's the dest used to create kwargs
|
||||
self.assertEqual(v, p[k.replace('-', '_')])
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import uuid
|
|||
from keystoneauth1 import fixture
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
|
||||
from keystoneclient import access
|
||||
from keystoneclient.auth import base
|
||||
|
@ -88,7 +87,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])
|
||||
|
||||
|
||||
|
|
|
@ -703,7 +703,7 @@ class Examples(fixtures.Fixture):
|
|||
self.TOKEN_RESPONSES[self.SIGNED_v3_TOKEN_SCOPED_KEY])
|
||||
|
||||
self.JSON_TOKEN_RESPONSES = dict([(k, jsonutils.dumps(v)) for k, v in
|
||||
six.iteritems(self.TOKEN_RESPONSES)])
|
||||
self.TOKEN_RESPONSES.items()])
|
||||
|
||||
|
||||
EXAMPLES_RESOURCE = testresources.FixtureResource(Examples())
|
||||
|
|
|
@ -243,7 +243,7 @@ class AvailableVersionsTests(utils.TestCase):
|
|||
'cinder': jsonutils.dumps(CINDER_EXAMPLES),
|
||||
'glance': jsonutils.dumps(GLANCE_EXAMPLES)}
|
||||
|
||||
for path, text in six.iteritems(examples):
|
||||
for path, text in examples.items():
|
||||
url = "%s%s" % (BASE_URL, path)
|
||||
|
||||
self.requests_mock.get(url, status_code=300, text=text)
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from keystoneclient import fixture
|
||||
from keystoneclient.tests.unit import utils
|
||||
|
@ -246,7 +245,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'])
|
||||
|
|
|
@ -202,10 +202,10 @@ class BasicRequestTests(utils.TestCase):
|
|||
|
||||
self.request(headers=headers)
|
||||
|
||||
for k, v in six.iteritems(headers):
|
||||
for k, v in headers.items():
|
||||
self.assertRequestHeaderEqual(k, v)
|
||||
|
||||
for header in six.iteritems(headers):
|
||||
for header in headers.items():
|
||||
self.assertThat(self.logger_message.getvalue(),
|
||||
matchers.Contains('-H "%s: %s"' % header))
|
||||
|
||||
|
|
|
@ -171,13 +171,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)
|
||||
|
|
|
@ -19,7 +19,6 @@ from oslo_serialization import jsonutils
|
|||
import requests
|
||||
import requests_mock
|
||||
from requests_mock.contrib import fixture
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
import testscenarios
|
||||
import testtools
|
||||
|
@ -97,7 +96,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])
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import json
|
|||
import uuid
|
||||
|
||||
from keystoneauth1 import fixture
|
||||
import six
|
||||
|
||||
from keystoneauth1 import session as auth_session
|
||||
from keystoneclient.auth import token_endpoint
|
||||
|
@ -207,7 +206,7 @@ class KeystoneClientTest(utils.TestCase):
|
|||
|
||||
cl = client.Client(session=sess, **opts)
|
||||
|
||||
for k, v in six.iteritems(opts):
|
||||
for k, v in opts.items():
|
||||
self.assertEqual(v, getattr(cl._adapter, k))
|
||||
|
||||
self.assertEqual('identity', cl._adapter.service_type)
|
||||
|
|
|
@ -14,7 +14,6 @@ import copy
|
|||
import json
|
||||
import uuid
|
||||
|
||||
import six
|
||||
|
||||
from keystoneauth1 import session as auth_session
|
||||
from keystoneclient.auth import token_endpoint
|
||||
|
@ -257,7 +256,7 @@ class KeystoneClientTest(utils.TestCase):
|
|||
|
||||
cl = client.Client(session=sess, **opts)
|
||||
|
||||
for k, v in six.iteritems(opts):
|
||||
for k, v in opts.items():
|
||||
self.assertEqual(v, getattr(cl._adapter, k))
|
||||
|
||||
self.assertEqual('identity', cl._adapter.service_type)
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
import uuid
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from keystoneclient.tests.unit import client_fixtures
|
||||
|
@ -301,7 +300,7 @@ class CrudTests(object):
|
|||
|
||||
qs_args = self.requests_mock.last_request.qs
|
||||
qs_args_expected = expected_query or filter_kwargs
|
||||
for key, value in six.iteritems(qs_args_expected):
|
||||
for key, value in qs_args_expected.items():
|
||||
self.assertIn(key, qs_args)
|
||||
# The querystring value is a list. Note we convert the value to a
|
||||
# string and lower, as the query string is always a string and the
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
# under the License.
|
||||
|
||||
from keystoneauth1 import plugin
|
||||
import six
|
||||
from six.moves import urllib
|
||||
|
||||
from keystoneclient import base
|
||||
|
@ -92,7 +91,7 @@ class TenantManager(base.ManagerWithFind):
|
|||
"enabled": enabled}}
|
||||
|
||||
# Allow Extras Passthru and ensure we don't clobber primary arguments.
|
||||
for k, v in six.iteritems(kwargs):
|
||||
for k, v in kwargs.items():
|
||||
if k not in params['tenant']:
|
||||
params['tenant'][k] = v
|
||||
|
||||
|
@ -142,7 +141,7 @@ class TenantManager(base.ManagerWithFind):
|
|||
body['tenant']['description'] = description
|
||||
|
||||
# Allow Extras Passthru and ensure we don't clobber primary arguments.
|
||||
for k, v in six.iteritems(kwargs):
|
||||
for k, v in kwargs.items():
|
||||
if k not in body['tenant']:
|
||||
body['tenant'][k] = v
|
||||
|
||||
|
|
Loading…
Reference in New Issue