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>
This commit is contained in:
Marcin Piwowarczyk 2018-08-27 09:41:56 +02:00
parent 80ecbbc337
commit 4021a1062b
3 changed files with 5 additions and 3 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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()