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
This commit is contained in:
parent
5ad01a5101
commit
070bde3e21
@ -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__))
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"] = []
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user