1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can use
dict.items instead, as it will return iterators
in PY3 as well. And dict.items/keys will more readable.
2.In py2, the performance about list should be negligible,
see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html
Change-Id: Ifbe7929580ec61a2cd50232794c0cbd0cbf37edc
There is a performance impact when using dict() instead of {}
in CPython (up to 6 times longer).
Considering the to_primitive function is recursive this can
have quite an effect.
Measuring:
$ python2.7 -m timeit -n 1000000 -r 5 -v 'dict()'
raw times: 0.24 0.24 0.24 0.239 0.24
1000000 loops, best of 5: 0.239 usec per loop
$ python2.7 -m timeit -n 1000000 -r 5 -v '{}'
raw times: 0.0417 0.0413 0.0407 0.0411 0.042
1000000 loops, best of 5: 0.0407 usec per loop
For more information:
https://doughellmann.com/blog/2012/11/12/
the-performance-impact-of-using-dict-instead-of-in-cpython-2-7-2/
Change-Id: Ia0b5892773a19cbabe40313a3bc788580a943f53
There are some differences in the behaviour of json and msgpack
serializers. Msgpack throws TypeError when it doesn't know
how to handle an object. Json throws ValueError instead. Regarding
the fact that serialization should be configurable (in particular,
serializers should have similar behaviour; right now transition from
json to msgpack leads to errors and fails) this patch proposes to
raise ValueError instead of TypeError on failures so that libraries
already using jsonutils would be able to also work with msgpackutils.
Change-Id: I3d21b7d136e5a426a3c4a70a953c82ddcd6ef5af
Fixes jsonutils.to_primitive so that it can serialize ipaddress
objects, as used by Python 3 or through the backport in
global-requirements.txt. Current support for netaddr is maintained.
Change-Id: I6aa1ecd5be754f61cdda4e47bc0e0180e232b366
Closes-bug: 1590076
OpenStack has ended support for Python 2.6 in all services and
libraries. We no longer need to support a fallback to simplejson on
Python 2.6 so we can remove this fallback logic.
Closes-bug: 1533337
Change-Id: I613541a37229ff2f3ce269cfa7496223d1ff37d0
Document in which version new types and functions were added using
".. versionadded:: x.y". Document changes using
".. versionchanged:: x.y."
For base64 module, add the versionadded tag in the module top
docstring, not on each type/function.
I used "git blame" + "git tag --contains=SHA1" to find these version,
and then I checked manually each version.
Change-Id: I4a891b18064fe7b857a79c57030ff31f7a0370b4
The jsonutils.dumps() function returns bytes on Python 2 and Unicode
oon Python 3. In some cases, we always want bytes. For example, a
HTTP body must be bytes. This function avoids an condition call to
.encode() depending on the type or on the Python version.
For example:
body = jsonutils.dumps(data)
if isinstance(body, six.text_type):
body = body.encode('utf-8')
can be replaced with:
body = jsonutils.dump_as_bytes(data)
Change-Id: Ib9d8f1309982762b54d8a91b1f24f64d0ae6723a
This is a wire format change that the projects are not ready for yet (example Nova).
We should do this as part of a major version bump (2.x) with ample time for folks to move up.
Nova review to prepare the Nova code base for this change:
Ib7e60ed94edd1eb409baf8c29c61237d85944787
This reverts commit 5b0827a3df584b3e26bb44e5358cc28ac4a91636.
Change-Id: Ic4bf047b40c1dad2f8d2bc0afda934e47dba1f9d
Currently, only the dict value are converted with to_primitive().
There's no reason not to do it on keys too to support special types.
Change-Id: I5b447f2fcd814088483f67e54261131cfc87ae79
There's a few code duplications because for some reason the code
handling the recursive part got some conversion code for non-recursive
value.
Let's stack non-recursive value conversion as the top, and then use
"recursive" only where needed.
Change-Id: Ic1ecc76aba5402129a936dfb4649df0806a564a4
Following discussion in change I8b5119e64369ccac3423dccc04421f99912df733
in oslo.utils, we plan to deprecated and remove strtime() which is to be
considered dangerous.
This changes the json serialization code to embed the timezone in the
encoded datetime string if it's available.
Change-Id: I262391987d25b483d2bec4ac3abe94b6e9d032ad
Ensure jsonutils and msgpackutils headers are linkable and
connect into there associated functions and classes so that
clicking on links works (instead of not working).
Change-Id: Ifa28421e7d21a85290ee13d04918325c3f991b92
There's a different behaviour currently between dump() and dumps() as by
default dumps() use the to_primitive function provided by this module,
and dump() does not. This patch fixes that.
Change-Id: I8a116e3777901bc713e9812c1a654a51b43e702a
Move the public API out of oslo.serialization to
oslo_serialization. Retain the ability to import from the old namespace
package for backwards compatibility for this release cycle.
bp/drop-namespace-packages
Change-Id: Ic60f809ea00ac77b0753556c6fd00b97e64d57ff