summaryrefslogtreecommitdiffstats
path: root/openstack/common/jsonutils.py
Commit message (Collapse)AuthorAgeFilesLines
* Convert unicode for python3 portabilityChuck Short2013-05-061-3/+5
| | | | | | | | | | | | | From http://docs.python.org/3.1/whatsnew/3.0.html: "Python 3.0 uses the concepts of text and (binary) data instead of Unicode strings and 8-bit strings." Use six.text_type to Type for representing (Unicode) textual data. This is unicode() in Python 2 and str in Python 3. Change-Id: I3da268a714a34a8e626a2590f01b86e414dc3411 Signed-off-by: Chuck Short <chuck.short@canonical.com>
* Optimise to_primitive common casesStanislaw Pitucha2013-04-091-16/+42
| | | | | | | | | | | | | | to_primitive included many checks that were executed before any usual types have been checked. It's safe to reorder / duplicate the most common ones. Especially built-in types can be checked before other more complicated scenarios. This is important since to_primitive gets called over a million times in usual test run and many more times in a live environment. This change strips around 4% of nova testing time on my machine and the function itself is ~5x faster on average according to the profiler. Change-Id: I71e0c06bbcc31793a1cdcebb36d4e3d8c5876f73
* Don't LOG.error on max_depth (by default).Dan Prince2013-03-021-6/+0
| | | | | | | | | | | | Reverts part of a94b9b4 which added an extra LOG.error statement when max_depth is hit. This is causing spurious errors to get logged in some of our projects which have adopted this changed. Related to: https://bugs.launchpad.net/nova/+bug/1140133 Change-Id: Ie7939e41797da000dd8b269f905f351df0b7116d
* to_primitive imposes what seems to be an arbitary data structurePhil Day2013-02-121-3/+10
| | | | | | | | | | | | | | | | | | | depth of 3, but there is at least on case in Nova (Security group Rules) which requires a depth beyond this. https://bugs.launchpad.net/nova/+bug/1118608 Specifically security_group_rule_get_by_security_group returns a set of rules which have the structure: rule -> grantee_group -> Instance -> Instance_type Rather than just bumping the depth limit, which might break some other user of to_primitive we make it a specific parameter that defaults to the current value but can be over-ridden when required and log a warning when the depth is exceeded Change-Id: I1eaebd484e20cb2eae09a693289709973de9943c
* Allow to_primitive to ignore datetimesJoe Gordon2013-02-071-21/+13
| | | | | | | | | | | | In preparation for having nova.db.api not return any sqlalchemy objects. nova.db.api will return only primitives, except for datetime.datetime objects. Uses functools.partial to make code DRYING Partially implements bp db-api-cleanup Change-Id: I9980d8c4e20b05bbe734cf90ac209e4e7e89befb
* Make project pyflakes clean.Monty Taylor2012-11-281-1/+1
| | | | | | | | | | | | | Added both a tox test-env for pyflakes and fixed the current pyflakes errors. This did actually fix a couple of bugs. The CI team has started using pyflakes on its projects and also has started using oslo for things, so ignoring pyflakes warnings on the oslo code was starting to get old. However, additionally, pyflakes is pretty solid, so we should maybe consider gating on it across the board. (% locals() is the biggest thing that we do that it doesn't like) Change-Id: Iac1ca62db301892b7863711162fcbc74807eb24f
* Add missing convert_instances arg.Russell Bryant2012-07-181-1/+3
| | | | | | | | When calling jsonutils.to_primitive() recursively, the convert_instances argument should be passed along. This change fixes one place where it was not. Change-Id: I536e1ca05bb4e613fba71298797879587e8b4b00
* Track to_primitive() depth after iteritems().Russell Bryant2012-07-181-1/+1
| | | | | | | | | | | | | | | | | | Change jsonutils.to_primitive() to increase the recursion depth counter when calling to_primitive() on the result of iteritems() from the current element. Previously, the only time the counter was increased was when converting the __dict__ from an object. The iteritems() case risks cycles, as well. I hit a problem with this when trying to call to_primitive on an instance of nova.db.sqlalchemy.models.Instance. An Instance includes a reference to InstanceInfoCache, which has a reference back to the Instance. Without this change, to_primitive() would raise an exception for an Instance due to excessive recursion. Related to nova blueprint no-db-messaging. Change-Id: Ifb878368d97e92ab6c361a4dd5f5ab2e68fc16e2
* Use strtime() in to_primitive() for datetime objs.Russell Bryant2012-07-161-1/+3
| | | | | | | | | | | This patch updates jsonutils.to_primitive() to use timeutils.strtime() to convert a datimetime object to a string instead of just using str(). This ensures that we can easily convert the string back to a datetime using timeutils.parse_strtime(). Required for the nova blueprint no-db-messaging. Change-Id: I725b333695930e12e2832378102514326fec639c
* Add 'filedecoder' method to the jsonutils wrapper module.Tim Daly Jr2012-06-261-1/+5
| | | | | | | | | | | Fixes bug #1017765 After version 3.3.2, the anyjson library will throw a KeyError if filedecoder isn't present. The filedecoder is just like the decoder except it takes a file instead of a string, like json.load() instead of json.loads(). Change-Id: I7bd012a7b4afa9b1ec987c3e6393cc922b5dadff
* Make jsonutils.dumps more generalZhongyue Luo2012-06-081-2/+2
| | | | | | | | Fixes bug #1009848 Fixed jsonutils.dumps to receive other parameters Change-Id: I34836ae89359bccb689a36a7b486e85bb41d70e4
* Handle xmlrpclib.DateTime types when serializing to JSONJohannes Erdfelt2012-06-071-0/+7
| | | | | | | | | Fixes bug 1010124 Convert xmlrpclib.DateTime types to datetime so they can be serialized without creating an exception. Change-Id: Ifcab69ad81d39d7f4066df5c71c6ab6734fb1fab
* Revert "Add a load function wrapper to jsonutils"Russell Bryant2012-06-061-8/+3
| | | | | | | | | | | This reverts commit 72840edc736b7f4d2366b5049f6516d8f5b901ff. This change breaks kombu, so revert it since there is no specific need for it. Fixes bug 1009127. Change-Id: Id0ef8b3948b63d0151289cb7ce8e617d9816bb4b
* Add a load function wrapper to jsonutilsZhongyue Luo2012-06-041-3/+8
| | | | | | Fixes bug #1008065 Change-Id: I72aba29eea4637643cb7742f2fd4b1f05d15667f
* Create openstack.common.jsonutils.Russell Bryant2012-05-151-0/+133
This patch creates a new module, jsonutils. It is based on some code from nova.utils that is used by nova.rpc. It is being added to openstack-common as another step toward being able to eventually move nova.rpc to openstack-common. 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. Change-Id: I41e5759360d515ed53defe69f3e8247aafbcc83a