From d8341bb4aea738b67e9fed23e4a1da61cf6571a9 Mon Sep 17 00:00:00 2001 From: Hiroaki Kobayashi Date: Mon, 15 Jan 2018 15:33:42 +0900 Subject: [PATCH] Fix issues with Python3 Partially implements: blueprint python-3 Change-Id: I766594fb09047c0f114e20dc718bca2b374f3165 (cherry picked from commit 39e1b71b81b3cde1e7936552f837f42211ae7747) --- blazarclient/base.py | 7 +++---- blazarclient/command.py | 4 ++-- blazarclient/shell.py | 2 +- blazarclient/tests/test_command.py | 8 ++++---- blazarclient/utils.py | 3 ++- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/blazarclient/base.py b/blazarclient/base.py index fc18ef3..2fc65ae 100644 --- a/blazarclient/base.py +++ b/blazarclient/base.py @@ -13,9 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json - from keystoneauth1 import adapter +from oslo_serialization import jsonutils import requests from blazarclient import exception @@ -89,13 +88,13 @@ class RequestManager(object): if 'body' in kwargs: kwargs['headers']['Content-Type'] = 'application/json' - kwargs['data'] = json.dumps(kwargs['body']) + kwargs['data'] = jsonutils.dump_as_bytes(kwargs['body']) del kwargs['body'] resp = requests.request(method, self.blazar_url + url, **kwargs) try: - body = json.loads(resp.text) + body = jsonutils.loads(resp.text) except ValueError: body = None diff --git a/blazarclient/command.py b/blazarclient/command.py index 4aa92bd..e605130 100644 --- a/blazarclient/command.py +++ b/blazarclient/command.py @@ -134,7 +134,7 @@ class CreateCommand(BlazarCommand, show.ShowOne): print('Created a new %s:' % self.resource, file=self.app.stdout) else: data = {'': ''} - return zip(*sorted(data.items())) + return list(zip(*sorted(data.items()))) class UpdateCommand(BlazarCommand): @@ -291,4 +291,4 @@ class ShowCommand(BlazarCommand, show.ShowOne): resource_manager = getattr(blazar_client, self.resource) data = resource_manager.get(res_id) self.format_output_data(data) - return zip(*sorted(data.items())) + return list(zip(*sorted(data.items()))) diff --git a/blazarclient/shell.py b/blazarclient/shell.py index 69138a8..5cd7eed 100644 --- a/blazarclient/shell.py +++ b/blazarclient/shell.py @@ -511,7 +511,7 @@ class BlazarShell(app.App): def main(argv=sys.argv[1:]): try: - return BlazarShell().run(map(encodeutils.safe_decode, argv)) + return BlazarShell().run(list(map(encodeutils.safe_decode, argv))) except exception.BlazarClientException: return 1 except Exception as e: diff --git a/blazarclient/tests/test_command.py b/blazarclient/tests/test_command.py index b6067b5..a03873b 100644 --- a/blazarclient/tests/test_command.py +++ b/blazarclient/tests/test_command.py @@ -68,12 +68,12 @@ class BlazarCommandTestCase(tests.TestCase): def test_format_output_data(self): data_before = {'key_string': 'string_value', - 'key_dict': "{'key0': 'value', 'key1': 'value'}", - 'key_list': "['1', '2', '3',]", + 'key_dict': {'key': 'value'}, + 'key_list': ['1', '2', '3'], 'key_none': None} data_after = {'key_string': 'string_value', - 'key_dict': "{'key0': 'value', 'key1': 'value'}", - 'key_list': "['1', '2', '3',]", + 'key_dict': '{"key": "value"}', + 'key_list': '1\n2\n3', 'key_none': ''} self.command.format_output_data(data_before) diff --git a/blazarclient/utils.py b/blazarclient/utils.py index c8ca68b..51398ac 100644 --- a/blazarclient/utils.py +++ b/blazarclient/utils.py @@ -14,10 +14,11 @@ # limitations under the License. import datetime -import json import os import re +from oslo_serialization import jsonutils as json + from blazarclient import exception from blazarclient.i18n import _