Hello community,
here is the log from the commit of package python-u-msgpack-python for
openSUSE:Factory checked in at 2017-11-17 10:36:38
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-u-msgpack-python (Old)
and /work/SRC/openSUSE:Factory/.python-u-msgpack-python.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-u-msgpack-python"
Fri Nov 17 10:36:38 2017 rev:2 rq:541758 version:2.4.1
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-u-msgpack-python/python-u-msgpack-python.changes
2017-04-19 18:09:08.400149393 +0200
+++
/work/SRC/openSUSE:Factory/.python-u-msgpack-python.new/python-u-msgpack-python.changes
2017-11-17 10:36:40.271963156 +0100
@@ -1,0 +2,12 @@
+Mon Nov 13 18:21:56 UTC 2017 - [email protected]
+
+- update to version 2.4.1:
+ * Fix module version tuple inconsistency.
+
+- changes from version 2.4.0:
+ * Add hash special method to Ext class.
+ * Add packing option to force floating point precision.
+ * Make codebase PEP 8 compliant.
+ * Add support for tox automated testing and use it in CI.
+
+-------------------------------------------------------------------
Old:
----
u-msgpack-python-2.3.0.tar.gz
New:
----
u-msgpack-python-2.4.1.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-u-msgpack-python.spec ++++++
--- /var/tmp/diff_new_pack.WsLwfN/_old 2017-11-17 10:36:41.015935925 +0100
+++ /var/tmp/diff_new_pack.WsLwfN/_new 2017-11-17 10:36:41.019935779 +0100
@@ -15,9 +15,10 @@
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
+
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-u-msgpack-python
-Version: 2.3.0
+Version: 2.4.1
Release: 0
Summary: A portable, lightweight MessagePack serializer and deserializer
License: MIT
++++++ u-msgpack-python-2.3.0.tar.gz -> u-msgpack-python-2.4.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/u-msgpack-python-2.3.0/PKG-INFO
new/u-msgpack-python-2.4.1/PKG-INFO
--- old/u-msgpack-python-2.3.0/PKG-INFO 2016-10-19 14:55:59.000000000 +0200
+++ new/u-msgpack-python-2.4.1/PKG-INFO 2017-04-25 15:45:00.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: u-msgpack-python
-Version: 2.3.0
+Version: 2.4.1
Summary: A portable, lightweight MessagePack serializer and deserializer
written in pure Python.
Home-page: https://github.com/vsergeev/u-msgpack-python
Author: vsergeev
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/u-msgpack-python-2.3.0/setup.cfg
new/u-msgpack-python-2.4.1/setup.cfg
--- old/u-msgpack-python-2.3.0/setup.cfg 2016-10-19 14:55:59.000000000
+0200
+++ new/u-msgpack-python-2.4.1/setup.cfg 2017-04-25 15:45:00.000000000
+0200
@@ -7,5 +7,4 @@
[egg_info]
tag_build =
tag_date = 0
-tag_svn_revision = 0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/u-msgpack-python-2.3.0/setup.py
new/u-msgpack-python-2.4.1/setup.py
--- old/u-msgpack-python-2.3.0/setup.py 2016-10-19 14:55:36.000000000 +0200
+++ new/u-msgpack-python-2.4.1/setup.py 2017-04-25 15:43:31.000000000 +0200
@@ -5,7 +5,7 @@
setup(
name='u-msgpack-python',
- version='2.3.0',
+ version='2.4.1',
description='A portable, lightweight MessagePack serializer and
deserializer written in pure Python.',
author='vsergeev',
author_email='[email protected]',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/u-msgpack-python-2.3.0/test_umsgpack.py
new/u-msgpack-python-2.4.1/test_umsgpack.py
--- old/u-msgpack-python-2.3.0/test_umsgpack.py 2016-10-19 14:55:36.000000000
+0200
+++ new/u-msgpack-python-2.4.1/test_umsgpack.py 2017-04-25 15:43:28.000000000
+0200
@@ -18,207 +18,280 @@
single_test_vectors = [
# None
- [ "nil", None, b"\xc0" ],
+ ["nil", None, b"\xc0"],
# Booleans
- [ "bool false", False, b"\xc2" ],
- [ "bool true", True, b"\xc3" ],
+ ["bool false", False, b"\xc2"],
+ ["bool true", True, b"\xc3"],
# + 7-bit uint
- [ "7-bit uint", 0x00, b"\x00" ],
- [ "7-bit uint", 0x10, b"\x10" ],
- [ "7-bit uint", 0x7f, b"\x7f" ],
+ ["7-bit uint", 0x00, b"\x00"],
+ ["7-bit uint", 0x10, b"\x10"],
+ ["7-bit uint", 0x7f, b"\x7f"],
# - 5-bit int
- [ "5-bit sint", -1, b"\xff" ],
- [ "5-bit sint", -16, b"\xf0" ],
- [ "5-bit sint", -32, b"\xe0" ],
+ ["5-bit sint", -1, b"\xff"],
+ ["5-bit sint", -16, b"\xf0"],
+ ["5-bit sint", -32, b"\xe0"],
# 8-bit uint
- [ "8-bit uint", 0x80, b"\xcc\x80" ],
- [ "8-bit uint", 0xf0, b"\xcc\xf0" ],
- [ "8-bit uint", 0xff, b"\xcc\xff" ],
+ ["8-bit uint", 0x80, b"\xcc\x80"],
+ ["8-bit uint", 0xf0, b"\xcc\xf0"],
+ ["8-bit uint", 0xff, b"\xcc\xff"],
# 16-bit uint
- [ "16-bit uint", 0x100, b"\xcd\x01\x00" ],
- [ "16-bit uint", 0x2000, b"\xcd\x20\x00" ],
- [ "16-bit uint", 0xffff, b"\xcd\xff\xff" ],
+ ["16-bit uint", 0x100, b"\xcd\x01\x00"],
+ ["16-bit uint", 0x2000, b"\xcd\x20\x00"],
+ ["16-bit uint", 0xffff, b"\xcd\xff\xff"],
# 32-bit uint
- [ "32-bit uint", 0x10000, b"\xce\x00\x01\x00\x00" ],
- [ "32-bit uint", 0x200000, b"\xce\x00\x20\x00\x00" ],
- [ "32-bit uint", 0xffffffff, b"\xce\xff\xff\xff\xff" ],
+ ["32-bit uint", 0x10000, b"\xce\x00\x01\x00\x00"],
+ ["32-bit uint", 0x200000, b"\xce\x00\x20\x00\x00"],
+ ["32-bit uint", 0xffffffff, b"\xce\xff\xff\xff\xff"],
# 64-bit uint
- [ "64-bit uint", 0x100000000, b"\xcf\x00\x00\x00\x01\x00\x00\x00\x00" ],
- [ "64-bit uint", 0x200000000000, b"\xcf\x00\x00\x20\x00\x00\x00\x00\x00" ],
- [ "64-bit uint", 0xffffffffffffffff,
b"\xcf\xff\xff\xff\xff\xff\xff\xff\xff" ],
+ ["64-bit uint", 0x100000000, b"\xcf\x00\x00\x00\x01\x00\x00\x00\x00"],
+ ["64-bit uint", 0x200000000000, b"\xcf\x00\x00\x20\x00\x00\x00\x00\x00"],
+ ["64-bit uint", 0xffffffffffffffff,
b"\xcf\xff\xff\xff\xff\xff\xff\xff\xff"],
# 8-bit int
- [ "8-bit int", -33, b"\xd0\xdf" ],
- [ "8-bit int", -100, b"\xd0\x9c" ],
- [ "8-bit int", -128, b"\xd0\x80" ],
+ ["8-bit int", -33, b"\xd0\xdf"],
+ ["8-bit int", -100, b"\xd0\x9c"],
+ ["8-bit int", -128, b"\xd0\x80"],
# 16-bit int
- [ "16-bit int", -129, b"\xd1\xff\x7f" ],
- [ "16-bit int", -2000, b"\xd1\xf8\x30" ],
- [ "16-bit int", -32768, b"\xd1\x80\x00" ],
+ ["16-bit int", -129, b"\xd1\xff\x7f"],
+ ["16-bit int", -2000, b"\xd1\xf8\x30"],
+ ["16-bit int", -32768, b"\xd1\x80\x00"],
# 32-bit int
- [ "32-bit int", -32769, b"\xd2\xff\xff\x7f\xff" ],
- [ "32-bit int", -1000000000, b"\xd2\xc4\x65\x36\x00" ],
- [ "32-bit int", -2147483648, b"\xd2\x80\x00\x00\x00" ],
+ ["32-bit int", -32769, b"\xd2\xff\xff\x7f\xff"],
+ ["32-bit int", -1000000000, b"\xd2\xc4\x65\x36\x00"],
+ ["32-bit int", -2147483648, b"\xd2\x80\x00\x00\x00"],
# 64-bit int
- [ "64-bit int", -2147483649, b"\xd3\xff\xff\xff\xff\x7f\xff\xff\xff" ],
- [ "64-bit int", -1000000000000000002,
b"\xd3\xf2\x1f\x49\x4c\x58\x9b\xff\xfe" ],
- [ "64-bit int", -9223372036854775808,
b"\xd3\x80\x00\x00\x00\x00\x00\x00\x00" ],
+ ["64-bit int", -2147483649, b"\xd3\xff\xff\xff\xff\x7f\xff\xff\xff"],
+ ["64-bit int", -1000000000000000002,
b"\xd3\xf2\x1f\x49\x4c\x58\x9b\xff\xfe"],
+ ["64-bit int", -9223372036854775808,
b"\xd3\x80\x00\x00\x00\x00\x00\x00\x00"],
# 64-bit float
- [ "64-bit float", 0.0, b"\xcb\x00\x00\x00\x00\x00\x00\x00\x00" ],
- [ "64-bit float", 2.5, b"\xcb\x40\x04\x00\x00\x00\x00\x00\x00" ],
- [ "64-bit float", float(10**35), b"\xcb\x47\x33\x42\x61\x72\xc7\x4d\x82" ],
+ ["64-bit float", 0.0, b"\xcb\x00\x00\x00\x00\x00\x00\x00\x00"],
+ ["64-bit float", 2.5, b"\xcb\x40\x04\x00\x00\x00\x00\x00\x00"],
+ ["64-bit float", float(10**35), b"\xcb\x47\x33\x42\x61\x72\xc7\x4d\x82"],
# Fixstr String
- [ "fix string", u"", b"\xa0" ],
- [ "fix string", u"a", b"\xa1\x61" ],
- [ "fix string", u"abc", b"\xa3\x61\x62\x63" ],
- [ "fix string", u"a"*31, b"\xbf" + b"\x61"*31 ],
+ ["fix string", u"", b"\xa0"],
+ ["fix string", u"a", b"\xa1\x61"],
+ ["fix string", u"abc", b"\xa3\x61\x62\x63"],
+ ["fix string", u"a" * 31, b"\xbf" + b"\x61" * 31],
# 8-bit String
- [ "8-bit string", u"b"*32, b"\xd9\x20" + b"b"*32 ],
- [ "8-bit string", u"c"*100, b"\xd9\x64" + b"c"*100 ],
- [ "8-bit string", u"d"*255, b"\xd9\xff" + b"d"*255 ],
+ ["8-bit string", u"b" * 32, b"\xd9\x20" + b"b" * 32],
+ ["8-bit string", u"c" * 100, b"\xd9\x64" + b"c" * 100],
+ ["8-bit string", u"d" * 255, b"\xd9\xff" + b"d" * 255],
# 16-bit String
- [ "16-bit string", u"b"*256, b"\xda\x01\x00" + b"b"*256 ],
- [ "16-bit string", u"c"*65535, b"\xda\xff\xff" + b"c"*65535 ],
+ ["16-bit string", u"b" * 256, b"\xda\x01\x00" + b"b" * 256],
+ ["16-bit string", u"c" * 65535, b"\xda\xff\xff" + b"c" * 65535],
# 32-bit String
- [ "32-bit string", u"b"*65536, b"\xdb\x00\x01\x00\x00" + b"b"*65536 ],
+ ["32-bit string", u"b" * 65536, b"\xdb\x00\x01\x00\x00" + b"b" * 65536],
# Wide character String
- [ "wide char string", u"Allagbé", b"\xa8Allagb\xc3\xa9" ],
- [ "wide char string", u"По оживлённым берегам",
b"\xd9\x28\xd0\x9f\xd0\xbe\x20\xd0\xbe\xd0\xb6\xd0\xb8\xd0\xb2\xd0\xbb\xd1\x91\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xbc\x20\xd0\xb1\xd0\xb5\xd1\x80\xd0\xb5\xd0\xb3\xd0\xb0\xd0\xbc"
],
+ ["wide char string", u"Allagbé", b"\xa8Allagb\xc3\xa9"],
+ ["wide char string", u"По оживлённым берегам",
+
b"\xd9\x28\xd0\x9f\xd0\xbe\x20\xd0\xbe\xd0\xb6\xd0\xb8\xd0\xb2\xd0\xbb\xd1\x91\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xbc\x20\xd0\xb1\xd0\xb5\xd1\x80\xd0\xb5\xd0\xb3\xd0\xb0\xd0\xbc"],
# 8-bit Binary
- [ "8-bit binary", b"\x80"*1, b"\xc4\x01" + b"\x80"*1 ],
- [ "8-bit binary", b"\x80"*32, b"\xc4\x20" + b"\x80"*32 ],
- [ "8-bit binary", b"\x80"*255, b"\xc4\xff" + b"\x80"*255 ],
+ ["8-bit binary", b"\x80" * 1, b"\xc4\x01" + b"\x80" * 1],
+ ["8-bit binary", b"\x80" * 32, b"\xc4\x20" + b"\x80" * 32],
+ ["8-bit binary", b"\x80" * 255, b"\xc4\xff" + b"\x80" * 255],
# 16-bit Binary
- [ "16-bit binary", b"\x80"*256, b"\xc5\x01\x00" + b"\x80"*256 ],
+ ["16-bit binary", b"\x80" * 256, b"\xc5\x01\x00" + b"\x80" * 256],
# 32-bit Binary
- [ "32-bit binary", b"\x80"*65536, b"\xc6\x00\x01\x00\x00" + b"\x80"*65536
],
+ ["32-bit binary", b"\x80" * 65536, b"\xc6\x00\x01\x00\x00" + b"\x80" *
65536],
# Fixext 1
- [ "fixext 1", umsgpack.Ext(0x05, b"\x80"*1), b"\xd4\x05" + b"\x80"*1 ],
+ ["fixext 1", umsgpack.Ext(0x05, b"\x80" * 1), b"\xd4\x05" + b"\x80" * 1],
# Fixext 2
- [ "fixext 2", umsgpack.Ext(0x05, b"\x80"*2), b"\xd5\x05" + b"\x80"*2 ],
+ ["fixext 2", umsgpack.Ext(0x05, b"\x80" * 2), b"\xd5\x05" + b"\x80" * 2],
# Fixext 4
- [ "fixext 4", umsgpack.Ext(0x05, b"\x80"*4), b"\xd6\x05" + b"\x80"*4 ],
+ ["fixext 4", umsgpack.Ext(0x05, b"\x80" * 4), b"\xd6\x05" + b"\x80" * 4],
# Fixext 8
- [ "fixext 8", umsgpack.Ext(0x05, b"\x80"*8), b"\xd7\x05" + b"\x80"*8 ],
+ ["fixext 8", umsgpack.Ext(0x05, b"\x80" * 8), b"\xd7\x05" + b"\x80" * 8],
# Fixext 16
- [ "fixext 16", umsgpack.Ext(0x05, b"\x80"*16), b"\xd8\x05" + b"\x80"*16 ],
+ ["fixext 16", umsgpack.Ext(0x05, b"\x80" * 16),
+ b"\xd8\x05" + b"\x80" * 16],
# 8-bit Ext
- [ "8-bit ext", umsgpack.Ext(0x05, b"\x80"*255), b"\xc7\xff\x05" +
b"\x80"*255 ],
+ ["8-bit ext", umsgpack.Ext(0x05, b"\x80" * 255),
+ b"\xc7\xff\x05" + b"\x80" * 255],
# 16-bit Ext
- [ "16-bit ext", umsgpack.Ext(0x05, b"\x80"*256), b"\xc8\x01\x00\x05" +
b"\x80"*256 ],
+ ["16-bit ext", umsgpack.Ext(0x05, b"\x80" * 256),
+ b"\xc8\x01\x00\x05" + b"\x80" * 256],
# 32-bit Ext
- [ "32-bit ext", umsgpack.Ext(0x05, b"\x80"*65536),
b"\xc9\x00\x01\x00\x00\x05" + b"\x80"*65536 ],
+ ["32-bit ext", umsgpack.Ext(0x05, b"\x80" * 65536),
+ b"\xc9\x00\x01\x00\x00\x05" + b"\x80" * 65536],
# Empty Array
- [ "empty array", [], b"\x90" ],
+ ["empty array", [], b"\x90"],
# Empty Map
- [ "empty map", {}, b"\x80" ],
+ ["empty map", {}, b"\x80"],
]
composite_test_vectors = [
# Fix Array
- [ "fix array", [ 5, u"abc", True ], b"\x93\x05\xa3\x61\x62\x63\xc3" ],
+ ["fix array", [5, u"abc", True],
+ b"\x93\x05\xa3\x61\x62\x63\xc3"],
# 16-bit Array
- [ "16-bit array", [ 0x05 ]*16, b"\xdc\x00\x10" + b"\x05"*16 ],
- [ "16-bit array", [ 0x05 ]*65535, b"\xdc\xff\xff" + b"\x05"*65535 ],
+ ["16-bit array", [0x05] * 16,
+ b"\xdc\x00\x10" + b"\x05" * 16],
+ ["16-bit array", [0x05] * 65535,
+ b"\xdc\xff\xff" + b"\x05" * 65535],
# 32-bit Array
- [ "32-bit array", [ 0x05 ]*65536, b"\xdd\x00\x01\x00\x00" + b"\x05"*65536
],
+ ["32-bit array", [0x05] * 65536,
+ b"\xdd\x00\x01\x00\x00" + b"\x05" * 65536],
# Fix Map
- [ "fix map", OrderedDict([(1, True), (2, u"abc"), (3, b"\x80")]),
b"\x83\x01\xc3\x02\xa3\x61\x62\x63\x03\xc4\x01\x80" ],
- [ "fix map", { u"abc" : 5 }, b"\x81\xa3\x61\x62\x63\x05" ],
- [ "fix map", { b"\x80" : 0xffff }, b"\x81\xc4\x01\x80\xcd\xff\xff" ],
- [ "fix map", { True : None }, b"\x81\xc3\xc0" ],
+ ["fix map", OrderedDict([(1, True), (2, u"abc"), (3, b"\x80")]),
+ b"\x83\x01\xc3\x02\xa3\x61\x62\x63\x03\xc4\x01\x80"],
+ ["fix map", {u"abc": 5},
+ b"\x81\xa3\x61\x62\x63\x05"],
+ ["fix map", {b"\x80": 0xffff},
+ b"\x81\xc4\x01\x80\xcd\xff\xff"],
+ ["fix map", {True: None},
+ b"\x81\xc3\xc0"],
# 16-bit Map
- [ "16-bit map", OrderedDict([(k, 0x05) for k in range(16)]),
b"\xde\x00\x10" + b"".join([struct.pack("B", i) + b"\x05" for i in range(16)])],
- [ "16-bit map", OrderedDict([(k, 0x05) for k in range(6000)]),
b"\xde\x17\x70" + b"".join([struct.pack("B", i) + b"\x05" for i in range(128)])
+ b"".join([b"\xcc" + struct.pack("B", i) + b"\x05" for i in range(128, 256)])
+ b"".join([b"\xcd" + struct.pack(">H", i) + b"\x05" for i in range(256,
6000)]) ],
+ ["16-bit map", OrderedDict([(k, 0x05) for k in range(16)]),
+ b"\xde\x00\x10" + b"".join([struct.pack("B", i) + b"\x05" for i in
range(16)])],
+ ["16-bit map", OrderedDict([(k, 0x05) for k in range(6000)]),
+ b"\xde\x17\x70" + b"".join([struct.pack("B", i) + b"\x05" for i in
range(128)]) +
+ b"".join([b"\xcc" + struct.pack("B", i) + b"\x05" for i in range(128,
256)]) +
+ b"".join([b"\xcd" + struct.pack(">H", i) + b"\x05" for i in range(256,
6000)])],
# Complex Array
- [ "complex array", [ True, 0x01, umsgpack.Ext(0x03, b"foo"), 0xff,
OrderedDict([(1, False), (2, u"abc")]), b"\x80", [1, 2, 3], u"abc" ],
b"\x98\xc3\x01\xc7\x03\x03\x66\x6f\x6f\xcc\xff\x82\x01\xc2\x02\xa3\x61\x62\x63\xc4\x01\x80\x93\x01\x02\x03\xa3\x61\x62\x63"
],
+ ["complex array", [True, 0x01, umsgpack.Ext(0x03, b"foo"), 0xff,
+ OrderedDict([(1, False), (2, u"abc")]), b"\x80",
+ [1, 2, 3], u"abc"],
+
b"\x98\xc3\x01\xc7\x03\x03\x66\x6f\x6f\xcc\xff\x82\x01\xc2\x02\xa3\x61\x62\x63\xc4\x01\x80\x93\x01\x02\x03\xa3\x61\x62\x63"],
# Complex Map
- [ "complex map", OrderedDict([(1, [OrderedDict([(1, 2), (3, 4)]), {}]),
(2, 1), (3, [False, u"def"]), (4, OrderedDict([(0x100000000, u"a"),
(0xffffffff, u"b")]))]),
b"\x84\x01\x92\x82\x01\x02\x03\x04\x80\x02\x01\x03\x92\xc2\xa3\x64\x65\x66\x04\x82\xcf\x00\x00\x00\x01\x00\x00\x00\x00\xa1\x61\xce\xff\xff\xff\xff\xa1\x62"
],
+ ["complex map", OrderedDict([(1, [OrderedDict([(1, 2), (3, 4)]), {}]),
+ (2, 1), (3, [False, u"def"]),
+ (4, OrderedDict([(0x100000000, u"a"),
+ (0xffffffff, u"b")]))]),
+
b"\x84\x01\x92\x82\x01\x02\x03\x04\x80\x02\x01\x03\x92\xc2\xa3\x64\x65\x66\x04\x82\xcf\x00\x00\x00\x01\x00\x00\x00\x00\xa1\x61\xce\xff\xff\xff\xff\xa1\x62"],
# Map with Tuple Keys
- [ "map with tuple keys", OrderedDict([((u"foo", False, 3), True), ((3e6,
-5), u"def")]),
b"\x82\x93\xa3\x66\x6f\x6f\xc2\x03\xc3\x92\xcb\x41\x46\xe3\x60\x00\x00\x00\x00\xfb\xa3\x64\x65\x66"
],
+ ["map with tuple keys", OrderedDict([((u"foo", False, 3), True),
+ ((3e6, -5), u"def")]),
+
b"\x82\x93\xa3\x66\x6f\x6f\xc2\x03\xc3\x92\xcb\x41\x46\xe3\x60\x00\x00\x00\x00\xfb\xa3\x64\x65\x66"],
# Map with Complex Tuple Keys
- [ "map with complex tuple keys", {(u"foo", (1,2,3), 3) : -5},
b"\x81\x93\xa3\x66\x6f\x6f\x93\x01\x02\x03\x03\xfb" ]
+ ["map with complex tuple keys", {(u"foo", (1, 2, 3), 3): -5},
+ b"\x81\x93\xa3\x66\x6f\x6f\x93\x01\x02\x03\x03\xfb"]
]
pack_exception_test_vectors = [
# Unsupported type exception
- [ "unsupported type", set([1,2,3]), umsgpack.UnsupportedTypeException ],
- [ "unsupported type", -2**(64-1)-1, umsgpack.UnsupportedTypeException ],
- [ "unsupported type", 2**64, umsgpack.UnsupportedTypeException ],
+ ["unsupported type", set([1, 2, 3]), umsgpack.UnsupportedTypeException],
+ ["unsupported type", -2**(64 - 1) - 1, umsgpack.UnsupportedTypeException],
+ ["unsupported type", 2**64, umsgpack.UnsupportedTypeException],
]
unpack_exception_test_vectors = [
# Type errors
- [ "type error unpack unicode string", u"\x01", TypeError ],
- [ "type error unpack boolean", True, TypeError ],
+ ["type error unpack unicode string", u"\x01", TypeError],
+ ["type error unpack boolean", True, TypeError],
# Insufficient data to unpack object
- [ "insufficient data 8-bit uint", b"\xcc",
umsgpack.InsufficientDataException ],
- [ "insufficient data 16-bit uint", b"\xcd\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit uint", b"\xce\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 64-bit uint", b"\xcf\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 8-bit int", b"\xd0",
umsgpack.InsufficientDataException ],
- [ "insufficient data 16-bit int", b"\xd1\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit int", b"\xd2\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 64-bit int", b"\xd3\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit float", b"\xca\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data 64-bit float", b"\xcb\xff",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixstr", b"\xa1", umsgpack.InsufficientDataException
],
- [ "insufficient data 8-bit string", b"\xd9",
umsgpack.InsufficientDataException ],
- [ "insufficient data 8-bit string", b"\xd9\x01",
umsgpack.InsufficientDataException ],
- [ "insufficient data 16-bit string", b"\xda\x01\x00",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit string", b"\xdb\x00\x01\x00\x00",
umsgpack.InsufficientDataException ],
- [ "insufficient data 8-bit binary", b"\xc4",
umsgpack.InsufficientDataException ],
- [ "insufficient data 8-bit binary", b"\xc4\x01",
umsgpack.InsufficientDataException ],
- [ "insufficient data 16-bit binary", b"\xc5\x01\x00",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit binary", b"\xc6\x00\x01\x00\x00",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixarray", b"\x91",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixarray", b"\x92\xc2",
umsgpack.InsufficientDataException ],
- [ "insufficient data 16-bit array", b"\xdc\x00\xf0\xc2\xc3",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit array", b"\xdd\x00\x01\x00\x00\xc2\xc3",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixmap", b"\x81", umsgpack.InsufficientDataException
],
- [ "insufficient data fixmap", b"\x82\xc2\xc3",
umsgpack.InsufficientDataException ],
- [ "insufficient data 16-bit map", b"\xde\x00\xf0\xc2\xc3",
umsgpack.InsufficientDataException ],
- [ "insufficient data 32-bit map", b"\xdf\x00\x01\x00\x00\xc2\xc3",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixext 1", b"\xd4",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixext 1", b"\xd4\x05",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixext 2", b"\xd5\x05\x01",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixext 4", b"\xd6\x05\x01\x02\x03",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixext 8", b"\xd7\x05\x01\x02\x03",
umsgpack.InsufficientDataException ],
- [ "insufficient data fixext 16", b"\xd8\x05\x01\x02\x03",
umsgpack.InsufficientDataException ],
- [ "insufficient data ext 8-bit", b"\xc7\x05\x05\x01\x02\x03",
umsgpack.InsufficientDataException ],
- [ "insufficient data ext 16-bit", b"\xc8\x01\x00\x05\x01\x02\x03",
umsgpack.InsufficientDataException ],
- [ "insufficient data ext 32-bit", b"\xc9\x00\x01\x00\x00\x05\x01\x02\x03",
umsgpack.InsufficientDataException ],
+ ["insufficient data 8-bit uint", b"\xcc",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 16-bit uint", b"\xcd\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit uint", b"\xce\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 64-bit uint", b"\xcf\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 8-bit int", b"\xd0",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 16-bit int", b"\xd1\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit int", b"\xd2\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 64-bit int", b"\xd3\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit float", b"\xca\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 64-bit float", b"\xcb\xff",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixstr", b"\xa1",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 8-bit string", b"\xd9",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 8-bit string", b"\xd9\x01",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 16-bit string", b"\xda\x01\x00",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit string", b"\xdb\x00\x01\x00\x00",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 8-bit binary", b"\xc4",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 8-bit binary", b"\xc4\x01",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 16-bit binary", b"\xc5\x01\x00",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit binary", b"\xc6\x00\x01\x00\x00",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixarray", b"\x91",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixarray", b"\x92\xc2",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 16-bit array", b"\xdc\x00\xf0\xc2\xc3",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit array", b"\xdd\x00\x01\x00\x00\xc2\xc3",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixmap", b"\x81",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixmap", b"\x82\xc2\xc3",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 16-bit map", b"\xde\x00\xf0\xc2\xc3",
+ umsgpack.InsufficientDataException],
+ ["insufficient data 32-bit map", b"\xdf\x00\x01\x00\x00\xc2\xc3",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixext 1", b"\xd4",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixext 1", b"\xd4\x05",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixext 2", b"\xd5\x05\x01",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixext 4", b"\xd6\x05\x01\x02\x03",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixext 8", b"\xd7\x05\x01\x02\x03",
+ umsgpack.InsufficientDataException],
+ ["insufficient data fixext 16", b"\xd8\x05\x01\x02\x03",
+ umsgpack.InsufficientDataException],
+ ["insufficient data ext 8-bit", b"\xc7\x05\x05\x01\x02\x03",
+ umsgpack.InsufficientDataException],
+ ["insufficient data ext 16-bit", b"\xc8\x01\x00\x05\x01\x02\x03",
+ umsgpack.InsufficientDataException],
+ ["insufficient data ext 32-bit", b"\xc9\x00\x01\x00\x00\x05\x01\x02\x03",
+ umsgpack.InsufficientDataException],
# Unhashable key { 1 : True, { 1 : 1 } : False }
- [ "unhashable key", b"\x82\x01\xc3\x81\x01\x01\xc2",
umsgpack.UnhashableKeyException ],
+ ["unhashable key", b"\x82\x01\xc3\x81\x01\x01\xc2",
+ umsgpack.UnhashableKeyException],
# Unhashable key { [ 1, 2, {} ] : True }
- [ "unhashable key", b"\x81\x93\x01\x02\x80\xc3",
umsgpack.UnhashableKeyException ],
+ ["unhashable key", b"\x81\x93\x01\x02\x80\xc3",
+ umsgpack.UnhashableKeyException],
# Key duplicate { 1 : True, 1 : False }
- [ "duplicate key", b"\x82\x01\xc3\x01\xc2", umsgpack.DuplicateKeyException
],
+ ["duplicate key", b"\x82\x01\xc3\x01\xc2",
+ umsgpack.DuplicateKeyException],
# Reserved code (0xc1)
- [ "reserved code", b"\xc1", umsgpack.ReservedCodeException ],
+ ["reserved code", b"\xc1",
+ umsgpack.ReservedCodeException],
# Invalid string (non utf-8)
- [ "invalid string", b"\xa1\x80", umsgpack.InvalidStringException ],
+ ["invalid string", b"\xa1\x80",
+ umsgpack.InvalidStringException],
]
compatibility_test_vectors = [
# Fix Raw
- [ "fix raw", b"", b"\xa0" ],
- [ "fix raw", u"", b"\xa0" ],
- [ "fix raw", b"a", b"\xa1\x61" ],
- [ "fix raw", u"a", b"\xa1\x61" ],
- [ "fix raw", b"abc", b"\xa3\x61\x62\x63" ],
- [ "fix raw", u"abc", b"\xa3\x61\x62\x63" ],
- [ "fix raw", b"a"*31, b"\xbf" + b"\x61"*31 ],
- [ "fix raw", u"a"*31, b"\xbf" + b"\x61"*31 ],
+ ["fix raw", b"", b"\xa0"],
+ ["fix raw", u"", b"\xa0"],
+ ["fix raw", b"a", b"\xa1\x61"],
+ ["fix raw", u"a", b"\xa1\x61"],
+ ["fix raw", b"abc", b"\xa3\x61\x62\x63"],
+ ["fix raw", u"abc", b"\xa3\x61\x62\x63"],
+ ["fix raw", b"a" * 31, b"\xbf" + b"\x61" * 31],
+ ["fix raw", u"a" * 31, b"\xbf" + b"\x61" * 31],
# 16-bit Raw
- [ "16-bit raw", u"b"*32, b"\xda\x00\x20" + b"b"*32 ],
- [ "16-bit raw", b"b"*32, b"\xda\x00\x20" + b"b"*32 ],
- [ "16-bit raw", u"b"*256, b"\xda\x01\x00" + b"b"*256 ],
- [ "16-bit raw", b"b"*256, b"\xda\x01\x00" + b"b"*256 ],
- [ "16-bit raw", u"c"*65535, b"\xda\xff\xff" + b"c"*65535 ],
- [ "16-bit raw", b"c"*65535, b"\xda\xff\xff" + b"c"*65535 ],
+ ["16-bit raw", u"b" * 32, b"\xda\x00\x20" + b"b" * 32],
+ ["16-bit raw", b"b" * 32, b"\xda\x00\x20" + b"b" * 32],
+ ["16-bit raw", u"b" * 256, b"\xda\x01\x00" + b"b" * 256],
+ ["16-bit raw", b"b" * 256, b"\xda\x01\x00" + b"b" * 256],
+ ["16-bit raw", u"c" * 65535, b"\xda\xff\xff" + b"c" * 65535],
+ ["16-bit raw", b"c" * 65535, b"\xda\xff\xff" + b"c" * 65535],
# 32-bit Raw
- [ "32-bit raw", u"b"*65536, b"\xdb\x00\x01\x00\x00" + b"b"*65536 ],
- [ "32-bit raw", b"b"*65536, b"\xdb\x00\x01\x00\x00" + b"b"*65536 ],
+ ["32-bit raw", u"b" * 65536, b"\xdb\x00\x01\x00\x00" + b"b" * 65536],
+ ["32-bit raw", b"b" * 65536, b"\xdb\x00\x01\x00\x00" + b"b" * 65536],
+]
+
+float_precision_test_vectors = [
+ ["float precision single", 2.5, b"\xca\x40\x20\x00\x00"],
+ ["float precision double", 2.5, b"\xcb\x40\x04\x00\x00\x00\x00\x00\x00"],
]
CustomType = namedtuple('CustomType', ['x', 'y', 'z'])
@@ -231,8 +304,9 @@
}
ext_handlers_test_vectors = [
- [ "complex", complex(1, 2), b"\xd7\x20\x00\x00\x80\x3f\x00\x00\x00\x40" ],
- [ "custom type", CustomType(b"abc", 123, True),
b"\xd7\x30\x93\xc4\x03\x61\x62\x63\x7b\xc3" ],
+ ["complex", complex(1, 2), b"\xd7\x20\x00\x00\x80\x3f\x00\x00\x00\x40"],
+ ["custom type", CustomType(b"abc", 123, True),
+ b"\xd7\x30\x93\xc4\x03\x61\x62\x63\x7b\xc3"],
]
# These are the only global variables that should be exported by umsgpack
@@ -261,32 +335,42 @@
"compatibility",
]
-################################################################################
+##########################################################################
+
class TestUmsgpack(unittest.TestCase):
+
def test_pack_single(self):
for (name, obj, data) in single_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
self.assertEqual(umsgpack.packb(obj), data)
def test_pack_composite(self):
for (name, obj, data) in composite_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
self.assertEqual(umsgpack.packb(obj), data)
def test_pack_exceptions(self):
for (name, obj, exception) in pack_exception_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
with self.assertRaises(exception):
umsgpack.packb(obj)
def test_unpack_single(self):
for (name, obj, data) in single_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
unpacked = umsgpack.unpackb(data)
# In Python2, we have both int and long integer types, but which
@@ -294,7 +378,8 @@
if sys.version_info[0] == 2:
# Allow both {int,long} -> unpackb -> {int,long}
if isinstance(obj, int) or isinstance(obj, long):
- self.assertTrue(isinstance(unpacked, int) or
isinstance(unpacked, long))
+ self.assertTrue(isinstance(unpacked, int) or
+ isinstance(unpacked, long))
else:
self.assertTrue(isinstance(unpacked, type(obj)))
# In Python3, we only have the int integer type
@@ -306,12 +391,15 @@
def test_unpack_composite(self):
for (name, obj, data) in composite_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
self.assertEqual(umsgpack.unpackb(data), obj)
def test_unpack_exceptions(self):
for (name, data, exception) in unpack_exception_test_vectors:
print("\tTesting %s" % name)
+
with self.assertRaises(exception):
umsgpack.unpackb(data)
@@ -320,7 +408,9 @@
for (name, obj, data) in compatibility_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
self.assertEqual(umsgpack.packb(obj), data)
umsgpack.compatibility = False
@@ -330,7 +420,9 @@
for (name, obj, data) in compatibility_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
unpacked = umsgpack.unpackb(data)
# Encoded raw should always unpack to bytes in compatibility mode,
@@ -385,14 +477,29 @@
def test_pack_ext_handler(self):
for (name, obj, data) in ext_handlers_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
- self.assertEqual(umsgpack.packb(obj, ext_handlers=ext_handlers),
data)
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
+ packed = umsgpack.packb(obj, ext_handlers=ext_handlers)
+ self.assertEqual(packed, data)
def test_unpack_ext_handler(self):
for (name, obj, data) in ext_handlers_test_vectors:
obj_repr = repr(obj)
- print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr)
< 24 else obj_repr[0:24] + "..."))
- self.assertEqual(umsgpack.unpackb(data,
ext_handlers=ext_handlers), obj)
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
+ unpacked = umsgpack.unpackb(data, ext_handlers=ext_handlers)
+ self.assertEqual(unpacked, obj)
+
+ def test_pack_force_float_precision(self):
+ for ((name, obj, data), precision) in
zip(float_precision_test_vectors, ["single", "double"]):
+ obj_repr = repr(obj)
+ print("\tTesting %s: object %s" %
+ (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] +
"..."))
+
+ packed = umsgpack.packb(obj, force_float_precision=precision)
+ self.assertEqual(packed, data)
def test_streaming_writer(self):
# Try first composite test vector
@@ -409,13 +516,16 @@
def test_namespacing(self):
# Get a list of global variables from umsgpack module
- exported_vars = list(filter(lambda x: not x.startswith("_"),
dir(umsgpack)))
+ exported_vars = list(filter(lambda x: not x.startswith("_"),
+ dir(umsgpack)))
# Ignore imports
- exported_vars = list(filter(lambda x: x != "struct" and x !=
"collections" and x != "sys" and x != "io" and x != "xrange", exported_vars))
+ exported_vars = list(filter(lambda x: x != "struct" and x !=
"collections" and x !=
+ "sys" and x != "io" and x != "xrange",
exported_vars))
self.assertTrue(len(exported_vars) == len(exported_vars_test_vector))
for var in exported_vars_test_vector:
self.assertTrue(var in exported_vars)
+
if __name__ == '__main__':
unittest.main()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/u-msgpack-python-2.3.0/u_msgpack_python.egg-info/PKG-INFO
new/u-msgpack-python-2.4.1/u_msgpack_python.egg-info/PKG-INFO
--- old/u-msgpack-python-2.3.0/u_msgpack_python.egg-info/PKG-INFO
2016-10-19 14:55:59.000000000 +0200
+++ new/u-msgpack-python-2.4.1/u_msgpack_python.egg-info/PKG-INFO
2017-04-25 15:45:00.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: u-msgpack-python
-Version: 2.3.0
+Version: 2.4.1
Summary: A portable, lightweight MessagePack serializer and deserializer
written in pure Python.
Home-page: https://github.com/vsergeev/u-msgpack-python
Author: vsergeev
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/u-msgpack-python-2.3.0/umsgpack.py
new/u-msgpack-python-2.4.1/umsgpack.py
--- old/u-msgpack-python-2.3.0/umsgpack.py 2016-10-19 14:55:36.000000000
+0200
+++ new/u-msgpack-python-2.4.1/umsgpack.py 2017-04-25 15:43:31.000000000
+0200
@@ -1,4 +1,4 @@
-# u-msgpack-python v2.3.0 - v at sergeev.io
+# u-msgpack-python v2.4.1 - v at sergeev.io
# https://github.com/vsergeev/u-msgpack-python
#
# u-msgpack-python is a lightweight MessagePack serializer and deserializer
@@ -31,7 +31,7 @@
# THE SOFTWARE.
#
"""
-u-msgpack-python v2.3.0 - v at sergeev.io
+u-msgpack-python v2.4.1 - v at sergeev.io
https://github.com/vsergeev/u-msgpack-python
u-msgpack-python is a lightweight MessagePack serializer and deserializer
@@ -43,21 +43,21 @@
License: MIT
"""
+import struct
+import collections
+import sys
+import io
-__version__ = "2.3.0"
+__version__ = "2.4.1"
"Module version string"
-version = (2,3,0)
+version = (2, 4, 1)
"Module version tuple"
-import struct
-import collections
-import sys
-import io
-################################################################################
-### Ext Class
-################################################################################
+##############################################################################
+# Ext Class
+##############################################################################
# Extension type for application-defined types and data
class Ext:
@@ -117,60 +117,82 @@
String representation of this Ext object.
"""
s = "Ext Object (Type: 0x%02x, Data: " % self.type
- s += " ".join(["0x%02x" % ord(self.data[i:i+1]) for i in
xrange(min(len(self.data), 8))])
+ s += " ".join(["0x%02x" % ord(self.data[i:i + 1])
+ for i in xrange(min(len(self.data), 8))])
if len(self.data) > 8:
s += " ..."
s += ")"
return s
+ def __hash__(self):
+ """
+ Provide a hash of this Ext object.
+ """
+ return hash((self.type, self.data))
+
+
class InvalidString(bytes):
"""Subclass of bytes to hold invalid UTF-8 strings."""
pass
-################################################################################
-### Exceptions
-################################################################################
+##############################################################################
+# Exceptions
+##############################################################################
+
# Base Exception classes
class PackException(Exception):
"Base class for exceptions encountered during packing."
pass
+
+
class UnpackException(Exception):
"Base class for exceptions encountered during unpacking."
pass
+
# Packing error
class UnsupportedTypeException(PackException):
"Object type not supported for packing."
pass
+
# Unpacking error
class InsufficientDataException(UnpackException):
"Insufficient data to unpack the serialized object."
pass
+
+
class InvalidStringException(UnpackException):
"Invalid UTF-8 string encountered during unpacking."
pass
+
+
class ReservedCodeException(UnpackException):
"Reserved code encountered during unpacking."
pass
+
+
class UnhashableKeyException(UnpackException):
"""
Unhashable key encountered during map unpacking.
The serialized map cannot be deserialized into a Python dictionary.
"""
pass
+
+
class DuplicateKeyException(UnpackException):
"Duplicate key encountered during map unpacking."
pass
+
# Backwards compatibility
KeyNotPrimitiveException = UnhashableKeyException
KeyDuplicateException = DuplicateKeyException
-################################################################################
-### Exported Functions and Globals
-################################################################################
+#############################################################################
+# Exported Functions and Glob
+#############################################################################
# Exported functions and variables, set up in __init()
pack = None
@@ -201,88 +223,100 @@
>>>
"""
-################################################################################
-### Packing
-################################################################################
+##############################################################################
+# Packing
+##############################################################################
# You may notice struct.pack("B", obj) instead of the simpler chr(obj) in the
# code below. This is to allow for seamless Python 2 and 3 compatibility, as
# chr(obj) has a str return type instead of bytes in Python 3, and
# struct.pack(...) has the right return type in both versions.
+
def _pack_integer(obj, fp, options):
if obj < 0:
if obj >= -32:
fp.write(struct.pack("b", obj))
- elif obj >= -2**(8-1):
+ elif obj >= -2**(8 - 1):
fp.write(b"\xd0" + struct.pack("b", obj))
- elif obj >= -2**(16-1):
+ elif obj >= -2**(16 - 1):
fp.write(b"\xd1" + struct.pack(">h", obj))
- elif obj >= -2**(32-1):
+ elif obj >= -2**(32 - 1):
fp.write(b"\xd2" + struct.pack(">i", obj))
- elif obj >= -2**(64-1):
+ elif obj >= -2**(64 - 1):
fp.write(b"\xd3" + struct.pack(">q", obj))
else:
raise UnsupportedTypeException("huge signed int")
else:
if obj <= 127:
fp.write(struct.pack("B", obj))
- elif obj <= 2**8-1:
+ elif obj <= 2**8 - 1:
fp.write(b"\xcc" + struct.pack("B", obj))
- elif obj <= 2**16-1:
+ elif obj <= 2**16 - 1:
fp.write(b"\xcd" + struct.pack(">H", obj))
- elif obj <= 2**32-1:
+ elif obj <= 2**32 - 1:
fp.write(b"\xce" + struct.pack(">I", obj))
- elif obj <= 2**64-1:
+ elif obj <= 2**64 - 1:
fp.write(b"\xcf" + struct.pack(">Q", obj))
else:
raise UnsupportedTypeException("huge unsigned int")
+
def _pack_nil(obj, fp, options):
fp.write(b"\xc0")
+
def _pack_boolean(obj, fp, options):
fp.write(b"\xc3" if obj else b"\xc2")
+
def _pack_float(obj, fp, options):
- if _float_size == 64:
+ float_precision = options.get('force_float_precision', _float_precision)
+
+ if float_precision == "double":
fp.write(b"\xcb" + struct.pack(">d", obj))
- else:
+ elif float_precision == "single":
fp.write(b"\xca" + struct.pack(">f", obj))
+ else:
+ raise ValueError("invalid float precision")
+
def _pack_string(obj, fp, options):
obj = obj.encode('utf-8')
if len(obj) <= 31:
fp.write(struct.pack("B", 0xa0 | len(obj)) + obj)
- elif len(obj) <= 2**8-1:
+ elif len(obj) <= 2**8 - 1:
fp.write(b"\xd9" + struct.pack("B", len(obj)) + obj)
- elif len(obj) <= 2**16-1:
+ elif len(obj) <= 2**16 - 1:
fp.write(b"\xda" + struct.pack(">H", len(obj)) + obj)
- elif len(obj) <= 2**32-1:
+ elif len(obj) <= 2**32 - 1:
fp.write(b"\xdb" + struct.pack(">I", len(obj)) + obj)
else:
raise UnsupportedTypeException("huge string")
+
def _pack_binary(obj, fp, options):
- if len(obj) <= 2**8-1:
+ if len(obj) <= 2**8 - 1:
fp.write(b"\xc4" + struct.pack("B", len(obj)) + obj)
- elif len(obj) <= 2**16-1:
+ elif len(obj) <= 2**16 - 1:
fp.write(b"\xc5" + struct.pack(">H", len(obj)) + obj)
- elif len(obj) <= 2**32-1:
+ elif len(obj) <= 2**32 - 1:
fp.write(b"\xc6" + struct.pack(">I", len(obj)) + obj)
else:
raise UnsupportedTypeException("huge binary string")
+
def _pack_oldspec_raw(obj, fp, options):
if len(obj) <= 31:
fp.write(struct.pack("B", 0xa0 | len(obj)) + obj)
- elif len(obj) <= 2**16-1:
+ elif len(obj) <= 2**16 - 1:
fp.write(b"\xda" + struct.pack(">H", len(obj)) + obj)
- elif len(obj) <= 2**32-1:
+ elif len(obj) <= 2**32 - 1:
fp.write(b"\xdb" + struct.pack(">I", len(obj)) + obj)
else:
raise UnsupportedTypeException("huge raw string")
+
def _pack_ext(obj, fp, options):
if len(obj.data) == 1:
fp.write(b"\xd4" + struct.pack("B", obj.type & 0xff) + obj.data)
@@ -294,21 +328,25 @@
fp.write(b"\xd7" + struct.pack("B", obj.type & 0xff) + obj.data)
elif len(obj.data) == 16:
fp.write(b"\xd8" + struct.pack("B", obj.type & 0xff) + obj.data)
- elif len(obj.data) <= 2**8-1:
- fp.write(b"\xc7" + struct.pack("BB", len(obj.data), obj.type & 0xff) +
obj.data)
- elif len(obj.data) <= 2**16-1:
- fp.write(b"\xc8" + struct.pack(">HB", len(obj.data), obj.type & 0xff)
+ obj.data)
- elif len(obj.data) <= 2**32-1:
- fp.write(b"\xc9" + struct.pack(">IB", len(obj.data), obj.type & 0xff)
+ obj.data)
+ elif len(obj.data) <= 2**8 - 1:
+ fp.write(b"\xc7" +
+ struct.pack("BB", len(obj.data), obj.type & 0xff) + obj.data)
+ elif len(obj.data) <= 2**16 - 1:
+ fp.write(b"\xc8" +
+ struct.pack(">HB", len(obj.data), obj.type & 0xff) + obj.data)
+ elif len(obj.data) <= 2**32 - 1:
+ fp.write(b"\xc9" +
+ struct.pack(">IB", len(obj.data), obj.type & 0xff) + obj.data)
else:
raise UnsupportedTypeException("huge ext data")
+
def _pack_array(obj, fp, options):
if len(obj) <= 15:
fp.write(struct.pack("B", 0x90 | len(obj)))
- elif len(obj) <= 2**16-1:
+ elif len(obj) <= 2**16 - 1:
fp.write(b"\xdc" + struct.pack(">H", len(obj)))
- elif len(obj) <= 2**32-1:
+ elif len(obj) <= 2**32 - 1:
fp.write(b"\xdd" + struct.pack(">I", len(obj)))
else:
raise UnsupportedTypeException("huge array")
@@ -316,22 +354,24 @@
for e in obj:
pack(e, fp, **options)
+
def _pack_map(obj, fp, options):
if len(obj) <= 15:
fp.write(struct.pack("B", 0x80 | len(obj)))
- elif len(obj) <= 2**16-1:
+ elif len(obj) <= 2**16 - 1:
fp.write(b"\xde" + struct.pack(">H", len(obj)))
- elif len(obj) <= 2**32-1:
+ elif len(obj) <= 2**32 - 1:
fp.write(b"\xdf" + struct.pack(">I", len(obj)))
else:
raise UnsupportedTypeException("huge array")
- for k,v in obj.items():
+ for k, v in obj.items():
pack(k, fp, **options)
pack(v, fp, **options)
########################################
+
# Pack for Python 2, with 'unicode' type, 'str' type, and 'long' type
def _pack2(obj, fp, **options):
"""
@@ -345,6 +385,10 @@
ext_handlers (dict): dictionary of Ext handlers, mapping a custom type
to a callable that packs an instance of the type
into an Ext object
+ force_float_precision (str): "single" to force packing floats as
+ IEEE-754 single-precision floats,
+ "double" to force packing floats as
+ IEEE-754 double-precision floats.
Returns:
None.
@@ -392,10 +436,12 @@
if t:
_pack_ext(ext_handlers[t](obj), fp, options)
else:
- raise UnsupportedTypeException("unsupported type: %s" %
str(type(obj)))
+ raise UnsupportedTypeException(
+ "unsupported type: %s" % str(type(obj)))
else:
raise UnsupportedTypeException("unsupported type: %s" % str(type(obj)))
+
# Pack for Python 3, with unicode 'str' type, 'bytes' type, and no 'long' type
def _pack3(obj, fp, **options):
"""
@@ -409,6 +455,10 @@
ext_handlers (dict): dictionary of Ext handlers, mapping a custom type
to a callable that packs an instance of the type
into an Ext object
+ force_float_precision (str): "single" to force packing floats as
+ IEEE-754 single-precision floats,
+ "double" to force packing floats as
+ IEEE-754 double-precision floats.
Returns:
None.
@@ -456,9 +506,12 @@
if t:
_pack_ext(ext_handlers[t](obj), fp, options)
else:
- raise UnsupportedTypeException("unsupported type: %s" %
str(type(obj)))
+ raise UnsupportedTypeException(
+ "unsupported type: %s" % str(type(obj)))
else:
- raise UnsupportedTypeException("unsupported type: %s" % str(type(obj)))
+ raise UnsupportedTypeException(
+ "unsupported type: %s" % str(type(obj)))
+
def _packb2(obj, **options):
"""
@@ -471,6 +524,10 @@
ext_handlers (dict): dictionary of Ext handlers, mapping a custom type
to a callable that packs an instance of the type
into an Ext object
+ force_float_precision (str): "single" to force packing floats as
+ IEEE-754 single-precision floats,
+ "double" to force packing floats as
+ IEEE-754 double-precision floats.
Returns:
A 'str' containing serialized MessagePack bytes.
@@ -488,6 +545,7 @@
_pack2(obj, fp, **options)
return fp.getvalue()
+
def _packb3(obj, **options):
"""
Serialize a Python object into MessagePack bytes.
@@ -499,6 +557,10 @@
ext_handlers (dict): dictionary of Ext handlers, mapping a custom type
to a callable that packs an instance of the type
into an Ext object
+ force_float_precision (str): "single" to force packing floats as
+ IEEE-754 single-precision floats,
+ "double" to force packing floats as
+ IEEE-754 double-precision floats.
Returns:
A 'bytes' containing serialized MessagePack bytes.
@@ -516,9 +578,10 @@
_pack3(obj, fp, **options)
return fp.getvalue()
-################################################################################
-### Unpacking
-################################################################################
+#############################################################################
+# Unpacking
+#############################################################################
+
def _read_except(fp, n):
data = fp.read(n)
@@ -526,6 +589,7 @@
raise InsufficientDataException()
return data
+
def _unpack_integer(code, fp, options):
if (ord(code) & 0xe0) == 0xe0:
return struct.unpack("b", code)[0]
@@ -549,16 +613,21 @@
return struct.unpack(">Q", _read_except(fp, 8))[0]
raise Exception("logic error, not int: 0x%02x" % ord(code))
+
def _unpack_reserved(code, fp, options):
if code == b'\xc1':
- raise ReservedCodeException("encountered reserved code: 0x%02x" %
ord(code))
- raise Exception("logic error, not reserved code: 0x%02x" % ord(code))
+ raise ReservedCodeException(
+ "encountered reserved code: 0x%02x" % ord(code))
+ raise Exception(
+ "logic error, not reserved code: 0x%02x" % ord(code))
+
def _unpack_nil(code, fp, options):
if code == b'\xc0':
return None
raise Exception("logic error, not nil: 0x%02x" % ord(code))
+
def _unpack_boolean(code, fp, options):
if code == b'\xc2':
return False
@@ -566,6 +635,7 @@
return True
raise Exception("logic error, not boolean: 0x%02x" % ord(code))
+
def _unpack_float(code, fp, options):
if code == b'\xca':
return struct.unpack(">f", _read_except(fp, 4))[0]
@@ -573,6 +643,7 @@
return struct.unpack(">d", _read_except(fp, 8))[0]
raise Exception("logic error, not float: 0x%02x" % ord(code))
+
def _unpack_string(code, fp, options):
if (ord(code) & 0xe0) == 0xa0:
length = ord(code) & ~0xe0
@@ -598,6 +669,7 @@
return InvalidString(data)
raise InvalidStringException("unpacked string is invalid utf-8")
+
def _unpack_binary(code, fp, options):
if code == b'\xc4':
length = struct.unpack("B", _read_except(fp, 1))[0]
@@ -610,6 +682,7 @@
return _read_except(fp, length)
+
def _unpack_ext(code, fp, options):
if code == b'\xd4':
length = 1
@@ -639,6 +712,7 @@
return ext
+
def _unpack_array(code, fp, options):
if (ord(code) & 0xf0) == 0x90:
length = (ord(code) & ~0xf0)
@@ -651,11 +725,13 @@
return [_unpack(fp, options) for i in xrange(length)]
+
def _deep_list_to_tuple(obj):
if isinstance(obj, list):
return tuple([_deep_list_to_tuple(e) for e in obj])
return obj
+
def _unpack_map(code, fp, options):
if (ord(code) & 0xf0) == 0x80:
length = (ord(code) & ~0xf0)
@@ -666,7 +742,8 @@
else:
raise Exception("logic error, not map: 0x%02x" % ord(code))
- d = {} if not options.get('use_ordered_dict') else
collections.OrderedDict()
+ d = {} if not options.get('use_ordered_dict') \
+ else collections.OrderedDict()
for _ in xrange(length):
# Unpack key
k = _unpack(fp, options)
@@ -675,9 +752,11 @@
# Attempt to convert list into a hashable tuple
k = _deep_list_to_tuple(k)
elif not isinstance(k, collections.Hashable):
- raise UnhashableKeyException("encountered unhashable key: %s, %s"
% (str(k), str(type(k))))
+ raise UnhashableKeyException(
+ "encountered unhashable key: %s, %s" % (str(k), str(type(k))))
elif k in d:
- raise DuplicateKeyException("encountered duplicate key: %s, %s" %
(str(k), str(type(k))))
+ raise DuplicateKeyException(
+ "encountered duplicate key: %s, %s" % (str(k), str(type(k))))
# Unpack value
v = _unpack(fp, options)
@@ -685,15 +764,18 @@
try:
d[k] = v
except TypeError:
- raise UnhashableKeyException("encountered unhashable key: %s" %
str(k))
+ raise UnhashableKeyException(
+ "encountered unhashable key: %s" % str(k))
return d
+
def _unpack(fp, options):
code = _read_except(fp, 1)
return _unpack_dispatch_table[code](code, fp, options)
########################################
+
def _unpack2(fp, **options):
"""
Deserialize MessagePack bytes into a Python object.
@@ -735,6 +817,7 @@
"""
return _unpack(fp, options)
+
def _unpack3(fp, **options):
"""
Deserialize MessagePack bytes into a Python object.
@@ -776,6 +859,7 @@
"""
return _unpack(fp, options)
+
# For Python 2, expects a str object
def _unpackb2(s, **options):
"""
@@ -821,6 +905,7 @@
raise TypeError("packed data must be type 'str' or 'bytearray'")
return _unpack(io.BytesIO(s), options)
+
# For Python 3, expects a bytes object
def _unpackb3(s, **options):
"""
@@ -866,9 +951,10 @@
raise TypeError("packed data must be type 'bytes' or 'bytearray'")
return _unpack(io.BytesIO(s), options)
-################################################################################
-### Module Initialization
-################################################################################
+#############################################################################
+# Module Initialization
+#############################################################################
+
def __init():
global pack
@@ -880,7 +966,7 @@
global load
global loads
global compatibility
- global _float_size
+ global _float_precision
global _unpack_dispatch_table
global xrange
@@ -889,9 +975,9 @@
# Auto-detect system float precision
if sys.float_info.mant_dig == 53:
- _float_size = 64
+ _float_precision = "double"
else:
- _float_size = 32
+ _float_precision = "single"
# Map packb and unpackb to the appropriate version
if sys.version_info[0] == 3:
@@ -918,16 +1004,16 @@
_unpack_dispatch_table = {}
# Fix uint
- for code in range(0, 0x7f+1):
+ for code in range(0, 0x7f + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_integer
# Fix map
- for code in range(0x80, 0x8f+1):
+ for code in range(0x80, 0x8f + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_map
# Fix array
- for code in range(0x90, 0x9f+1):
+ for code in range(0x90, 0x9f + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_array
# Fix str
- for code in range(0xa0, 0xbf+1):
+ for code in range(0xa0, 0xbf + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_string
# Nil
_unpack_dispatch_table[b'\xc0'] = _unpack_nil
@@ -937,25 +1023,25 @@
_unpack_dispatch_table[b'\xc2'] = _unpack_boolean
_unpack_dispatch_table[b'\xc3'] = _unpack_boolean
# Bin
- for code in range(0xc4, 0xc6+1):
+ for code in range(0xc4, 0xc6 + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_binary
# Ext
- for code in range(0xc7, 0xc9+1):
+ for code in range(0xc7, 0xc9 + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_ext
# Float
_unpack_dispatch_table[b'\xca'] = _unpack_float
_unpack_dispatch_table[b'\xcb'] = _unpack_float
# Uint
- for code in range(0xcc, 0xcf+1):
+ for code in range(0xcc, 0xcf + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_integer
# Int
- for code in range(0xd0, 0xd3+1):
+ for code in range(0xd0, 0xd3 + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_integer
# Fixext
- for code in range(0xd4, 0xd8+1):
+ for code in range(0xd4, 0xd8 + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_ext
# String
- for code in range(0xd9, 0xdb+1):
+ for code in range(0xd9, 0xdb + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_string
# Array
_unpack_dispatch_table[b'\xdc'] = _unpack_array
@@ -964,7 +1050,8 @@
_unpack_dispatch_table[b'\xde'] = _unpack_map
_unpack_dispatch_table[b'\xdf'] = _unpack_map
# Negative fixint
- for code in range(0xe0, 0xff+1):
+ for code in range(0xe0, 0xff + 1):
_unpack_dispatch_table[struct.pack("B", code)] = _unpack_integer
+
__init()