This repo was created by accident, use deb-python-oslo.serialization
instead.
Needed-By: I1ac1a06931c8b6dd7c2e73620a0302c29e605f03
Change-Id: I81894aea69b9d09b0977039623c26781093a397a
Many assertEqual sentences don't follow assertEqual(expected, actual),
These misplaces have 2 impacts:
1, giving confusing messages when some tests failed.
2, mislead other developers, new test modules may follow these wrong pattern.
This patch fix all of them.
Change-Id: Ice3148685b81bf906672b91159fbb29bd618abb0
Closes-Bug: #1604213
Now that there is a passing gate job, we can claim support for
Python 3.5 in the classifier. This patch also adds the convenience
py35 venv.
Change-Id: I6f67834cc0f6f204aba2457f71e788d1fafd2640
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
This patch is a proposition to the oslo.serialization for making a
more convenient API. Let me explain briefly why the current library
isn't very convenient for its users. Imagine that a library user
want to implement a function having some (de-)serialization inside.
The user also wants to make serialization configurable through
an additional argument to the function (e.g. some id like "json",
"msgpack" etc.). One can achieve this behaviour by importing all
necessary serializers (an import per a serializer) and adding
some logic for selecting an appropriate serialization mechanism
depending on id. But what if some new serializer is added to the
oslo.serialization? Then all users of the library will have to make
changes in their code. It's not good, and I think it would be better
if all changes concerning serializers were in the oslo.serialization
library. Therefore I think it is a good idea to have a module which
will bring together all implemented serializers under a unified and
somewhat simplified (because in most cases default values for some
parameters are fine) object oriented API, so that future users of the
library will be able to get any available serializer by its id
(importing only one module). Also it is worth saying that the patch
doesn't affect already written code, so there won't be any problems
with the backward compatibility.
May be this implementation isn't the best one, but I hope
the community will appreciate the idea and propose possible
improvements.
Change-Id: Idb12666255a990dfc8f8ff6b43e941b3481b9c1c
In order to make it easy to extend the default msgpack extension
registry add a copy method to registries and select type handlers
so that a registry with additional values can be easily provided
to the various msgpack utils loads/dumps code.
This also re-adds the msgpackutils tests which appear to have
not shifted over (or otherwise disappeared somehow?) from when the
tests used to live in the root directory.
Closes-Bug: #1537716
Change-Id: I9785a9071044d0e8c044a36ae9af9912fd06c49d
If the datetime is serialized with python2 and deserializer
with python3 we got KeyError, because python3 will read
the data written with python2 as bytes and doesn't convert it in unicode.
So ensure we use always unicode everywhere.
Change-Id: I4bee7369a278fa7705cde860c68e133cee2fa79e
Closes-bug: #1556081
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
We doesn't support python 2.6 now, this commit
removes Python 2.6 related code in module msgpackutls.
Change-Id: Id148239ee6c1ad461188fa38b06ca0d7913d7454
* Remove support for python 2.6
* Remove skipsdist : Needs to be set only if
sdist is expensive
* Remove usedevelop : only needed when skipsdist
is set to True
* Remove install_command : We can just use the
default, we don't need to override
* Remove setenv : We can just use the default as
we don't need any extra environment variables
* Remove requirements.txt from deps, as this is
already added automatically
Change-Id: I741b7cae51555bc5f8d79a018598d1dccbba4459
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
Writing a code using the base64 module (of the Python standard
library) working on Python 2.7 and 3.4 requires many checks on the
input and/or output type:
* base64.b64encode() only accepts byte string: text must be
explicitly encoded to ASCII
* base64.b64decode() returns bytes: output must be decoded from UTF-8
when text is expected
This change adds two pairs of encode/decode functions:
* encode_as_bytes(), decode_as_bytes(): always return the result as
a byte string
* encode_as_text(), decode_as_text(): always return the result as a
text string
Encode functions accept text: text is encoded to UTF-8 by default,
but the encoding is configurable.
Decode functions accept text: text is decoded from ASCII.
decode_as_text() decodes the result from UTF-8 by default, but again
the encoding is configurable.
The new submodule is called "base64" to be able to replace:
import base64
with:
from oslo_serialization import base64
If the base64 module of the stdlib is needed, it can be imported as a
different name. Example:
import base64 as std_base64
The encoding example:
if isinstance(text, six.text_type):
text = text.encode('utf-8')
text_b64 = base64.b64encode(text)
text_b64 = text_b64.decode('ascii')
can be replaced with:
text_b64 = base64.encode_as_text(text)
The decoding example:
if isinstance(encoded, six.text_type):
encoded = encoded.decode('ascii')
text = base64.b64decode(encoded)
text = text.decode('utf-8')
can be replaced with:
text = base64.decode_as_text(text)
Change-Id: Icf8df9c947bc0c5f4838508b756ed8f53efd9fc4