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

View File

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

View File

@ -14,10 +14,11 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json
import os import os
import uuid import uuid
from oslo_serialization import jsonutils
from debtcollector import removals from debtcollector import removals
from keystoneauth1 import adapter from keystoneauth1 import adapter
from keystoneauth1.identity import generic 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, schema_string = resource_string('schemas', version, '%s.json' % name,
package=package) 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={}): 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 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json
from oslo_serialization import jsonutils
from designateclient import client from designateclient import client
from designateclient import utils from designateclient import utils
@ -53,7 +54,7 @@ class DomainsController(client.CrudController):
:param domain: A :class:`Domain` to create :param domain: A :class:`Domain` to create
:returns: :class:`Domain` :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()) return Domain(response.json())
@ -65,7 +66,7 @@ class DomainsController(client.CrudController):
:returns: :class:`Domain` :returns: :class:`Domain`
""" """
response = self.client.put('/domains/%s' % domain.id, response = self.client.put('/domains/%s' % domain.id,
data=json.dumps(domain.changes)) data=jsonutils.dumps(domain.changes))
return Domain(response.json()) return Domain(response.json())

View File

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

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json from oslo_serialization import jsonutils
from designateclient import client from designateclient import client
from designateclient import utils from designateclient import utils
@ -74,7 +74,7 @@ class RecordsController(client.CrudController):
'domain_id': domain_id '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()) return Record(response.json())
@ -93,7 +93,7 @@ class RecordsController(client.CrudController):
'record_id': record.id '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()) return Record(response.json())

View File

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

View File

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