From 3027e890362e99f51be16fd59478a55771fcf2e5 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 10 Oct 2013 13:26:27 -0400 Subject: [PATCH] python3: Refactor dict for python2/python3 compat Python3 changed the behavior of dict.keys such that it is now returns a dict_keys object, which is iterable but not indexable. You can get the python2 result back with an explicit call to list. Change-Id: Ic504d3929398aa82ac87d1735cf4cedea2dfc5d1 Signed-off-by: Chuck Short --- keystoneclient/apiclient/exceptions.py | 2 +- keystoneclient/base.py | 2 +- keystoneclient/contrib/ec2/utils.py | 4 ++-- keystoneclient/service_catalog.py | 2 +- keystoneclient/shell.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/keystoneclient/apiclient/exceptions.py b/keystoneclient/apiclient/exceptions.py index 852456f5b..7f04136a4 100644 --- a/keystoneclient/apiclient/exceptions.py +++ b/keystoneclient/apiclient/exceptions.py @@ -424,7 +424,7 @@ def from_response(response, method, url): pass else: if hasattr(body, "keys"): - error = body[body.keys()[0]] + error = body[list(body)[0]] kwargs["message"] = error.get("message") kwargs["details"] = error.get("details") elif content_type.startswith("text/"): diff --git a/keystoneclient/base.py b/keystoneclient/base.py index 7528bd126..57ae20574 100644 --- a/keystoneclient/base.py +++ b/keystoneclient/base.py @@ -428,7 +428,7 @@ class Resource(object): return self.__dict__[k] def __repr__(self): - reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and + reprkeys = sorted(k for k in self.__dict__ if k[0] != '_' and k != 'manager') info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) return "<%s %s>" % (self.__class__.__name__, info) diff --git a/keystoneclient/contrib/ec2/utils.py b/keystoneclient/contrib/ec2/utils.py index 29a01f5bf..d6ab54f4c 100644 --- a/keystoneclient/contrib/ec2/utils.py +++ b/keystoneclient/contrib/ec2/utils.py @@ -116,7 +116,7 @@ class Ec2Signer(object): def _calc_signature_1(self, params): """Generate AWS signature version 1 string.""" - keys = params.keys() + keys = list(params) keys.sort(cmp=lambda x, y: cmp(x.lower(), y.lower())) for key in keys: self.hmac.update(key) @@ -129,7 +129,7 @@ class Ec2Signer(object): """Construct a sorted, correctly encoded query string as required for _calc_signature_2 and _calc_signature_4. """ - keys = params.keys() + keys = list(params) keys.sort() pairs = [] for key in keys: diff --git a/keystoneclient/service_catalog.py b/keystoneclient/service_catalog.py index 9f569a402..9f47cb8b7 100644 --- a/keystoneclient/service_catalog.py +++ b/keystoneclient/service_catalog.py @@ -141,7 +141,7 @@ class ServiceCatalogV2(ServiceCatalog): continue sc[service['type']] = [] for endpoint in service['endpoints']: - if endpoint_type and endpoint_type not in endpoint.keys(): + if endpoint_type and endpoint_type not in endpoint: continue sc[service['type']].append(endpoint) return sc diff --git a/keystoneclient/shell.py b/keystoneclient/shell.py index 1c3427370..7ce8f9a5d 100644 --- a/keystoneclient/shell.py +++ b/keystoneclient/shell.py @@ -454,7 +454,7 @@ class OpenStackIdentityShell(object): options = set() for sc_str, sc in self.subcommands.items(): commands.add(sc_str) - for option in sc._optionals._option_string_actions.keys(): + for option in list(sc._optionals._option_string_actions): options.add(option) commands.remove('bash-completion')