From 5793232f257a645a16b12f89eef1f78faf53e12b Mon Sep 17 00:00:00 2001 From: zhulingjie Date: Wed, 20 Feb 2019 00:54:29 +0800 Subject: [PATCH] Update json module to jsonutils 1. json is deprecated, should use oslo_serialization.jsonutils instead. 2. cleanup of .keys() from dict_object.keys() *in* operator Change-Id: I09076a781a6fb12697d38b365ffda664be053187 --- README.rst | 2 ++ searchlightclient/common/base.py | 2 +- searchlightclient/common/utils.py | 2 +- searchlightclient/osc/v1/search.py | 7 ++++--- searchlightclient/tests/unit/osc/fakes.py | 2 +- searchlightclient/v1/search.py | 2 +- setup.cfg | 2 ++ 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 156494c..3afda0a 100644 --- a/README.rst +++ b/README.rst @@ -150,3 +150,5 @@ There are multiple test targets that can be run to validate the code. * tox -e pep8 - style guidelines enforcement * tox -e py27 - traditional unit testing with python 2.7 * tox -e py35 - traditional unit testing with python 3.5 +* tox -e py36 - traditional unit testing with python 3.6 +* tox -e py37 - traditional unit testing with python 3.7 diff --git a/searchlightclient/common/base.py b/searchlightclient/common/base.py index 50c1944..56e1a2d 100644 --- a/searchlightclient/common/base.py +++ b/searchlightclient/common/base.py @@ -460,7 +460,7 @@ class Resource(object): def __repr__(self): reprkeys = sorted(k - for k in self.__dict__.keys() + 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/searchlightclient/common/utils.py b/searchlightclient/common/utils.py index f54f578..b9240c6 100644 --- a/searchlightclient/common/utils.py +++ b/searchlightclient/common/utils.py @@ -96,7 +96,7 @@ def print_dict(d, formatters=None): caching=False, print_empty=False) pt.align = 'l' - for field in d.keys(): + for field in d: if field in formatters: pt.add_row([field, formatters[field](d[field])]) else: diff --git a/searchlightclient/osc/v1/search.py b/searchlightclient/osc/v1/search.py index 1ec3e7b..c5f1e55 100644 --- a/searchlightclient/osc/v1/search.py +++ b/searchlightclient/osc/v1/search.py @@ -13,9 +13,10 @@ """Searchlight v1 Search action implementations""" -import json import logging +from oslo_serialization import jsonutils + from osc_lib.command import command from osc_lib import utils @@ -96,10 +97,10 @@ class SearchResource(command.Lister): if parsed_args.query: if parsed_args.json: - query = json.loads(parsed_args.query) + query = jsonutils.loads(parsed_args.query) else: try: - json.loads(parsed_args.query) + jsonutils.loads(parsed_args.query) print("You should use the --json flag when specifying " "a JSON object.") exit(1) diff --git a/searchlightclient/tests/unit/osc/fakes.py b/searchlightclient/tests/unit/osc/fakes.py index 5024c67..bfa6ea4 100644 --- a/searchlightclient/tests/unit/osc/fakes.py +++ b/searchlightclient/tests/unit/osc/fakes.py @@ -61,7 +61,7 @@ class FakeResource(object): setattr(self, k, v) 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/searchlightclient/v1/search.py b/searchlightclient/v1/search.py index 66a82e4..052a0fb 100644 --- a/searchlightclient/v1/search.py +++ b/searchlightclient/v1/search.py @@ -52,7 +52,7 @@ class SearchManager(base.BaseManager): # transfer, since the data have been wrapped several times # before transfer, and the data overhead is pretty small comparing # to the data payload('_source'), it is done here for simplicity. - if 'simplified' in kwargs.keys() and kwargs['simplified']: + if 'simplified' in kwargs and kwargs['simplified']: resources = [h['_source'] for h in resources.hits['hits']] return resources diff --git a/setup.cfg b/setup.cfg index 2827a2a..36710e5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,6 +17,8 @@ classifier = Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 [files] packages =