From 070bde3e21cb1b9df83c6b532b4046d418590723 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 13 Jul 2015 12:34:24 +0200 Subject: [PATCH] Replace dict.iteritems() with six.iteritems(dict) The iteritems() method of Python 2 dictionaries was renamed to items() on Python 3. The overhead of creating a temporary list for items() on Python 2 is negligible. Replace also dict.itervalues() with six.itervalues(dict) in horizon/test/utils.py. Partial-Implements: blueprint porting-python3 Change-Id: Ib2d62236be2620c4626099ce80e6c8a9397a4533 --- horizon/test/utils.py | 6 ++++-- .../content/data_processing/jobs/workflows/launch.py | 3 ++- openstack_dashboard/dashboards/admin/images/views.py | 7 ++++--- .../dashboards/project/instances/console.py | 3 ++- openstack_dashboard/dashboards/project/instances/tables.py | 3 ++- .../test/integration_tests/pages/navigation.py | 4 +++- openstack_dashboard/utils/settings.py | 3 ++- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/horizon/test/utils.py b/horizon/test/utils.py index a315eeba75..3b1a856f66 100644 --- a/horizon/test/utils.py +++ b/horizon/test/utils.py @@ -10,13 +10,15 @@ # License for the specific language governing permissions and limitations # under the License. +import six + class ObjDictWrapper(object): """ObjDictWrapper is a container that provides both dictionary-like and object-like attribute access. """ def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): + for key, value in six.iteritems(kwargs): setattr(self, key, value) def __getitem__(self, item): @@ -32,4 +34,4 @@ class ObjDictWrapper(object): return hasattr(self, item) def __iter__(self): - return iter(self.__dict__.itervalues()) + return iter(six.itervalues(self.__dict__)) diff --git a/openstack_dashboard/contrib/sahara/content/data_processing/jobs/workflows/launch.py b/openstack_dashboard/contrib/sahara/content/data_processing/jobs/workflows/launch.py index 495ced7a52..039b41d3ee 100644 --- a/openstack_dashboard/contrib/sahara/content/data_processing/jobs/workflows/launch.py +++ b/openstack_dashboard/contrib/sahara/content/data_processing/jobs/workflows/launch.py @@ -15,6 +15,7 @@ import json import logging from django.utils.translation import ugettext_lazy as _ +import six from horizon import exceptions from horizon import forms @@ -232,7 +233,7 @@ class JobConfigAction(workflows.Action): def clean_edp_configs(self, configs): edp_configs = {} - for key, value in configs.iteritems(): + for key, value in six.iteritems(configs): if key.startswith(self.EDP_PREFIX): edp_configs[key] = value for rmkey in edp_configs.keys(): diff --git a/openstack_dashboard/dashboards/admin/images/views.py b/openstack_dashboard/dashboards/admin/images/views.py index 485a062813..8ad26540dd 100644 --- a/openstack_dashboard/dashboards/admin/images/views.py +++ b/openstack_dashboard/dashboards/admin/images/views.py @@ -20,6 +20,7 @@ import json import logging from oslo_utils import units +import six from django import conf from django.core.urlresolvers import reverse @@ -170,7 +171,7 @@ class UpdateMetadataView(forms.ModalFormView): reserved_props = getattr(conf.settings, 'IMAGE_RESERVED_CUSTOM_PROPERTIES', []) image.properties = dict((k, v) - for (k, v) in image.properties.iteritems() + for (k, v) in six.iteritems(image.properties) if k not in reserved_props) context['existing_metadata'] = json.dumps(image.properties) args = (self.kwargs['id'],) @@ -195,7 +196,7 @@ class UpdateMetadataView(forms.ModalFormView): if hasattr(details, 'properties'): details.properties = dict( (k, v) - for (k, v) in details.properties.iteritems() + for (k, v) in six.iteritems(details.properties) if k not in reserved_props ) @@ -203,7 +204,7 @@ class UpdateMetadataView(forms.ModalFormView): for obj in details.objects: obj['properties'] = dict( (k, v) - for (k, v) in obj['properties'].iteritems() + for (k, v) in six.iteritems(obj['properties']) if k not in reserved_props ) diff --git a/openstack_dashboard/dashboards/project/instances/console.py b/openstack_dashboard/dashboards/project/instances/console.py index d865212b4c..e592539da6 100644 --- a/openstack_dashboard/dashboards/project/instances/console.py +++ b/openstack_dashboard/dashboards/project/instances/console.py @@ -16,6 +16,7 @@ import logging from django.utils.datastructures import SortedDict from django.utils.http import urlencode from django.utils.translation import ugettext_lazy as _ +import six from horizon import exceptions @@ -48,7 +49,7 @@ def get_console(request, console_type, instance): except AttributeError: httpnotimplemented = nova_exception.HTTPNotImplemented - for con_type, api_call in check_consoles.iteritems(): + for con_type, api_call in six.iteritems(check_consoles): try: console = api_call(request, instance.id) # If not supported, don't log it to avoid lot of errors in case diff --git a/openstack_dashboard/dashboards/project/instances/tables.py b/openstack_dashboard/dashboards/project/instances/tables.py index f682a4403b..16c34afc18 100644 --- a/openstack_dashboard/dashboards/project/instances/tables.py +++ b/openstack_dashboard/dashboards/project/instances/tables.py @@ -27,6 +27,7 @@ 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 @@ -853,7 +854,7 @@ def get_ips(instance): template_name = 'project/instances/_instance_ips.html' ip_groups = {} - for ip_group, addresses in instance.addresses.iteritems(): + for ip_group, addresses in six.iteritems(instance.addresses): ip_groups[ip_group] = {} ip_groups[ip_group]["floating"] = [] ip_groups[ip_group]["non_floating"] = [] diff --git a/openstack_dashboard/test/integration_tests/pages/navigation.py b/openstack_dashboard/test/integration_tests/pages/navigation.py index e4ae111e31..e77b65df5d 100644 --- a/openstack_dashboard/test/integration_tests/pages/navigation.py +++ b/openstack_dashboard/test/integration_tests/pages/navigation.py @@ -13,6 +13,8 @@ import importlib import types +import six + class Navigation(object): """Provide basic navigation among pages. @@ -296,7 +298,7 @@ class Navigation(object): def rec(items, sub_menus): if isinstance(items, dict): - for sub_menu, sub_item in items.iteritems(): + for sub_menu, sub_item in six.iteritems(items): rec(sub_item, sub_menus + (sub_menu,)) elif isinstance(items, tuple): # exclude ITEMS element from sub_menus diff --git a/openstack_dashboard/utils/settings.py b/openstack_dashboard/utils/settings.py index ad673c6e15..f0b3e02846 100644 --- a/openstack_dashboard/utils/settings.py +++ b/openstack_dashboard/utils/settings.py @@ -123,7 +123,8 @@ def update_dashboards(modules, horizon_config, installed_apps): base_path = os.path.join(module.__path__[0], 'static/') fd.populate_horizon_config(horizon_config, base_path) - for category, exc_list in config.get('ADD_EXCEPTIONS', {}).iteritems(): + add_exceptions = six.iteritems(config.get('ADD_EXCEPTIONS', {})) + for category, exc_list in add_exceptions: exceptions[category] = tuple(set(exceptions.get(category, ()) + exc_list))