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
This commit is contained in:
zhulingjie 2019-02-20 00:54:29 +08:00
parent 1be720f91d
commit 5793232f25
7 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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