From a25d4fe59aac92eece3f080f16fdca7ffc453064 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Mon, 24 Jun 2013 08:32:05 -0500 Subject: [PATCH] python3: Compatibility for iteritems differences In python3 dict.iteritems(), dict.iterkeys(), and dict.itervalues() are no longer supported. So use six.iteritems() where it is appropriate. Change-Id: I8b07dc2a89d790ec275d45f859e1644e9b00c837 Signed-off-by: Chuck Short --- novaclient/auth_plugin.py | 4 +++- novaclient/base.py | 5 ++++- novaclient/utils.py | 3 ++- novaclient/v1_1/security_groups.py | 4 +++- novaclient/v1_1/servers.py | 4 +++- novaclient/v1_1/volumes.py | 4 +++- requirements.txt | 1 + 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/novaclient/auth_plugin.py b/novaclient/auth_plugin.py index 39da86aa6..843489788 100644 --- a/novaclient/auth_plugin.py +++ b/novaclient/auth_plugin.py @@ -17,6 +17,8 @@ import logging import pkg_resources +import six + from novaclient import exceptions from novaclient import utils @@ -49,7 +51,7 @@ def load_auth_system_opts(parser): This function will try to populate the parser with options from the available plugins. """ - for name, auth_plugin in _discovered_plugins.iteritems(): + for name, auth_plugin in six.iteritems(_discovered_plugins): add_opts_fn = getattr(auth_plugin, "add_opts", None) if add_opts_fn: group = parser.add_argument_group("Auth-system '%s' options" % diff --git a/novaclient/base.py b/novaclient/base.py index c97c104c4..3cbc65ed5 100644 --- a/novaclient/base.py +++ b/novaclient/base.py @@ -23,6 +23,9 @@ import abc import contextlib import hashlib import os + +import six + from novaclient import exceptions from novaclient import utils @@ -315,7 +318,7 @@ class Resource(object): return None def _add_details(self, info): - for (k, v) in info.iteritems(): + for (k, v) in six.iteritems(info): try: setattr(self, k, v) self._info[k] = v diff --git a/novaclient/utils.py b/novaclient/utils.py index d1e08e961..9badbe84a 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -6,6 +6,7 @@ import textwrap import uuid import prettytable +import six from novaclient import exceptions from novaclient.openstack.common import strutils @@ -172,7 +173,7 @@ def print_list(objs, fields, formatters={}, sortby_index=None): def print_dict(d, dict_property="Property", dict_value="Value", wrap=0): pt = prettytable.PrettyTable([dict_property, dict_value], caching=False) pt.align = 'l' - for k, v in d.iteritems(): + for k, v in six.iteritems(d): # convert dict to str to check length if isinstance(v, dict): v = str(v) diff --git a/novaclient/v1_1/security_groups.py b/novaclient/v1_1/security_groups.py index d0778634a..85e67de7b 100644 --- a/novaclient/v1_1/security_groups.py +++ b/novaclient/v1_1/security_groups.py @@ -19,6 +19,8 @@ Security group interface (1.1 extension). import urllib +import six + from novaclient import base @@ -87,7 +89,7 @@ class SecurityGroupManager(base.ManagerWithFind): """ search_opts = search_opts or {} - qparams = dict((k, v) for (k, v) in search_opts.iteritems() if v) + qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v) query_string = '?%s' % urllib.urlencode(qparams) if qparams else '' diff --git a/novaclient/v1_1/servers.py b/novaclient/v1_1/servers.py index 260d81806..02a7aa338 100644 --- a/novaclient/v1_1/servers.py +++ b/novaclient/v1_1/servers.py @@ -21,6 +21,8 @@ Server interface. import urllib +import six + from novaclient import base from novaclient import crypto from novaclient.v1_1 import base as local_base @@ -365,7 +367,7 @@ class ServerManager(local_base.BootingManagerWithFind): qparams = {} - for opt, val in search_opts.iteritems(): + for opt, val in six.iteritems(search_opts): if val: qparams[opt] = val diff --git a/novaclient/v1_1/volumes.py b/novaclient/v1_1/volumes.py index 7e371ac7b..b17457068 100644 --- a/novaclient/v1_1/volumes.py +++ b/novaclient/v1_1/volumes.py @@ -19,6 +19,8 @@ Volume interface (1.1 extension). import urllib +import six + from novaclient import base @@ -86,7 +88,7 @@ class VolumeManager(base.ManagerWithFind): """ search_opts = search_opts or {} - qparams = dict((k, v) for (k, v) in search_opts.iteritems() if v) + qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v) query_string = '?%s' % urllib.urlencode(qparams) if qparams else '' diff --git a/requirements.txt b/requirements.txt index f7deffed1..3390adde9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ iso8601>=0.1.4 prettytable>=0.6,<0.8 requests>=0.8 simplejson +six