Merge "Fix JSON serialization issues with Python3"
This commit is contained in:
commit
ade7363ce0
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from blazar.api.v1 import app as v1_app
|
||||
from blazar.api.v2 import app as v2_app
|
||||
|
@ -31,7 +31,7 @@ class VersionSelectorApplication(object):
|
|||
def _append_versions_from_app(self, versions, app, environ):
|
||||
tmp_versions = app(environ, self.internal_start_response)
|
||||
if self._status.startswith("300"):
|
||||
tmp_versions = json.loads("".join(tmp_versions))
|
||||
tmp_versions = jsonutils.loads(tmp_versions.pop())
|
||||
versions['versions'].extend(tmp_versions['versions'])
|
||||
|
||||
def internal_start_response(self, status, response_headers, exc_info=None):
|
||||
|
@ -49,7 +49,7 @@ class VersionSelectorApplication(object):
|
|||
if len(versions['versions']):
|
||||
start_response("300 Multiple Choices",
|
||||
[("Content-Type", "application/json")])
|
||||
return [json.dumps(versions)]
|
||||
return [jsonutils.dump_as_bytes(versions)]
|
||||
else:
|
||||
start_response("204 No Content", [])
|
||||
return []
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
from blazar import context
|
||||
|
@ -23,7 +22,7 @@ from blazar import exceptions
|
|||
|
||||
def ctx_from_headers(headers):
|
||||
try:
|
||||
service_catalog = json.loads(headers['X-Service-Catalog'])
|
||||
service_catalog = jsonutils.loads(headers['X-Service-Catalog'])
|
||||
except KeyError:
|
||||
raise exceptions.ServiceCatalogNotFound()
|
||||
except TypeError:
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from oslo_serialization import jsonutils
|
||||
import pecan
|
||||
|
||||
from blazar.api.v2 import controllers
|
||||
|
@ -37,7 +37,7 @@ class RootController(object):
|
|||
versions = {"versions": []}
|
||||
self._append_versions_from_controller(versions['versions'],
|
||||
self.v2, 'v2')
|
||||
return json.dumps(versions)
|
||||
return jsonutils.dump_as_bytes(versions)
|
||||
|
||||
@pecan.expose(content_type='application/json')
|
||||
def versions(self):
|
||||
|
|
|
@ -160,7 +160,7 @@ def render(result=None, response_type=None, status=None, **kwargs):
|
|||
_("Content type '%s' isn't supported") % response_type)
|
||||
return
|
||||
|
||||
body = serializer.dumps(result)
|
||||
body = serializer.dump_as_bytes(result)
|
||||
|
||||
response_type = str(response_type)
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
from wsme import types as wtypes
|
||||
from wsme import utils as wutils
|
||||
|
@ -81,7 +81,7 @@ class CPUInfo(wtypes.UserType):
|
|||
# another. We need to keep this method as generic as
|
||||
# possible, ie. we accept JSONified dict.
|
||||
try:
|
||||
cpu_info = json.loads(value)
|
||||
cpu_info = jsonutils.loads(value)
|
||||
except TypeError:
|
||||
raise exceptions.InvalidInput(cls=CPUInfo.name, value=value)
|
||||
if not isinstance(cpu_info, dict):
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
import webob
|
||||
|
||||
from blazar.db import exceptions as db_exceptions
|
||||
|
@ -79,7 +78,7 @@ class ParsableErrorMiddleware(object):
|
|||
if not state:
|
||||
return app_iter
|
||||
try:
|
||||
res_dct = json.loads(app_iter[0])
|
||||
res_dct = jsonutils.loads(app_iter[0])
|
||||
except ValueError:
|
||||
return app_iter
|
||||
else:
|
||||
|
@ -128,7 +127,7 @@ class ParsableErrorMiddleware(object):
|
|||
state['status_code'] = cls.code
|
||||
|
||||
# NOTE(sbauza): Client expects a JSON encoded dict
|
||||
body = [json.dumps(
|
||||
body = [jsonutils.dump_as_bytes(
|
||||
{'error_code': state['status_code'],
|
||||
'error_message': faultstring,
|
||||
'error_name': state['status_code']}
|
||||
|
|
|
@ -24,7 +24,7 @@ class JsonEncoded(sa.TypeDecorator):
|
|||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if value is not None:
|
||||
value = jsonutils.dumps(value)
|
||||
value = jsonutils.dump_as_bytes(value)
|
||||
return value
|
||||
|
||||
def process_result_value(self, value, dialect):
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from blazar.api import context as api_context
|
||||
from blazar import context
|
||||
|
@ -34,7 +34,7 @@ class ContextTestCase(tests.TestCase):
|
|||
|
||||
def test_ctx_from_headers(self):
|
||||
self.context = self.patch(context, 'BlazarContext')
|
||||
catalog = json.dumps({'nova': 'catalog'})
|
||||
catalog = jsonutils.dump_as_bytes({'nova': 'catalog'})
|
||||
self.fake_headers[u'X-Service-Catalog'] = catalog
|
||||
api_context.ctx_from_headers(self.fake_headers)
|
||||
self.context.assert_called_once_with(user_id=u'1',
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from blazar.tests import api
|
||||
|
||||
|
@ -21,7 +21,7 @@ from blazar.tests import api
|
|||
class TestRoot(api.APITest):
|
||||
def setUp(self):
|
||||
super(TestRoot, self).setUp()
|
||||
self.versions = json.dumps(
|
||||
self.versions = jsonutils.dump_as_bytes(
|
||||
{"versions":
|
||||
[{"status": "CURRENT",
|
||||
"id": "v2.0",
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from blazar.api import app as api
|
||||
from blazar.api.v1 import app as v1_app
|
||||
|
@ -35,7 +35,7 @@ class FakeWSGIApp(object):
|
|||
|
||||
def __call__(self, environ, start_response):
|
||||
start_response(self.status_code, [])
|
||||
return [json.dumps(self.versions)]
|
||||
return [jsonutils.dump_as_bytes(self.versions)]
|
||||
|
||||
|
||||
class TestVersionDiscovery(tests.TestCase):
|
||||
|
@ -62,7 +62,7 @@ class TestVersionDiscovery(tests.TestCase):
|
|||
environ = {'PATH_INFO': self.path}
|
||||
|
||||
versions_raw = version_selector(environ, self.start_response)
|
||||
versions = json.loads("".join(versions_raw))
|
||||
versions = jsonutils.loads(versions_raw.pop())
|
||||
|
||||
self.assertEqual(2, len(versions['versions']))
|
||||
self.assertEqual("v{0}".format(self.v1_make_app().id_version),
|
||||
|
@ -79,7 +79,7 @@ class TestVersionDiscovery(tests.TestCase):
|
|||
environ = {'PATH_INFO': self.path}
|
||||
|
||||
versions_raw = version_selector(environ, self.start_response)
|
||||
versions = json.loads("".join(versions_raw))
|
||||
versions = jsonutils.loads(versions_raw.pop())
|
||||
|
||||
self.assertEqual(1, len(versions['versions']))
|
||||
self.assertEqual("v{0}".format(self.v1_make_app().id_version),
|
||||
|
@ -117,7 +117,7 @@ class TestVersionSelectorApplication(tests.TestCase):
|
|||
environ = {'PATH_INFO': "/v1"}
|
||||
|
||||
versions_raw = version_selector(environ, self.start_response)
|
||||
versions = json.loads("".join(versions_raw))
|
||||
versions = jsonutils.loads(versions_raw.pop())
|
||||
self.assertEqual(self.v1_make_app().versions, versions)
|
||||
|
||||
def test_get_v2_app(self):
|
||||
|
@ -125,5 +125,5 @@ class TestVersionSelectorApplication(tests.TestCase):
|
|||
environ = {'PATH_INFO': "/v2"}
|
||||
|
||||
versions_raw = version_selector(environ, self.start_response)
|
||||
versions = json.loads("".join(versions_raw))
|
||||
versions = jsonutils.loads(versions_raw.pop())
|
||||
self.assertEqual(self.v2_make_app().versions, versions)
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
from blazar.manager import exceptions as manager_ex
|
||||
|
@ -30,7 +29,7 @@ def convert_requirements(requirements):
|
|||
# Convert text to json
|
||||
if isinstance(requirements, six.string_types):
|
||||
try:
|
||||
requirements = json.loads(requirements)
|
||||
requirements = jsonutils.loads(requirements)
|
||||
except ValueError:
|
||||
raise manager_ex.MalformedRequirements(rqrms=requirements)
|
||||
|
||||
|
|
Loading…
Reference in New Issue