Skip to content

Commit dc7e4fc

Browse files
author
Tang Chen
committed
Fix dict.keys() compatibility for python 3
In Python 2, dict.keys() will return a list. But in Python 3, it will return an iterator. So we need to fix all the places that assuming dict.keys() is a list. Change-Id: I8d1cc536377b3e5c644cfaa0892e40d0bd7c11b1 Closes-Bug: #1556350
1 parent 586a038 commit dc7e4fc

11 files changed

Lines changed: 11 additions & 11 deletions

File tree

openstackclient/common/commandmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def get_command_names(self, group=None):
5656
)
5757
group_list.append(cmd_name)
5858
return group_list
59-
return self.commands.keys()
59+
return list(self.commands.keys())

openstackclient/common/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def from_response(response, body):
122122
cls = _code_map.get(response.status, ClientException)
123123
if body:
124124
if hasattr(body, 'keys'):
125-
error = body[body.keys()[0]]
125+
error = body[list(body.keys())[0]]
126126
message = error.get('message')
127127
details = error.get('details')
128128
else:

openstackclient/common/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def get_client_class(api_name, version, version_map):
281281
client_path = version_map[str(version)]
282282
except (KeyError, ValueError):
283283
msg = "Invalid %s client version '%s'. must be one of: %s" % (
284-
(api_name, version, ', '.join(version_map.keys())))
284+
(api_name, version, ', '.join(list(version_map.keys()))))
285285
raise exceptions.UnsupportedVersion(msg)
286286

287287
return importutils.import_class(client_path)

openstackclient/network/v2/floating_ip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def _get_columns(item):
21-
columns = item.keys()
21+
columns = list(item.keys())
2222
if 'tenant_id' in columns:
2323
columns.remove('tenant_id')
2424
columns.append('project_id')

openstackclient/network/v2/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _format_router_external(item):
3838

3939

4040
def _get_columns(item):
41-
columns = item.keys()
41+
columns = list(item.keys())
4242
if 'tenant_id' in columns:
4343
columns.remove('tenant_id')
4444
columns.append('project_id')

openstackclient/network/v2/port.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _format_admin_state(state):
3636

3737

3838
def _get_columns(item):
39-
columns = item.keys()
39+
columns = list(item.keys())
4040
if 'tenant_id' in columns:
4141
columns.remove('tenant_id')
4242
columns.append('project_id')

openstackclient/network/v2/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _format_external_gateway_info(info):
4242

4343

4444
def _get_columns(item):
45-
columns = item.keys()
45+
columns = list(item.keys())
4646
if 'tenant_id' in columns:
4747
columns.remove('tenant_id')
4848
columns.append('project_id')

openstackclient/network/v2/security_group_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _format_security_group_rule_show(obj):
2727

2828

2929
def _get_columns(item):
30-
columns = item.keys()
30+
columns = list(item.keys())
3131
if 'tenant_id' in columns:
3232
columns.remove('tenant_id')
3333
columns.append('project_id')

openstackclient/network/v2/subnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _format_allocation_pools(data):
3131

3232

3333
def _get_columns(item):
34-
columns = item.keys()
34+
columns = list(item.keys())
3535
if 'tenant_id' in columns:
3636
columns.remove('tenant_id')
3737
columns.append('project_id')

openstackclient/network/v2/subnet_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def _get_columns(item):
23-
columns = item.keys()
23+
columns = list(item.keys())
2424
if 'tenant_id' in columns:
2525
columns.remove('tenant_id')
2626
columns.append('project_id')

0 commit comments

Comments
 (0)