diff --git a/requirements-py3.txt b/requirements-py3.txt index 7746e00b..f4714583 100644 --- a/requirements-py3.txt +++ b/requirements-py3.txt @@ -10,3 +10,4 @@ zake>=0.1.6 # Apache-2.0 msgpack-python>=0.4.0 retrying>=1.2.3,!=1.3.0 # Apache-2.0 oslo.utils>=1.4.0 # Apache-2.0 +oslo.serialization>=1.4.0 # Apache-2.0 diff --git a/requirements.txt b/requirements.txt index 1f34e92e..3dd1ca6b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ msgpack-python>=0.4.0 retrying>=1.2.3,!=1.3.0 # Apache-2.0 futures>=2.1.6 oslo.utils>=1.4.0 # Apache-2.0 +oslo.serialization>=1.4.0 # Apache-2.0 diff --git a/tooz/utils.py b/tooz/utils.py index 97289a78..b6b716be 100644 --- a/tooz/utils.py +++ b/tooz/utils.py @@ -15,6 +15,7 @@ # under the License. import msgpack +from oslo_serialization import msgpackutils import six from tooz import coordination @@ -36,26 +37,18 @@ def to_binary(text, encoding='ascii'): def dumps(data, excp_cls=coordination.ToozError): - """Serializes provided data using msgpack into a byte string. - - TODO(harlowja): use oslo.serialization 'msgpackutils.py' when we can since - that handles more native types better than the default does... - """ + """Serializes provided data using msgpack into a byte string.""" try: - return msgpack.packb(data, use_bin_type=True) + return msgpackutils.dumps(data) except (msgpack.PackException, ValueError) as e: coordination.raise_with_cause(excp_cls, exception_message(e), cause=e) def loads(blob, excp_cls=coordination.ToozError): - """Deserializes provided data using msgpack (from a prior byte string). - - TODO(harlowja): use oslo.serialization 'msgpackutils.py' when we can since - that handles more native types better than the default does... - """ + """Deserializes provided data using msgpack (from a prior byte string).""" try: - return msgpack.unpackb(blob, encoding='utf-8') + return msgpackutils.loads(blob) except (msgpack.UnpackException, ValueError) as e: coordination.raise_with_cause(excp_cls, exception_message(e), cause=e)