From 4021a1062b207f68747e10ffe88e93a7b7726014 Mon Sep 17 00:00:00 2001 From: Marcin Piwowarczyk Date: Mon, 27 Aug 2018 09:41:56 +0200 Subject: [PATCH] Fix python3 compatibility issues While executing functional tests in trove project, with baseptyhon python3 in change [1], there appears few incompatibilities in troveclient. All of them are directly related to differences in PY3 version. This change removes these issues and will allow to execute functional tests seamlessly. Change details: * troveclient/compat/base.py - dict.iteritems was removed in PY3 because dict.items now does the thing dict.iteritems did in PY2 * troveclient/compat/client.py - json.loads expects string, and PY3 doesnt convert bytes to string. We have to use explicity call decode() which will decode given bytes to string * troveclient/apiclient/base.py - to avoid infinite recursion exception raised when pickling class attributes [1] I9ee34642c700d1e6ba9c2f3891b7fa1f7f7e1e1d Change-Id: I8989fd4798e80eae27408017e1543819a68b4ab1 Signed-off-by: Marcin Piwowarczyk --- troveclient/apiclient/base.py | 2 ++ troveclient/compat/base.py | 2 +- troveclient/compat/client.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/troveclient/apiclient/base.py b/troveclient/apiclient/base.py index 1b7e35fe..e2a2f05a 100644 --- a/troveclient/apiclient/base.py +++ b/troveclient/apiclient/base.py @@ -458,6 +458,8 @@ class Resource(object): pass def __getattr__(self, k): + if k == "__setstate__": + raise AttributeError(k) if k not in self.__dict__: # NOTE(bcwaldon): disallow lazy-loading if already loaded once if not self.is_loaded: diff --git a/troveclient/compat/base.py b/troveclient/compat/base.py index 24d681ce..33016849 100644 --- a/troveclient/compat/base.py +++ b/troveclient/compat/base.py @@ -246,7 +246,7 @@ class Resource(object): return None def _add_details(self, info): - for (k, v) in info.iteritems(): + for (k, v) in info.items(): try: setattr(self, k, v) except AttributeError: diff --git a/troveclient/compat/client.py b/troveclient/compat/client.py index b04e0086..9dfa2844 100644 --- a/troveclient/compat/client.py +++ b/troveclient/compat/client.py @@ -200,9 +200,9 @@ class TroveHTTPClient(httplib2.Http): if 'body' in kwargs: kwargs['body'] = json.dumps(kwargs['body']) - def morph_response_body(self, body_string): + def morph_response_body(self, raw_body): try: - return json.loads(body_string) + return json.loads(raw_body.decode()) except ValueError: raise exceptions.ResponseFormatError()