python3: compatibility for iteritems and iterkeys

Use six to allow python2/pyton3 for iteritems and
iterkeys.

six.iteriems() replaces dictionary.iteritems() (python2)
and dictionary.iterms() (python3)

six.iterkeys() replaces dictionary.iterkeys (python2)
and dictionary.keys() (python3)

Change-Id: I26c80b78a7dedf3aa32eedf01a83ff6d1e592ba7
Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
Chuck Short 2013-06-11 13:22:56 -05:00
parent 93557c1929
commit d12d7a73ff
8 changed files with 17 additions and 7 deletions

@ -22,6 +22,9 @@ import abc
import contextlib
import hashlib
import os
import six
from cinderclient import exceptions
from cinderclient import utils
@ -248,7 +251,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)
except AttributeError:

@ -18,6 +18,7 @@ import re
import sys
import uuid
import six
import prettytable
from cinderclient import exceptions
@ -165,7 +166,7 @@ def print_list(objs, fields, formatters={}):
def print_dict(d, property="Property"):
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
pt.aligns = ['l', 'l']
[pt.add_row(list(r)) for r in d.iteritems()]
[pt.add_row(list(r)) for r in six.iteritems(d)]
print strutils.safe_encode(pt.get_string(sortby=property))

@ -19,6 +19,7 @@ Volume snapshot interface (1.1 extension).
import urllib
from cinderclient import base
import six
class Snapshot(base.Resource):
@ -95,7 +96,7 @@ class SnapshotManager(base.ManagerWithFind):
qparams = {}
for opt, val in search_opts.iteritems():
for opt, val in six.iteritems(search_opts):
if val:
qparams[opt] = val

@ -18,6 +18,7 @@ Volume interface (1.1 extension).
"""
import urllib
import six
from cinderclient import base
@ -167,7 +168,7 @@ class VolumeManager(base.ManagerWithFind):
qparams = {}
for opt, val in search_opts.iteritems():
for opt, val in six.iteritems(search_opts):
if val:
qparams[opt] = val

@ -15,6 +15,7 @@
"""Volume snapshot interface (1.1 extension)."""
import six
import urllib
from cinderclient import base
@ -83,7 +84,7 @@ class SnapshotManager(base.ManagerWithFind):
qparams = {}
for opt, val in search_opts.iteritems():
for opt, val in six.iteritems(search_opts):
if val:
qparams[opt] = val

@ -15,6 +15,7 @@
"""Volume interface (v2 extension)."""
import six
import urllib
from cinderclient import base
@ -161,7 +162,7 @@ class VolumeManager(base.ManagerWithFind):
qparams = {}
for opt, val in search_opts.iteritems():
for opt, val in six.iteritems(search_opts):
if val:
qparams[opt] = val

@ -4,3 +4,4 @@ argparse
prettytable>=0.6,<0.8
requests>=0.8
simplejson>=2.0.9
six

@ -47,6 +47,7 @@ import subunit
import sys
import unittest
import six
import testtools
@ -277,7 +278,7 @@ class NovaTestResult(testtools.TestResult):
self.stopTestRun()
def stopTestRun(self):
for cls in list(self.results.iterkeys()):
for cls in list(six.iterkeys(self.results)):
self.writeTestCase(cls)
self.stream.writeln()
self.writeSlowTests()