Don't use dict.iterkeys()

Iterating on a dictionary iterators on its keys, so calling its
iterkeys() method is not needed.

Moreover, the dict.iterkeys() method is gone in Python 3. This change
makes the modified code compatible with Python 3.

Blueprint nova-python3
Change-Id: I140f499d2054bb7d5486e4c61a2f886be6649cbb
This commit is contained in:
Victor Stinner 2015-05-21 14:51:18 -07:00
parent e9c8dfc6b3
commit 51f443ec4e
5 changed files with 6 additions and 6 deletions

View File

@ -2158,7 +2158,7 @@ def _regex_instance_filter(query, filters):
model = models.Instance
db_regexp_op = _get_regexp_op_for_connection(CONF.database.connection)
for filter_name in filters.iterkeys():
for filter_name in filters:
try:
column_attr = getattr(model, filter_name)
except AttributeError:

View File

@ -292,8 +292,8 @@ class TestCase(testtools.TestCase):
def inner(expected, observed):
if isinstance(expected, dict) and isinstance(observed, dict):
self.assertEqual(len(expected), len(observed))
expected_keys = sorted(expected.iterkeys())
observed_keys = sorted(expected.iterkeys())
expected_keys = sorted(expected)
observed_keys = sorted(expected)
self.assertEqual(expected_keys, observed_keys)
expected_values_iter = iter(sort(expected.values()))

View File

@ -465,7 +465,7 @@ class ServersTest(ServersTestBase):
# Cleanup
self._delete_server(created_server_id)
for server_id in server_map.iterkeys():
for server_id in server_map:
self._delete_server(server_id)
def test_create_server_with_injected_files(self):

View File

@ -223,7 +223,7 @@ class FakeNetworkAPI(object):
net['broadcast'] = str(subnet_v4.broadcast)
net['dhcp_start'] = str(subnet_v4[2])
for key in FAKE_NETWORKS[0].iterkeys():
for key in FAKE_NETWORKS[0]:
net.setdefault(key, kwargs.get(key))
new_networks.append(net)
self.networks += new_networks

View File

@ -268,7 +268,7 @@ class NovaTestResult(testtools.TestResult):
self.stopTestRun()
def stopTestRun(self):
for cls in list(self.results.iterkeys()):
for cls in list(self.results):
self.writeTestCase(cls)
self.stream.writeln()
self.writeSlowTests()