Browse Source

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 <chuck.short@canonical.com>
Chuck Short 5 years ago
parent
commit
a25d4fe59a

+ 3
- 1
novaclient/auth_plugin.py View File

@@ -17,6 +17,8 @@
17 17
 import logging
18 18
 import pkg_resources
19 19
 
20
+import six
21
+
20 22
 from novaclient import exceptions
21 23
 from novaclient import utils
22 24
 
@@ -49,7 +51,7 @@ def load_auth_system_opts(parser):
49 51
     This function will try to populate the parser with options from the
50 52
     available plugins.
51 53
     """
52
-    for name, auth_plugin in _discovered_plugins.iteritems():
54
+    for name, auth_plugin in six.iteritems(_discovered_plugins):
53 55
         add_opts_fn = getattr(auth_plugin, "add_opts", None)
54 56
         if add_opts_fn:
55 57
             group = parser.add_argument_group("Auth-system '%s' options" %

+ 4
- 1
novaclient/base.py View File

@@ -23,6 +23,9 @@ import abc
23 23
 import contextlib
24 24
 import hashlib
25 25
 import os
26
+
27
+import six
28
+
26 29
 from novaclient import exceptions
27 30
 from novaclient import utils
28 31
 
@@ -315,7 +318,7 @@ class Resource(object):
315 318
         return None
316 319
 
317 320
     def _add_details(self, info):
318
-        for (k, v) in info.iteritems():
321
+        for (k, v) in six.iteritems(info):
319 322
             try:
320 323
                 setattr(self, k, v)
321 324
                 self._info[k] = v

+ 2
- 1
novaclient/utils.py View File

@@ -6,6 +6,7 @@ import textwrap
6 6
 import uuid
7 7
 
8 8
 import prettytable
9
+import six
9 10
 
10 11
 from novaclient import exceptions
11 12
 from novaclient.openstack.common import strutils
@@ -172,7 +173,7 @@ def print_list(objs, fields, formatters={}, sortby_index=None):
172 173
 def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
173 174
     pt = prettytable.PrettyTable([dict_property, dict_value], caching=False)
174 175
     pt.align = 'l'
175
-    for k, v in d.iteritems():
176
+    for k, v in six.iteritems(d):
176 177
         # convert dict to str to check length
177 178
         if isinstance(v, dict):
178 179
             v = str(v)

+ 3
- 1
novaclient/v1_1/security_groups.py View File

@@ -19,6 +19,8 @@ Security group interface (1.1 extension).
19 19
 
20 20
 import urllib
21 21
 
22
+import six
23
+
22 24
 from novaclient import base
23 25
 
24 26
 
@@ -87,7 +89,7 @@ class SecurityGroupManager(base.ManagerWithFind):
87 89
         """
88 90
         search_opts = search_opts or {}
89 91
 
90
-        qparams = dict((k, v) for (k, v) in search_opts.iteritems() if v)
92
+        qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v)
91 93
 
92 94
         query_string = '?%s' % urllib.urlencode(qparams) if qparams else ''
93 95
 

+ 3
- 1
novaclient/v1_1/servers.py View File

@@ -21,6 +21,8 @@ Server interface.
21 21
 
22 22
 import urllib
23 23
 
24
+import six
25
+
24 26
 from novaclient import base
25 27
 from novaclient import crypto
26 28
 from novaclient.v1_1 import base as local_base
@@ -365,7 +367,7 @@ class ServerManager(local_base.BootingManagerWithFind):
365 367
 
366 368
         qparams = {}
367 369
 
368
-        for opt, val in search_opts.iteritems():
370
+        for opt, val in six.iteritems(search_opts):
369 371
             if val:
370 372
                 qparams[opt] = val
371 373
 

+ 3
- 1
novaclient/v1_1/volumes.py View File

@@ -19,6 +19,8 @@ Volume interface (1.1 extension).
19 19
 
20 20
 import urllib
21 21
 
22
+import six
23
+
22 24
 from novaclient import base
23 25
 
24 26
 
@@ -86,7 +88,7 @@ class VolumeManager(base.ManagerWithFind):
86 88
         """
87 89
         search_opts = search_opts or {}
88 90
 
89
-        qparams = dict((k, v) for (k, v) in search_opts.iteritems() if v)
91
+        qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v)
90 92
 
91 93
         query_string = '?%s' % urllib.urlencode(qparams) if qparams else ''
92 94
 

+ 1
- 0
requirements.txt View File

@@ -5,3 +5,4 @@ iso8601>=0.1.4
5 5
 prettytable>=0.6,<0.8
6 6
 requests>=0.8
7 7
 simplejson
8
+six

Loading…
Cancel
Save