diff --git a/doc/source/api/autoindex.rst b/doc/source/api/autoindex.rst index dd7778e3d..f33b37be1 100644 --- a/doc/source/api/autoindex.rst +++ b/doc/source/api/autoindex.rst @@ -32,7 +32,6 @@ zaqar.openstack.common.fileutils.rst zaqar.openstack.common.gettextutils.rst zaqar.openstack.common.importutils.rst - zaqar.openstack.common.jsonutils.rst zaqar.openstack.common.local.rst zaqar.openstack.common.lockutils.rst zaqar.openstack.common.log.rst diff --git a/doc/source/api/zaqar.openstack.common.jsonutils.rst b/doc/source/api/zaqar.openstack.common.jsonutils.rst deleted file mode 100644 index 6d6d5a123..000000000 --- a/doc/source/api/zaqar.openstack.common.jsonutils.rst +++ /dev/null @@ -1,7 +0,0 @@ -The :mod:`zaqar.openstack.common.jsonutils` module -=================================================== - -.. automodule:: zaqar.openstack.common.jsonutils - :members: - :undoc-members: - :show-inheritance: diff --git a/openstack-common.conf b/openstack-common.conf index 4266a0f76..246b86105 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -6,7 +6,6 @@ module=excutils module=fileutils module=gettextutils module=importutils -module=jsonutils module=local module=lockutils module=log diff --git a/requirements.txt b/requirements.txt index 55f34074a..2b260ad38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ stevedore>=1.1.0 # Apache-2.0 six>=1.7.0 oslo.config>=1.4.0 # Apache-2.0 oslo.i18n>=1.0.0 # Apache-2.0 +oslo.serialization>=1.0.0 # Apache-2.0 oslo.utils>=1.1.0 # Apache-2.0 SQLAlchemy>=0.9.7,<=0.9.99 enum34 diff --git a/tests/unit/transport/wsgi/test_v1_1.py b/tests/unit/transport/wsgi/test_v1_1.py index 05b7e0fd1..61f2b7c87 100644 --- a/tests/unit/transport/wsgi/test_v1_1.py +++ b/tests/unit/transport/wsgi/test_v1_1.py @@ -15,8 +15,8 @@ import uuid import ddt import falcon +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar.tests.unit.transport.wsgi import base from zaqar.tests.unit.transport.wsgi import v1_1 diff --git a/zaqar/openstack/common/jsonutils.py b/zaqar/openstack/common/jsonutils.py deleted file mode 100644 index 52e63cac2..000000000 --- a/zaqar/openstack/common/jsonutils.py +++ /dev/null @@ -1,190 +0,0 @@ -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# Copyright 2011 Justin Santa Barbara -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -''' -JSON related utilities. - -This module provides a few things: - - 1) A handy function for getting an object down to something that can be - JSON serialized. See to_primitive(). - - 2) Wrappers around loads() and dumps(). The dumps() wrapper will - automatically use to_primitive() for you if needed. - - 3) This sets up anyjson to use the loads() and dumps() wrappers if anyjson - is available. -''' - - -import codecs -import datetime -import functools -import inspect -import itertools -import sys - -if sys.version_info < (2, 7): - # On Python <= 2.6, json module is not C boosted, so try to use - # simplejson module if available - try: - import simplejson as json - except ImportError: - import json -else: - import json - -import six -import six.moves.xmlrpc_client as xmlrpclib - -from zaqar.openstack.common import gettextutils -from zaqar.openstack.common import importutils -from zaqar.openstack.common import strutils -from zaqar.openstack.common import timeutils - -netaddr = importutils.try_import("netaddr") - -_nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod, - inspect.isfunction, inspect.isgeneratorfunction, - inspect.isgenerator, inspect.istraceback, inspect.isframe, - inspect.iscode, inspect.isbuiltin, inspect.isroutine, - inspect.isabstract] - -_simple_types = (six.string_types + six.integer_types - + (type(None), bool, float)) - - -def to_primitive(value, convert_instances=False, convert_datetime=True, - level=0, max_depth=3): - """Convert a complex object into primitives. - - Handy for JSON serialization. We can optionally handle instances, - but since this is a recursive function, we could have cyclical - data structures. - - To handle cyclical data structures we could track the actual objects - visited in a set, but not all objects are hashable. Instead we just - track the depth of the object inspections and don't go too deep. - - Therefore, convert_instances=True is lossy ... be aware. - - """ - # handle obvious types first - order of basic types determined by running - # full tests on nova project, resulting in the following counts: - # 572754 - # 460353 - # 379632 - # 274610 - # 199918 - # 114200 - # 51817 - # 26164 - # 6491 - # 283 - # 19 - if isinstance(value, _simple_types): - return value - - if isinstance(value, datetime.datetime): - if convert_datetime: - return timeutils.strtime(value) - else: - return value - - # value of itertools.count doesn't get caught by nasty_type_tests - # and results in infinite loop when list(value) is called. - if type(value) == itertools.count: - return six.text_type(value) - - # FIXME(vish): Workaround for LP bug 852095. Without this workaround, - # tests that raise an exception in a mocked method that - # has a @wrap_exception with a notifier will fail. If - # we up the dependency to 0.5.4 (when it is released) we - # can remove this workaround. - if getattr(value, '__module__', None) == 'mox': - return 'mock' - - if level > max_depth: - return '?' - - # The try block may not be necessary after the class check above, - # but just in case ... - try: - recursive = functools.partial(to_primitive, - convert_instances=convert_instances, - convert_datetime=convert_datetime, - level=level, - max_depth=max_depth) - if isinstance(value, dict): - return dict((k, recursive(v)) for k, v in six.iteritems(value)) - elif isinstance(value, (list, tuple)): - return [recursive(lv) for lv in value] - - # It's not clear why xmlrpclib created their own DateTime type, but - # for our purposes, make it a datetime type which is explicitly - # handled - if isinstance(value, xmlrpclib.DateTime): - value = datetime.datetime(*tuple(value.timetuple())[:6]) - - if convert_datetime and isinstance(value, datetime.datetime): - return timeutils.strtime(value) - elif isinstance(value, gettextutils.Message): - return value.data - elif hasattr(value, 'iteritems'): - return recursive(dict(value.iteritems()), level=level + 1) - elif hasattr(value, '__iter__'): - return recursive(list(value)) - elif convert_instances and hasattr(value, '__dict__'): - # Likely an instance of something. Watch for cycles. - # Ignore class member vars. - return recursive(value.__dict__, level=level + 1) - elif netaddr and isinstance(value, netaddr.IPAddress): - return six.text_type(value) - else: - if any(test(value) for test in _nasty_type_tests): - return six.text_type(value) - return value - except TypeError: - # Class objects are tricky since they may define something like - # __iter__ defined but it isn't callable as list(). - return six.text_type(value) - - -def dumps(value, default=to_primitive, **kwargs): - return json.dumps(value, default=default, **kwargs) - - -def dump(obj, fp, *args, **kwargs): - return json.dump(obj, fp, *args, **kwargs) - - -def loads(s, encoding='utf-8', **kwargs): - return json.loads(strutils.safe_decode(s, encoding), **kwargs) - - -def load(fp, encoding='utf-8', **kwargs): - return json.load(codecs.getreader(encoding)(fp), **kwargs) - - -try: - import anyjson -except ImportError: - pass -else: - anyjson._modules.append((__name__, 'dumps', TypeError, - 'loads', ValueError, 'load')) - anyjson.force_implementation(__name__) diff --git a/zaqar/openstack/common/log.py b/zaqar/openstack/common/log.py index 5f058a1e1..873d260a2 100644 --- a/zaqar/openstack/common/log.py +++ b/zaqar/openstack/common/log.py @@ -37,6 +37,7 @@ import sys import traceback from oslo.config import cfg +from oslo.serialization import jsonutils import six from six import moves @@ -44,7 +45,6 @@ _PY26 = sys.version_info[0:2] == (2, 6) from zaqar.openstack.common.gettextutils import _ from zaqar.openstack.common import importutils -from zaqar.openstack.common import jsonutils from zaqar.openstack.common import local # NOTE(flaper87): Pls, remove when graduating this module # from the incubator. diff --git a/zaqar/storage/sqlalchemy/utils.py b/zaqar/storage/sqlalchemy/utils.py index 5401cee1b..1dcf0e7ad 100644 --- a/zaqar/storage/sqlalchemy/utils.py +++ b/zaqar/storage/sqlalchemy/utils.py @@ -15,12 +15,12 @@ import functools +from oslo.serialization import jsonutils from oslo.utils import encodeutils import sqlalchemy as sa from sqlalchemy import exc from sqlalchemy.sql import func as sfunc -from zaqar.openstack.common import jsonutils from zaqar.openstack.common import log as logging from zaqar.storage import errors from zaqar.storage.sqlalchemy import tables diff --git a/zaqar/tests/functional/http.py b/zaqar/tests/functional/http.py index d55030560..be8ca149b 100755 --- a/zaqar/tests/functional/http.py +++ b/zaqar/tests/functional/http.py @@ -17,11 +17,10 @@ import functools import json from falcon import testing as ftest +from oslo.serialization import jsonutils import requests import six -from zaqar.openstack.common import jsonutils - def _build_url(method): diff --git a/zaqar/tests/unit/transport/wsgi/base.py b/zaqar/tests/unit/transport/wsgi/base.py index 2e8ecaf3c..aa2422f16 100644 --- a/zaqar/tests/unit/transport/wsgi/base.py +++ b/zaqar/tests/unit/transport/wsgi/base.py @@ -15,9 +15,9 @@ import uuid from falcon import testing as ftest +from oslo.serialization import jsonutils from zaqar import bootstrap -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.transport import validation from zaqar.transport.wsgi import driver diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_claims.py b/zaqar/tests/unit/transport/wsgi/v1/test_claims.py index 78afd32e8..8ea336523 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_claims.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_claims.py @@ -19,10 +19,10 @@ import uuid import ddt import falcon import mock +from oslo.serialization import jsonutils from oslo.utils import timeutils from testtools import matchers -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py b/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py index 8665b1249..e4f75b734 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_default_limits.py @@ -17,8 +17,8 @@ import contextlib import uuid import falcon +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar import storage from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_home.py b/zaqar/tests/unit/transport/wsgi/v1/test_home.py index 84569a04c..5f128655d 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_home.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_home.py @@ -13,9 +13,9 @@ # the License. import falcon +from oslo.serialization import jsonutils import six.moves.urllib.parse as urlparse -from zaqar.openstack.common import jsonutils from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_messages.py b/zaqar/tests/unit/transport/wsgi/v1/test_messages.py index 61e36acc7..834e76dda 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_messages.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_messages.py @@ -19,11 +19,11 @@ import uuid import ddt import falcon import mock +from oslo.serialization import jsonutils from oslo.utils import timeutils import six from testtools import matchers -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base from zaqar.transport import validation diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_pools.py b/zaqar/tests/unit/transport/wsgi/v1/test_pools.py index e3b3c91a4..7f1590d29 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_pools.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_pools.py @@ -17,8 +17,8 @@ import uuid import ddt import falcon +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1/test_queue_lifecycle.py b/zaqar/tests/unit/transport/wsgi/v1/test_queue_lifecycle.py index 8776d23bd..3a48b0038 100644 --- a/zaqar/tests/unit/transport/wsgi/v1/test_queue_lifecycle.py +++ b/zaqar/tests/unit/transport/wsgi/v1/test_queue_lifecycle.py @@ -14,9 +14,9 @@ import ddt import falcon +from oslo.serialization import jsonutils import six -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_claims.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_claims.py index 31bf7f4b6..f3eb0864d 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_claims.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_claims.py @@ -20,10 +20,10 @@ import uuid import ddt import falcon import mock +from oslo.serialization import jsonutils from oslo.utils import timeutils from testtools import matchers -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_default_limits.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_default_limits.py index 5657fad42..188fab05e 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_default_limits.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_default_limits.py @@ -17,8 +17,8 @@ import contextlib import uuid import falcon +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar import storage from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_flavors.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_flavors.py index 2ea93bf27..7455dc7bb 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_flavors.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_flavors.py @@ -17,8 +17,8 @@ import uuid import ddt import falcon +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_health.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_health.py index 41e6512ee..05e2e3feb 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_health.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_health.py @@ -17,8 +17,8 @@ import ddt import falcon import mock +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar.storage import errors import zaqar.storage.mongodb as mongo from zaqar import tests as testing diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_home.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_home.py index 9f7e565a2..5b18a1c45 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_home.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_home.py @@ -15,9 +15,9 @@ import uuid import falcon +from oslo.serialization import jsonutils import six.moves.urllib.parse as urlparse -from zaqar.openstack.common import jsonutils from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py index 4e3ab35d1..5acf1ab1a 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_messages.py @@ -19,11 +19,11 @@ import uuid import ddt import falcon import mock +from oslo.serialization import jsonutils from oslo.utils import timeutils import six from testtools import matchers -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base from zaqar.transport import validation diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py index 59e7ea4f2..4f008a03c 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_pools.py @@ -17,8 +17,8 @@ import uuid import ddt import falcon +from oslo.serialization import jsonutils -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base diff --git a/zaqar/tests/unit/transport/wsgi/v1_1/test_queue_lifecycle.py b/zaqar/tests/unit/transport/wsgi/v1_1/test_queue_lifecycle.py index 7a1270683..768bc41e4 100644 --- a/zaqar/tests/unit/transport/wsgi/v1_1/test_queue_lifecycle.py +++ b/zaqar/tests/unit/transport/wsgi/v1_1/test_queue_lifecycle.py @@ -16,9 +16,9 @@ import uuid import ddt import falcon +from oslo.serialization import jsonutils import six -from zaqar.openstack.common import jsonutils from zaqar import tests as testing from zaqar.tests.unit.transport.wsgi import base