Replace six.iteritems(iter) with iter.items()

As mentioned in [1], we should avoid using six.iteritems(iter) to
achieve iterators. We can use iter.items() instead, as it will
return iterators in PY3 as well.

[1] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: Ieadd5fa69b3f6058c0641a5b96ef3e8e1e3f6cc2
This commit is contained in:
Cady_Chen 2016-12-12 11:42:39 +08:00
parent 39a35010e0
commit 51fe944449
12 changed files with 19 additions and 32 deletions

View File

@ -16,8 +16,6 @@ import functools
import warnings
import weakref
import six
class UnhashableKeyWarning(RuntimeWarning):
"""Raised when trying to memoize a function with an unhashable argument."""
@ -42,7 +40,7 @@ def _get_key(args, kwargs, remove_callback):
# Sort it, so that we don't depend on the order of keys.
weak_kwargs = tuple(sorted(
(key, _try_weakref(value, remove_callback))
for (key, value) in six.iteritems(kwargs)))
for (key, value) in kwargs.items()))
return weak_args, weak_kwargs

View File

@ -133,7 +133,7 @@ def _get_file_contents(from_data, files):
return
if isinstance(from_data, dict):
recurse_data = six.itervalues(from_data)
for key, value in six.iteritems(from_data):
for key, value in from_data.items():
if _ignore_if(key, value):
continue
if not value.startswith(('http://', 'https://')):

View File

@ -31,8 +31,6 @@ from openstack_dashboard.api.rest import urls
from openstack_dashboard.api.rest import utils as rest_utils
from openstack_dashboard.usage import quotas
import six
@urls.register
class Snapshots(generic.View):
@ -295,7 +293,7 @@ class RemoteConsoleInfo(generic.View):
except AttributeError:
httpnotimplemented = exceptions.HTTPNotImplemented
for con_type, api_call in six.iteritems(check_consoles):
for con_type, api_call in check_consoles.items():
try:
console = api_call(request, server_id)
# If not supported, don't log it to avoid lot of errors in case

View File

@ -14,8 +14,6 @@ from django.template import defaultfilters as filters
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
import six
from horizon import tables
from openstack_dashboard import api
@ -111,7 +109,7 @@ def get_aggregate_hosts(aggregate):
def get_metadata(aggregate):
return [' = '.join([key, val]) for key, val
in six.iteritems(aggregate.metadata)]
in aggregate.metadata.items()]
def get_available(zone):

View File

@ -16,7 +16,6 @@ import logging
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _
import six
from horizon import exceptions
@ -49,7 +48,7 @@ def get_console(request, console_type, instance):
except AttributeError:
httpnotimplemented = nova_exception.HTTPNotImplemented
for con_type, api_call in six.iteritems(check_consoles):
for con_type, api_call in check_consoles.items():
try:
console = api_call(request, instance.id)
# If not supported, don't log it to avoid lot of errors in case

View File

@ -27,7 +27,6 @@ from django.utils.translation import pgettext_lazy
from django.utils.translation import string_concat # noqa
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
import six
from horizon import conf
from horizon import exceptions
@ -998,7 +997,7 @@ def get_ips(instance):
template_name = 'project/instances/_instance_ips.html'
ip_groups = {}
for ip_group, addresses in six.iteritems(instance.addresses):
for ip_group, addresses in instance.addresses.items():
ip_groups[ip_group] = {}
ip_groups[ip_group]["floating"] = []
ip_groups[ip_group]["non_floating"] = []

View File

@ -17,7 +17,6 @@
# under the License.
import json
import six
from django.conf import settings
from django.core.urlresolvers import reverse
@ -99,10 +98,10 @@ class TranslationHelper(object):
self.port = dict(ports_choices)
self.port.update(dict(ports_status_choices))
# and turn all the keys into Uppercase for simple access
self.instance = {k.upper(): v for k, v in six.iteritems(self.instance)}
self.network = {k.upper(): v for k, v in six.iteritems(self.network)}
self.router = {k.upper(): v for k, v in six.iteritems(self.router)}
self.port = {k.upper(): v for k, v in six.iteritems(self.port)}
self.instance = {k.upper(): v for k, v in self.instance.items()}
self.network = {k.upper(): v for k, v in self.network.items()}
self.router = {k.upper(): v for k, v in self.router.items()}
self.port = {k.upper(): v for k, v in self.port.items()}
class NTAddInterfaceView(p_views.AddInterfaceView):

