diff options
author | Marcin Piwowarczyk <m.piwowarczy@samsung.com> | 2018-08-27 09:41:56 +0200 |
---|---|---|
committer | Marcin Piwowarczyk <m.piwowarczy@samsung.com> | 2018-08-31 12:51:32 +0000 |
commit | 4021a1062b207f68747e10ffe88e93a7b7726014 (patch) | |
tree | 513be11edc2b67c6539a5488cf4c13266f11f773 | |
parent | 80ecbbc3379d30bc91b2a2f06fc4fbaf84ab6a3f (diff) | |
download | python-troveclient-4021a1062b207f68747e10ffe88e93a7b7726014.tar.gz |
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 <m.piwowarczy@samsung.com>
-rw-r--r-- | troveclient/apiclient/base.py | 2 | ||||
-rw-r--r-- | troveclient/compat/base.py | 2 | ||||
-rw-r--r-- | 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 1b7e35f..e2a2f05 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 24d681c..3301684 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 b04e008..9dfa284 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() |