Merge "Using jsonutils instead of json"
This commit is contained in:
commit
1f7df3d53d
watcherclient
@ -17,7 +17,6 @@ import copy
|
|||||||
from distutils import version
|
from distutils import version
|
||||||
import functools
|
import functools
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
@ -27,6 +26,7 @@ import time
|
|||||||
|
|
||||||
from keystoneauth1 import adapter
|
from keystoneauth1 import adapter
|
||||||
from keystoneauth1 import exceptions as kexceptions
|
from keystoneauth1 import exceptions as kexceptions
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
import requests
|
import requests
|
||||||
import six
|
import six
|
||||||
@ -70,10 +70,10 @@ def _extract_error_json(body):
|
|||||||
"""Return error_message from the HTTP response body."""
|
"""Return error_message from the HTTP response body."""
|
||||||
error_json = {}
|
error_json = {}
|
||||||
try:
|
try:
|
||||||
body_json = json.loads(body)
|
body_json = jsonutils.loads(body)
|
||||||
if 'error_message' in body_json:
|
if 'error_message' in body_json:
|
||||||
raw_msg = body_json['error_message']
|
raw_msg = body_json['error_message']
|
||||||
error_json = json.loads(raw_msg)
|
error_json = jsonutils.loads(raw_msg)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -382,7 +382,7 @@ class HTTPClient(VersionNegotiationMixin):
|
|||||||
kwargs['headers'].setdefault('Accept', 'application/json')
|
kwargs['headers'].setdefault('Accept', 'application/json')
|
||||||
|
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
kwargs['body'] = json.dumps(kwargs['body'])
|
kwargs['body'] = jsonutils.dumps(kwargs['body'])
|
||||||
|
|
||||||
resp, body_iter = self._http_request(url, method, **kwargs)
|
resp, body_iter = self._http_request(url, method, **kwargs)
|
||||||
content_type = resp.headers.get('Content-Type')
|
content_type = resp.headers.get('Content-Type')
|
||||||
@ -395,7 +395,7 @@ class HTTPClient(VersionNegotiationMixin):
|
|||||||
if 'application/json' in content_type:
|
if 'application/json' in content_type:
|
||||||
body = ''.join([chunk for chunk in body_iter])
|
body = ''.join([chunk for chunk in body_iter])
|
||||||
try:
|
try:
|
||||||
body = json.loads(body)
|
body = jsonutils.loads(body)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
LOG.error(_LE('Could not decode response body as JSON'))
|
LOG.error(_LE('Could not decode response body as JSON'))
|
||||||
else:
|
else:
|
||||||
@ -545,7 +545,7 @@ class SessionClient(VersionNegotiationMixin, adapter.LegacyJsonAdapter):
|
|||||||
kwargs['headers'].setdefault('Accept', 'application/json')
|
kwargs['headers'].setdefault('Accept', 'application/json')
|
||||||
|
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
kwargs['data'] = json.dumps(kwargs.pop('body'))
|
kwargs['data'] = jsonutils.dumps(kwargs.pop('body'))
|
||||||
|
|
||||||
resp = self._http_request(url, method, **kwargs)
|
resp = self._http_request(url, method, **kwargs)
|
||||||
body = resp.content
|
body = resp.content
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
from watcherclient._i18n import _
|
from watcherclient._i18n import _
|
||||||
@ -89,7 +89,7 @@ def split_and_deserialize(string):
|
|||||||
raise exc.CommandError(_('Attributes must be a list of '
|
raise exc.CommandError(_('Attributes must be a list of '
|
||||||
'PATH=VALUE not "%s"') % string)
|
'PATH=VALUE not "%s"') % string)
|
||||||
try:
|
try:
|
||||||
value = json.loads(value)
|
value = jsonutils.loads(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -10,7 +10,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 oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from keystoneauth1.fixture import v2 as ks_v2_fixture
|
from keystoneauth1.fixture import v2 as ks_v2_fixture
|
||||||
@ -53,11 +53,11 @@ TOKENID = uuidutils.generate_uuid(dashed=False)
|
|||||||
|
|
||||||
|
|
||||||
def _create_version_list(versions):
|
def _create_version_list(versions):
|
||||||
return json.dumps({'versions': {'values': versions}})
|
return jsonutils.dumps({'versions': {'values': versions}})
|
||||||
|
|
||||||
|
|
||||||
def _create_single_version(version):
|
def _create_single_version(version):
|
||||||
return json.dumps({'version': version})
|
return jsonutils.dumps({'version': version})
|
||||||
|
|
||||||
|
|
||||||
V3_VERSION_LIST = _create_version_list([V3_VERSION, V2_VERSION])
|
V3_VERSION_LIST = _create_version_list([V3_VERSION, V2_VERSION])
|
||||||
@ -74,8 +74,8 @@ def keystone_request_callback(request, uri, headers):
|
|||||||
return (200, headers, V3_VERSION_LIST)
|
return (200, headers, V3_VERSION_LIST)
|
||||||
elif uri == BASE_URL + "/v2.0":
|
elif uri == BASE_URL + "/v2.0":
|
||||||
v2_token = ks_v2_fixture.Token(token_id)
|
v2_token = ks_v2_fixture.Token(token_id)
|
||||||
return (200, response_headers, json.dumps(v2_token))
|
return (200, response_headers, jsonutils.dumps(v2_token))
|
||||||
elif uri == BASE_URL + "/v3":
|
elif uri == BASE_URL + "/v3":
|
||||||
v3_token = ks_v3_fixture.Token()
|
v3_token = ks_v3_fixture.Token()
|
||||||
response_headers["X-Subject-Token"] = token_id
|
response_headers["X-Subject-Token"] = token_id
|
||||||
return (201, response_headers, json.dumps(v3_token))
|
return (201, response_headers, jsonutils.dumps(v3_token))
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from osc_lib import utils as oscutils
|
from osc_lib import utils as oscutils
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from watcherclient.common import httpclient
|
from watcherclient.common import httpclient
|
||||||
from watcherclient.tests.unit import utils
|
from watcherclient.tests.unit import utils
|
||||||
@ -55,7 +55,7 @@ class CommandTestCase(utils.BaseTestCase):
|
|||||||
def run_cmd(self, cmd, formatting='json'):
|
def run_cmd(self, cmd, formatting='json'):
|
||||||
if formatting:
|
if formatting:
|
||||||
formatter_arg = " -f %s" % formatting
|
formatter_arg = " -f %s" % formatting
|
||||||
formatter = json.loads
|
formatter = jsonutils.loads
|
||||||
else:
|
else:
|
||||||
formatter_arg = ''
|
formatter_arg = ''
|
||||||
formatter = str
|
formatter = str
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from watcherclient._i18n import _
|
from watcherclient._i18n import _
|
||||||
from watcherclient.common import command
|
from watcherclient.common import command
|
||||||
@ -38,7 +38,7 @@ class ShowStrategy(command.ShowOne):
|
|||||||
def _format_spec(self, strategy):
|
def _format_spec(self, strategy):
|
||||||
parameters_spec = strategy.parameters_spec.get('properties')
|
parameters_spec = strategy.parameters_spec.get('properties')
|
||||||
if parameters_spec:
|
if parameters_spec:
|
||||||
return json.dumps(parameters_spec, indent=2)
|
return jsonutils.dumps(parameters_spec, indent=2)
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user