diff --git a/horizon/middleware.py b/horizon/middleware.py index 80df26855e..07235e6d21 100644 --- a/horizon/middleware.py +++ b/horizon/middleware.py @@ -34,6 +34,8 @@ from django.utils.encoding import iri_to_uri # noqa from django.utils import timezone from django.utils.translation import ugettext_lazy as _ +import six + from horizon import exceptions from horizon.utils import functions as utils @@ -89,7 +91,7 @@ class HorizonMiddleware(object): if max_cookie_size is not None and session_key is not None: cookie_size = sum(( len(key) + len(value) - for key, value in request.COOKIES.iteritems() + for key, value in six.iteritems(request.COOKIES) )) if cookie_size >= max_cookie_size: LOG.error( @@ -171,9 +173,9 @@ class HorizonMiddleware(object): else: redirect_response = http.HttpResponse() # Copy cookies from HttpResponseRedirect towards HttpResponse - for cookie_name, cookie in response.cookies.iteritems(): + for cookie_name, cookie in six.iteritems(response.cookies): cookie_kwargs = dict(( - (key, value) for key, value in cookie.iteritems() + (key, value) for key, value in six.iteritems(cookie) if key in ('max_age', 'expires', 'path', 'domain', 'secure', 'httponly', 'logout_reason') and value )) diff --git a/horizon/utils/memoized.py b/horizon/utils/memoized.py index c9ba00b862..cc9a1f57c4 100644 --- a/horizon/utils/memoized.py +++ b/horizon/utils/memoized.py @@ -16,6 +16,8 @@ import functools import warnings import weakref +import six + class UnhashableKeyWarning(RuntimeWarning): """Raised when trying to memoize a function with an unhashable argument.""" @@ -40,7 +42,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 kwargs.iteritems())) + for (key, value) in six.iteritems(kwargs))) return weak_args, weak_kwargs diff --git a/horizon/workflows/views.py b/horizon/workflows/views.py index ba1ca74e1a..8455c8071e 100644 --- a/horizon/workflows/views.py +++ b/horizon/workflows/views.py @@ -20,6 +20,8 @@ from django import http from django import shortcuts from django.views import generic +import six + from horizon import exceptions from horizon.forms.views import ADD_TO_FIELD_HEADER # noqa from horizon import messages @@ -151,7 +153,7 @@ class WorkflowView(generic.TemplateView): if not step.action.is_valid(): errors[step.slug] = dict( (field, [unicode(error) for error in errors]) - for (field, errors) in step.action.errors.iteritems()) + for (field, errors) in six.iteritems(step.action.errors)) return { 'has_errors': bool(errors), 'workflow_slug': workflow.slug, diff --git a/openstack_dashboard/dashboards/admin/aggregates/tables.py b/openstack_dashboard/dashboards/admin/aggregates/tables.py index 5cefae1005..99d9e258ac 100644 --- a/openstack_dashboard/dashboards/admin/aggregates/tables.py +++ b/openstack_dashboard/dashboards/admin/aggregates/tables.py @@ -13,6 +13,8 @@ from django.template import defaultfilters as filters from django.utils.translation import ugettext_lazy as _ +import six + from horizon import tables from openstack_dashboard import api @@ -74,7 +76,7 @@ def get_aggregate_hosts(aggregate): def get_metadata(aggregate): return [' = '.join([key, val]) for key, val - in aggregate.metadata.iteritems()] + in six.iteritems(aggregate.metadata)] def get_available(zone): diff --git a/openstack_dashboard/dashboards/project/stacks/forms.py b/openstack_dashboard/dashboards/project/stacks/forms.py index 8e754e14b0..a87c5c850e 100644 --- a/openstack_dashboard/dashboards/project/stacks/forms.py +++ b/openstack_dashboard/dashboards/project/stacks/forms.py @@ -16,6 +16,8 @@ import logging from django.utils.translation import ugettext_lazy as _ from django.views.decorators.debug import sensitive_variables # noqa +import six + from horizon import exceptions from horizon import forms from horizon import messages @@ -327,7 +329,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 data.iteritems() + params_list = [(k[prefix_length:], v) for (k, v) in six.iteritems(data) if k.startswith(self.param_prefix)] fields = { 'stack_name': data.get('stack_name'), @@ -369,7 +371,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 data.iteritems() + params_list = [(k[prefix_length:], v) for (k, v) in six.iteritems(data) if k.startswith(self.param_prefix)] stack_id = data.get('stack_id') diff --git a/openstack_dashboard/test/api_tests/nova_tests.py b/openstack_dashboard/test/api_tests/nova_tests.py index 79302a3e6f..c3f6d897d9 100644 --- a/openstack_dashboard/test/api_tests/nova_tests.py +++ b/openstack_dashboard/test/api_tests/nova_tests.py @@ -25,6 +25,7 @@ from django.test.utils import override_settings from mox import IsA # noqa from novaclient.v1_1 import servers +import six from openstack_dashboard import api from openstack_dashboard.test import helpers as test @@ -214,7 +215,7 @@ class ComputeApiTests(test.APITestCase): values = {"maxTotalCores": -1, "maxTotalInstances": 10} limits = self.mox.CreateMockAnything() limits.absolute = [] - for key, val in values.iteritems(): + for key, val in six.iteritems(values): limit = self.mox.CreateMockAnything() limit.name = key limit.value = val diff --git a/openstack_dashboard/utils/settings.py b/openstack_dashboard/utils/settings.py index c02245748d..07f284b530 100644 --- a/openstack_dashboard/utils/settings.py +++ b/openstack_dashboard/utils/settings.py @@ -16,6 +16,8 @@ import pkgutil from django.utils import importlib +import six + def import_submodules(module): """Import all submodules and make them available in a dict.""" @@ -38,7 +40,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 import_submodules(module).iteritems(): + for key, submodule in six.iteritems(import_submodules(module)): if hasattr(submodule, 'DASHBOARD'): dashboard = submodule.DASHBOARD config[dashboard].update(submodule.__dict__) @@ -49,7 +51,7 @@ def import_dashboard_config(modules): logging.warning("Skipping %s because it doesn't have DASHBOARD" ", PANEL or PANEL_GROUP defined.", submodule.__name__) - return sorted(config.iteritems(), + return sorted(six.iteritems(config), key=lambda c: c[1]['__name__'].rsplit('.', 1))