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
This commit is contained in:
Tang Chen 2016-03-12 10:58:28 +08:00
parent 586a038afd
commit dc7e4fc15d
11 changed files with 11 additions and 11 deletions

View File

@ -56,4 +56,4 @@ class CommandManager(cliff.commandmanager.CommandManager):
)
group_list.append(cmd_name)
return group_list
return self.commands.keys()
return list(self.commands.keys())

View File

@ -122,7 +122,7 @@ def from_response(response, body):
cls = _code_map.get(response.status, ClientException)
if body:
if hasattr(body, 'keys'):
error = body[body.keys()[0]]
error = body[list(body.keys())[0]]
message = error.get('message')
details = error.get('details')
else:

View File

@ -281,7 +281,7 @@ def get_client_class(api_name, version, version_map):
client_path = version_map[str(version)]
except (KeyError, ValueError):
msg = "Invalid %s client version '%s'. must be one of: %s" % (
(api_name, version, ', '.join(version_map.keys())))
(api_name, version, ', '.join(list(version_map.keys()))))
raise exceptions.UnsupportedVersion(msg)
return importutils.import_class(client_path)

View File

@ -18,7 +18,7 @@ from openstackclient.network import common
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -38,7 +38,7 @@ _formatters = {
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -36,7 +36,7 @@ _formatters = {
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -42,7 +42,7 @@ _formatters = {
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -27,7 +27,7 @@ def _format_security_group_rule_show(obj):
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -31,7 +31,7 @@ _formatters = {
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -20,7 +20,7 @@ from openstackclient.common import utils
def _get_columns(item):
columns = item.keys()
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')

View File

@ -355,7 +355,7 @@ class OpenStackShell(app.App):
self.log.warning(
"%s version %s is not in supported versions %s"
% (api, version_opt,
', '.join(mod.API_VERSIONS.keys())))
', '.join(list(mod.API_VERSIONS.keys()))))
# Command groups deal only with major versions
version = '.v' + version_opt.replace('.', '_').split('_')[0]