Python 3 Refactoring: Replace six.iteritems() with the preferred items()
With Python3, the iteritems() method has been removed from dictionarys. This leaves us with two options: 1) replace with six.iteritems(dictionary) 2) replace with dictionary.items() The OpenStack Python 3 coders have documented their preference, and we should follow it. Their preference is dictionary.items() Change-Id: I2e27819404ae071bd21bfe4555e50dc8df9c65aa Partially-Implements: blueprint barbican-py3
This commit is contained in:
parent
b7d988027c
commit
11cb5629f6
@ -21,7 +21,6 @@ import pkgutil
|
||||
from oslo_policy import policy
|
||||
from oslo_serialization import jsonutils as json
|
||||
import pecan
|
||||
import six
|
||||
|
||||
from barbican.common import config
|
||||
from barbican.common import exception
|
||||
@ -130,7 +129,7 @@ def get_items(obj):
|
||||
|
||||
@get_items.register(dict)
|
||||
def _json_object(obj):
|
||||
return six.iteritems(obj)
|
||||
return obj.items()
|
||||
|
||||
|
||||
@get_items.register(list)
|
||||
|
@ -18,7 +18,6 @@ Barbican middleware modules.
|
||||
"""
|
||||
import sys
|
||||
|
||||
import six
|
||||
import webob.dec
|
||||
|
||||
from barbican.common import utils
|
||||
@ -85,7 +84,7 @@ class Debug(Middleware):
|
||||
resp = req.get_response(self.application)
|
||||
|
||||
LOG.debug(("*" * 40) + " RESPONSE HEADERS")
|
||||
for (key, value) in six.iteritems(resp.headers):
|
||||
for (key, value) in resp.headers.items():
|
||||
LOG.debug('%s=%s', key, value)
|
||||
LOG.debug(' ')
|
||||
|
||||
|
@ -133,7 +133,7 @@ class ModelBase(object):
|
||||
|
||||
def update(self, values):
|
||||
"""dict.update() behaviour."""
|
||||
for k, v in six.iteritems(values):
|
||||
for k, v in values.items():
|
||||
self[k] = v
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
|
@ -17,7 +17,6 @@ import uuid
|
||||
import mock
|
||||
import oslo_messaging
|
||||
from oslo_service import service
|
||||
import six
|
||||
|
||||
from barbican.common import config
|
||||
from barbican import queue
|
||||
@ -36,7 +35,7 @@ class UtilMixin(object):
|
||||
|
||||
def revert_overrides(self):
|
||||
'''Reverts configuration override values after test end.'''
|
||||
for k, v in six.iteritems(self.overrides):
|
||||
for k, v in self.overrides.items():
|
||||
value, group = v
|
||||
self.conf.set_override(k, value, group)
|
||||
|
||||
@ -45,7 +44,7 @@ class UtilMixin(object):
|
||||
self.addCleanup(self.revert_overrides)
|
||||
|
||||
def opt_in_group(self, group, **kw):
|
||||
for k, v in six.iteritems(kw):
|
||||
for k, v in kw.items():
|
||||
# add to local overrides if its not already set
|
||||
# we want to keep the original value from first override
|
||||
dict_value = self.overrides.get(k)
|
||||
|
@ -312,7 +312,7 @@ def construct_new_test_function(original_func, name, build_params):
|
||||
argdefs=six.get_function_defaults(original_func)
|
||||
)
|
||||
|
||||
for key, val in six.iteritems(original_func.__dict__):
|
||||
for key, val in original_func.__dict__.items():
|
||||
if key != 'build_data':
|
||||
new_func.__dict__[key] = val
|
||||
|
||||
@ -335,7 +335,7 @@ def process_parameterized_function(name, func_obj, build_data):
|
||||
to_remove = []
|
||||
to_add = []
|
||||
|
||||
for subtest_name, params in six.iteritems(build_data):
|
||||
for subtest_name, params in build_data.items():
|
||||
# Build new test function
|
||||
func_name = '{0}_{1}'.format(name, subtest_name)
|
||||
new_func = construct_new_test_function(func_obj, func_name, params)
|
||||
@ -357,7 +357,7 @@ def parameterized_test_case(cls):
|
||||
"""
|
||||
tests_to_remove = []
|
||||
tests_to_add = []
|
||||
for key, val in six.iteritems(vars(cls)):
|
||||
for key, val in vars(cls).items():
|
||||
# Only process tests with build data on them
|
||||
if key.startswith('test_') and val.__dict__.get('build_data'):
|
||||
to_remove, to_add = process_parameterized_function(
|
||||
|
@ -16,8 +16,6 @@ limitations under the License.
|
||||
import json
|
||||
import logging
|
||||
|
||||
import six
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -64,7 +62,7 @@ class BaseModel(object):
|
||||
resulting_dict = dictionary.copy()
|
||||
|
||||
# Dumping the keys to a list as we'll be changing the dict size
|
||||
empty_keys = [k for k, v in six.iteritems(dictionary) if v is None]
|
||||
empty_keys = [k for k, v in dictionary.items() if v is None]
|
||||
for k in empty_keys:
|
||||
del resulting_dict[k]
|
||||
return resulting_dict
|
||||
|
Loading…
Reference in New Issue
Block a user