View File

@ -374,7 +374,7 @@ class CreateStackForm(forms.SelfHandlingForm):
@sensitive_variables('password')
def handle(self, request, data):
prefix_length = len(self.param_prefix)
params_list = [(k[prefix_length:], v) for (k, v) in six.iteritems(data)
params_list = [(k[prefix_length:], v) for (k, v) in data.items()
if k.startswith(self.param_prefix)]
fields = {
'stack_name': data.get('stack_name'),
@ -424,7 +424,7 @@ class EditStackForm(CreateStackForm):
@sensitive_variables('password')
def handle(self, request, data):
prefix_length = len(self.param_prefix)
params_list = [(k[prefix_length:], v) for (k, v) in six.iteritems(data)
params_list = [(k[prefix_length:], v) for (k, v) in data.items()
if k.startswith(self.param_prefix)]
stack_id = data.get('stack_id')
@ -461,7 +461,7 @@ class PreviewStackForm(CreateStackForm):
def handle(self, request, data):
prefix_length = len(self.param_prefix)
params_list = [(k[prefix_length:], v) for (k, v) in six.iteritems(data)
params_list = [(k[prefix_length:], v) for (k, v) in data.items()
if k.startswith(self.param_prefix)]
fields = {
'stack_name': data.get('stack_name'),

View File

@ -14,7 +14,6 @@
from django.conf import settings
from django.test.utils import override_settings
import six
import cinderclient as cinder_client
@ -298,7 +297,7 @@ class CinderApiTests(test.APITestCase):
limits = self.mox.CreateMockAnything()
limits.absolute = []
for key, val in six.iteritems(values):
for key, val in values.items():
limit = self.mox.CreateMockAnything()
limit.name = key
limit.value = val

View File

@ -27,7 +27,6 @@ from mox3.mox import IsA # noqa
from novaclient import exceptions as nova_exceptions
from novaclient.v2 import flavor_access as nova_flavor_access
from novaclient.v2 import servers
import six
from horizon import exceptions as horizon_exceptions
from openstack_dashboard import api
@ -256,7 +255,7 @@ class ComputeApiTests(test.APITestCase):
def _test_absolute_limits(self, values, expected_results):
limits = self.mox.CreateMockAnything()
limits.absolute = []
for key, val in six.iteritems(values):
for key, val in values.items():
limit = self.mox.CreateMockAnything()
limit.name = key
limit.value = val

View File

@ -15,7 +15,6 @@ import json
import types
from selenium.webdriver.common import by
import six
from openstack_dashboard.test.integration_tests import config
@ -311,7 +310,7 @@ class Navigation(object):
def rec(items, sub_menus):
if isinstance(items, dict):
for sub_menu, sub_item in six.iteritems(items):
for sub_menu, sub_item in items.items():
rec(sub_item, sub_menus + (sub_menu,))
elif isinstance(items, (list, tuple)):
# exclude ITEMS element from sub_menus

View File

@ -15,7 +15,6 @@ from importlib import import_module
import logging
import os
import pkgutil
import six
from horizon.utils import file_discovery
from openstack_dashboard import theme_settings
@ -42,7 +41,7 @@ def import_dashboard_config(modules):
"""Imports configuration from all the modules and merges it."""
config = collections.defaultdict(dict)
for module in modules:
for key, submodule in six.iteritems(import_submodules(module)):
for key, submodule in import_submodules(module).items():
if hasattr(submodule, 'DASHBOARD'):
dashboard = submodule.DASHBOARD
config[dashboard].update(submodule.__dict__)
@ -54,7 +53,7 @@ def import_dashboard_config(modules):
logging.warning("Skipping %s because it doesn't have DASHBOARD"
", PANEL, PANEL_GROUP, or FEATURE defined.",
submodule.__name__)
return sorted(six.iteritems(config),
return sorted(config.items(),
key=lambda c: c[1]['__name__'].rsplit('.', 1)[1])
@ -125,7 +124,7 @@ def update_dashboards(modules, horizon_config, installed_apps):
file_discovery.populate_horizon_config(horizon_config,
base_path)
add_exceptions = six.iteritems(config.get('ADD_EXCEPTIONS', {}))
add_exceptions = config.get('ADD_EXCEPTIONS', {}).items()
for category, exc_list in add_exceptions:
exceptions[category] = tuple(set(exceptions.get(category, ())
+ exc_list))