replace dict.iteritems() with six.iteritems(dict)

According to https://wiki.openstack.org/wiki/Python3 dict.iteritems()
should be replaced with six.iteritems(dict).

Change-Id: Ia2dcabbd071e1fcdf111ba83573785989a77aef0
This commit is contained in:
Christian Berendt 2014-05-26 12:05:34 +02:00
parent 09370e93f7
commit 6458dccb6f
7 changed files with 24 additions and 11 deletions

View File

@ -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
))

View File

@ -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

View File

@ -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,

View File

@ -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):

View File

@ -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
@ -336,7 +338,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'),
@ -380,7 +382,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')

View File

@ -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

View File

@ -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))