Update json module to jsonutils

oslo project provide jsonutils, and the others use it in many place,
this PS to update the json moudule to oslo jsonutils for consistency.

Change-Id: I8cbf78b0735572f550ece31611258c3da9ae1d35
This commit is contained in:
cao.yuan 2019-02-24 23:54:49 +08:00 committed by caoyuan
parent 4ffd836c9a
commit e288539298
8 changed files with 25 additions and 18 deletions

View File

@ -13,13 +13,15 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
import json
import six
from six.moves.urllib import parse
from stevedore import extension
from oslo_serialization import jsonutils
from designateclient import exceptions
@ -48,7 +50,7 @@ class Controller(object):
content_type = headers.get('Content-Type') if headers else None
if 'data' in kwargs and content_type in {None, 'application/json'}:
kwargs['data'] = json.dumps(kwargs['data'])
kwargs['data'] = jsonutils.dumps(kwargs['data'])
def _post(self, url, response_key=None, **kwargs):
self._serialize(kwargs)

View File

@ -12,11 +12,12 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json as json_
import os
import fixtures
from keystoneauth1 import session as keystone_session
from oslo_serialization import jsonutils
from oslotest import base as test
from requests_mock.contrib import fixture as req_fixture
import six
@ -81,7 +82,7 @@ class APITestCase(TestCase):
base_url = self.get_base(base_url)
if json:
kwargs['text'] = json_.dumps(json)
kwargs['text'] = jsonutils.dumps(json)
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = 'application/json'
@ -103,7 +104,7 @@ class APITestCase(TestCase):
def assertRequestBodyIs(self, body=None, json=None):
last_request_body = self.requests.last_request.body
if json:
val = json_.loads(last_request_body)
val = jsonutils.loads(last_request_body)
self.assertEqual(json, val)
elif body:
self.assertEqual(body, last_request_body)

View File

@ -14,10 +14,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import os
import uuid
from oslo_serialization import jsonutils
from debtcollector import removals
from keystoneauth1 import adapter
from keystoneauth1.identity import generic
@ -51,7 +52,7 @@ def load_schema(version, name, package=None):
schema_string = resource_string('schemas', version, '%s.json' % name,
package=package)
return json.loads(schema_string.decode('utf-8'))
return jsonutils.loads(schema_string)
def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):

View File

@ -13,7 +13,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_serialization import jsonutils
from designateclient import client
from designateclient import utils
@ -53,7 +54,7 @@ class DomainsController(client.CrudController):
:param domain: A :class:`Domain` to create
:returns: :class:`Domain`
"""
response = self.client.post('/domains', data=json.dumps(domain))
response = self.client.post('/domains', data=jsonutils.dumps(domain))
return Domain(response.json())
@ -65,7 +66,7 @@ class DomainsController(client.CrudController):
:returns: :class:`Domain`
"""
response = self.client.put('/domains/%s' % domain.id,
data=json.dumps(domain.changes))
data=jsonutils.dumps(domain.changes))
return Domain(response.json())

View File

@ -13,7 +13,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_serialization import jsonutils
from designateclient import client
@ -29,7 +30,7 @@ class QuotasController(client.Controller):
def update(self, tenant_id, values):
response = self.client.put('/quotas/%s' % tenant_id,
data=json.dumps(values))
data=jsonutils.dumps(values))
return response.json()
def reset(self, tenant_id):

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_serialization import jsonutils
from designateclient import client
from designateclient import utils
@ -74,7 +74,7 @@ class RecordsController(client.CrudController):
'domain_id': domain_id
}
response = self.client.post(uri, data=json.dumps(record))
response = self.client.post(uri, data=jsonutils.dumps(record))
return Record(response.json())
@ -93,7 +93,7 @@ class RecordsController(client.CrudController):
'record_id': record.id
}
response = self.client.put(uri, data=json.dumps(record.changes))
response = self.client.put(uri, data=jsonutils.dumps(record.changes))
return Record(response.json())

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_serialization import jsonutils
from designateclient import client
from designateclient import utils
@ -53,7 +53,7 @@ class ServersController(client.CrudController):
:param server: A :class:`Server` to create
:returns: :class:`Server`
"""
response = self.client.post('/servers', data=json.dumps(server))
response = self.client.post('/servers', data=jsonutils.dumps(server))
return Server(response.json())
@ -65,7 +65,7 @@ class ServersController(client.CrudController):
:returns: :class:`Server`
"""
response = self.client.put('/servers/%s' % server.id,
data=json.dumps(server.changes))
data=jsonutils.dumps(server.changes))
return Server(response.json())

View File

@ -4,6 +4,7 @@
cliff!=2.9.0,>=2.8.0 # Apache-2.0
jsonschema<3.0.0,>=2.6.0 # MIT
osc-lib>=1.8.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
pbr!=2.1.0,>=2.0.0 # Apache-2.0
keystoneauth1>=3.4.0 # Apache-2.0