u-msgpack-python 2.7.2__tar.gz → 2.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2022 vsergeev / Ivan (Vanya) A. Sergeev
1
+ Copyright (c) 2013-2026 vsergeev / Ivan (Vanya) A. Sergeev
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: u-msgpack-python
3
- Version: 2.7.2
3
+ Version: 2.9.0
4
4
  Summary: A portable, lightweight MessagePack serializer and deserializer written in pure Python.
5
5
  Home-page: https://github.com/vsergeev/u-msgpack-python
6
6
  Author: vsergeev
@@ -15,6 +15,17 @@ Classifier: Programming Language :: Python :: 2
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: Implementation :: CPython
17
17
  Classifier: Programming Language :: Python :: Implementation :: PyPy
18
+ Description-Content-Type: text/x-rst
18
19
  License-File: LICENSE
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: keywords
27
+ Dynamic: license
28
+ Dynamic: license-file
29
+ Dynamic: summary
19
30
 
20
- u-msgpack-python is a lightweight `MessagePack <http://msgpack.org/>`_ serializer and deserializer module written in pure Python, compatible with both Python 2 and Python 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest `MessagePack specification <https://github.com/msgpack/msgpack/blob/master/spec.md>`_. In particular, it supports the new binary, UTF-8 string, and application-defined ext types. See https://github.com/vsergeev/u-msgpack-python for more information.
31
+ u-msgpack-python is a lightweight `MessagePack <http://msgpack.org/>`_ serializer and deserializer module written in pure Python, compatible with both Python 2 and Python 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest `MessagePack specification <https://github.com/msgpack/msgpack/blob/master/spec.md>`_. In particular, it supports the new binary, UTF-8 string, application-defined ext, and timestamp types. See https://github.com/vsergeev/u-msgpack-python for more information.
@@ -0,0 +1,163 @@
1
+ # u-msgpack-python [![Tests Status](https://github.com/vsergeev/u-msgpack-python/actions/workflows/tests.yml/badge.svg)](https://github.com/vsergeev/u-msgpack-python/actions/workflows/tests.yml) [![Docs Status](https://app.readthedocs.org/projects/u-msgpack-python/badge/)](https://u-msgpack-python.readthedocs.io/en/latest/) [![GitHub release](https://img.shields.io/github/release/vsergeev/u-msgpack-python.svg?maxAge=7200)](https://github.com/vsergeev/u-msgpack-python) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vsergeev/u-msgpack-python/blob/master/LICENSE)
2
+
3
+ u-msgpack-python is a lightweight [MessagePack](http://msgpack.org/) serializer and deserializer module written in pure Python, compatible with Python 2 and 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest [MessagePack specification](https://github.com/msgpack/msgpack/blob/master/spec.md). In particular, it supports the new binary, UTF-8 string, application-defined ext, and timestamp types.
4
+
5
+ u-msgpack-python is currently distributed as a package on [PyPI](https://pypi.python.org/pypi/u-msgpack-python) and as a single file module.
6
+
7
+ ## Installation
8
+
9
+ With pip:
10
+ ``` text
11
+ $ pip install u-msgpack-python
12
+ ```
13
+
14
+ or simply drop `umsgpack.py` into your project!
15
+ ``` text
16
+ $ wget https://raw.github.com/vsergeev/u-msgpack-python/master/umsgpack/__init__.py -O umsgpack.py
17
+ ```
18
+
19
+ ## Examples
20
+
21
+ Basic Example:
22
+ ``` python
23
+ >>> import umsgpack
24
+ >>> umsgpack.packb({u"compact": True, u"schema": 0})
25
+ b'\x82\xa7compact\xc3\xa6schema\x00'
26
+ >>> umsgpack.unpackb(_)
27
+ {u'compact': True, u'schema': 0}
28
+ >>>
29
+ ```
30
+
31
+ A more complicated example:
32
+ ``` python
33
+ >>> umsgpack.packb([1, True, False, 0xffffffff, {u"foo": b"\x80\x01\x02", \
34
+ ... u"bar": [1,2,3, {u"a": [1,2,3,{}]}]}, -1, 2.12345])
35
+ b'\x97\x01\xc3\xc2\xce\xff\xff\xff\xff\x82\xa3foo\xc4\x03\x80\x01\
36
+ \x02\xa3bar\x94\x01\x02\x03\x81\xa1a\x94\x01\x02\x03\x80\xff\xcb\
37
+ @\x00\xfc\xd3Z\x85\x87\x94'
38
+ >>> umsgpack.unpackb(_)
39
+ [1, True, False, 4294967295, {u'foo': b'\x80\x01\x02', \
40
+ u'bar': [1, 2, 3, {u'a': [1, 2, 3, {}]}]}, -1, 2.12345]
41
+ >>>
42
+ ```
43
+
44
+ Streaming serialization with file-like objects:
45
+ ``` python
46
+ >>> f = open('test.bin', 'wb')
47
+ >>> umsgpack.pack({u"compact": True, u"schema": 0}, f)
48
+ >>> umsgpack.pack([1,2,3], f)
49
+ >>> f.close()
50
+ >>>
51
+ >>> f = open('test.bin', 'rb')
52
+ >>> umsgpack.unpack(f)
53
+ {u'compact': True, u'schema': 0}
54
+ >>> umsgpack.unpack(f)
55
+ [1, 2, 3]
56
+ >>> f.close()
57
+ >>>
58
+ ```
59
+
60
+ Serializing and deserializing a raw Ext type:
61
+ ``` python
62
+ >>> # Create an Ext object with type 5 and data b"\x01\x02\x03"
63
+ ... foo = umsgpack.Ext(5, b"\x01\x02\x03")
64
+ >>> umsgpack.packb({u"stuff": foo, u"awesome": True})
65
+ b'\x82\xa5stuff\xc7\x03\x05\x01\x02\x03\xa7awesome\xc3'
66
+ >>>
67
+ >>> bar = umsgpack.unpackb(_)
68
+ >>> print(bar['stuff'])
69
+ Ext Object (Type: 5, Data: 0x01 0x02 0x03)
70
+ >>> bar['stuff'].type
71
+ 5
72
+ >>> bar['stuff'].data
73
+ b'\x01\x02\x03'
74
+ >>>
75
+ ```
76
+
77
+ Serializing and deserializing application-defined types with `ext_serializable()`:
78
+ ``` python
79
+ >>> @umsgpack.ext_serializable(0x50)
80
+ ... class Point(collections.namedtuple('Point', ['x', 'y'])):
81
+ ... def packb(self):
82
+ ... return struct.pack(">ii", self.x, self.y)
83
+ ... @staticmethod
84
+ ... def unpackb(data):
85
+ ... return Point(*struct.unpack(">ii", data))
86
+ ...
87
+ >>> umsgpack.packb(Point(1, 2))
88
+ b'\xd7P\x00\x00\x00\x01\x00\x00\x00\x02'
89
+ >>> umsgpack.unpackb(_)
90
+ Point(x=1, y=2)
91
+ >>>
92
+ ```
93
+
94
+ Serializing and deserializing application-defined types with Ext handlers:
95
+ ``` python
96
+ >>> umsgpack.packb([complex(1,2), decimal.Decimal("0.31")],
97
+ ... ext_handlers = {
98
+ ... complex: lambda obj: umsgpack.Ext(0x30, struct.pack("ff", obj.real, obj.imag)),
99
+ ... decimal.Decimal: lambda obj: umsgpack.Ext(0x40, str(obj).encode()),
100
+ ... })
101
+ b'\x92\xd70\x00\x00\x80?\x00\x00\x00@\xd6@0.31'
102
+ >>> umsgpack.unpackb(_,
103
+ ... ext_handlers = {
104
+ ... 0x30: lambda ext: complex(*struct.unpack("ff", ext.data)),
105
+ ... 0x40: lambda ext: decimal.Decimal(ext.data.decode()),
106
+ ... })
107
+ [(1+2j), Decimal('0.31')]
108
+ >>>
109
+ ```
110
+
111
+ Python standard library style names `dump`, `dumps`, `load`, `loads` are also available:
112
+ ``` python
113
+ >>> umsgpack.dumps({u"compact": True, u"schema": 0})
114
+ b'\x82\xa7compact\xc3\xa6schema\x00'
115
+ >>> umsgpack.loads(_)
116
+ {u'compact': True, u'schema': 0}
117
+ >>>
118
+ >>> f = open('test.bin', 'wb')
119
+ >>> umsgpack.dump({u"compact": True, u"schema": 0}, f)
120
+ >>> f.close()
121
+ >>>
122
+ >>> f = open('test.bin', 'rb')
123
+ >>> umsgpack.load(f)
124
+ {u'compact': True, u'schema': 0}
125
+ >>>
126
+ ```
127
+
128
+ ## Documentation
129
+
130
+ Documentation is hosted at [https://u-msgpack-python.readthedocs.io](https://u-msgpack-python.readthedocs.io).
131
+
132
+ To build documentation locally with Sphinx, run:
133
+
134
+ ```
135
+ cd docs
136
+ make html
137
+ ```
138
+
139
+ Sphinx will produce the HTML documentation in `docs/_build/html/`.
140
+
141
+ Run `make help` to see other output targets (LaTeX, man, text, etc.).
142
+
143
+ ## Testing
144
+
145
+ The included unit tests may be run with `test_umsgpack.py`, under your favorite interpreter.
146
+
147
+ ``` text
148
+ $ python2 test_umsgpack.py
149
+ $ python3 test_umsgpack.py
150
+ $ pypy test_umsgpack.py
151
+ $ pypy3 test_umsgpack.py
152
+ ```
153
+
154
+ Alternatively, you can use `tox` or `detox` to test multiple Python versions at once.
155
+
156
+ ``` text
157
+ $ pip install tox
158
+ $ tox
159
+ ```
160
+
161
+ ## License
162
+
163
+ u-msgpack-python is MIT licensed. See the included `LICENSE` file for more details.
@@ -1,6 +1,3 @@
1
- [metadata]
2
- description_file = README.md
3
-
4
1
  [bdist_wheel]
5
2
  universal = True
6
3
 
@@ -5,13 +5,15 @@ except ImportError:
5
5
 
6
6
  setup(
7
7
  name='u-msgpack-python',
8
- version='2.7.2',
8
+ version='2.9.0',
9
9
  description='A portable, lightweight MessagePack serializer and deserializer written in pure Python.',
10
10
  author='vsergeev',
11
11
  author_email='v@sergeev.io',
12
12
  url='https://github.com/vsergeev/u-msgpack-python',
13
- py_modules=['umsgpack'],
14
- long_description="""u-msgpack-python is a lightweight `MessagePack <http://msgpack.org/>`_ serializer and deserializer module written in pure Python, compatible with both Python 2 and Python 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest `MessagePack specification <https://github.com/msgpack/msgpack/blob/master/spec.md>`_. In particular, it supports the new binary, UTF-8 string, and application-defined ext types. See https://github.com/vsergeev/u-msgpack-python for more information.""",
13
+ packages=['umsgpack'],
14
+ package_data={'umsgpack': ['*.pyi', 'py.typed']},
15
+ long_description="""u-msgpack-python is a lightweight `MessagePack <http://msgpack.org/>`_ serializer and deserializer module written in pure Python, compatible with both Python 2 and Python 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest `MessagePack specification <https://github.com/msgpack/msgpack/blob/master/spec.md>`_. In particular, it supports the new binary, UTF-8 string, application-defined ext, and timestamp types. See https://github.com/vsergeev/u-msgpack-python for more information.""",
16
+ long_description_content_type='text/x-rst',
15
17
  classifiers=[
16
18
  "Development Status :: 5 - Production/Stable",
17
19
  "License :: OSI Approved :: MIT License",
@@ -381,6 +381,7 @@ exported_vars_test_vector = [
381
381
  "ReservedCodeException",
382
382
  "UnhashableKeyException",
383
383
  "DuplicateKeyException",
384
+ "MaximumDepthException",
384
385
  "KeyNotPrimitiveException",
385
386
  "KeyDuplicateException",
386
387
  "ext_serializable",
@@ -438,9 +439,9 @@ class TestUmsgpack(unittest.TestCase):
438
439
  # one we end up with depends on the architecture (32-bit/64-bit)
439
440
  if sys.version_info[0] == 2:
440
441
  # Allow both {int,long} -> unpackb -> {int,long}
441
- if isinstance(obj, int) or isinstance(obj, long):
442
+ if isinstance(obj, int) or isinstance(obj, long): # noqa: F821
442
443
  self.assertTrue(isinstance(unpacked, int) or
443
- isinstance(unpacked, long))
444
+ isinstance(unpacked, long)) # noqa: F821
444
445
  else:
445
446
  self.assertTrue(isinstance(unpacked, type(obj)))
446
447
  # In Python3, we only have the int integer type
@@ -490,7 +491,7 @@ class TestUmsgpack(unittest.TestCase):
490
491
  # so convert any string obj to bytes before comparison
491
492
  if sys.version_info[0] == 3 and isinstance(obj, str):
492
493
  _obj = obj.encode('utf-8')
493
- elif sys.version_info[0] == 2 and isinstance(obj, unicode):
494
+ elif sys.version_info[0] == 2 and isinstance(obj, unicode): # noqa: F821
494
495
  _obj = bytes(obj)
495
496
  else:
496
497
  _obj = obj
@@ -712,11 +713,6 @@ class TestUmsgpack(unittest.TestCase):
712
713
  with self.assertRaises(NotImplementedError):
713
714
  umsgpack.unpackb(b"\xd4\x21\x00")
714
715
 
715
- # Unregister Ext serializable classes to prevent interference with
716
- # subsequent tests
717
- umsgpack._ext_classes_to_code = {}
718
- umsgpack._ext_code_to_classes = {}
719
-
720
716
  def test_ext_serializable_subclass(self):
721
717
  @umsgpack.ext_serializable(0x10)
722
718
  class Rectangle:
@@ -746,17 +742,12 @@ class TestUmsgpack(unittest.TestCase):
746
742
  unpacked = umsgpack.unpackb(packed)
747
743
  self.assertEqual(unpacked, Rectangle(5, 5))
748
744
 
749
- # Unregister Ext serializable classes to prevent interference with
750
- # subsequent tests
751
- umsgpack._ext_classes_to_code = {}
752
- umsgpack._ext_code_to_classes = {}
753
-
754
745
  def test_streaming_writer(self):
755
746
  # Try first composite test vector
756
747
  (_, obj, data) = composite_test_vectors[0]
757
748
  writer = io.BytesIO()
758
749
  umsgpack.pack(obj, writer)
759
- self.assertTrue(writer.getvalue(), data)
750
+ self.assertEqual(writer.getvalue(), data)
760
751
 
761
752
  def test_streaming_reader(self):
762
753
  # Try first composite test vector
@@ -764,12 +755,34 @@ class TestUmsgpack(unittest.TestCase):
764
755
  reader = io.BytesIO(data)
765
756
  self.assertEqual(umsgpack.unpack(reader), obj)
766
757
 
758
+ def test_max_depth_default_wraps_recursion(self):
759
+ # Default (no max_depth): deeply nested input must raise a
760
+ # MaximumDepthException (an UnpackException), not a bare RecursionError.
761
+ payload = b"\x91" * 5000 + b"\xc0"
762
+ self.assertRaises(umsgpack.MaximumDepthException, umsgpack.unpackb, payload)
763
+ self.assertRaises(umsgpack.UnpackException, umsgpack.unpackb, payload)
764
+ # Moderate nesting still works.
765
+ self.assertEqual(umsgpack.unpackb(b"\x91" * 100 + b"\xc0"),
766
+ umsgpack.unpackb(b"\x91" * 100 + b"\xc0"))
767
+
768
+ def test_max_depth_cap_arrays_and_maps(self):
769
+ self.assertTrue(
770
+ umsgpack.unpackb(b"\x91" * 32 + b"\xc0", max_depth=32) is not None)
771
+ self.assertRaises(umsgpack.MaximumDepthException,
772
+ umsgpack.unpackb, b"\x91" * 33 + b"\xc0", max_depth=32)
773
+ self.assertRaises(umsgpack.MaximumDepthException,
774
+ umsgpack.unpackb, b"\x81\xa1k" * 17 + b"\xc0", max_depth=16)
775
+ # Siblings are not counted, only nesting depth.
776
+ self.assertEqual(
777
+ len(umsgpack.unpackb(b"\xdc\x00\xc8" + b"\xc0" * 200, max_depth=1)), 200)
778
+
767
779
  def test_namespacing(self):
768
780
  # Get a list of global variables from umsgpack module
769
781
  exported_vars = list([x for x in dir(umsgpack) if not x.startswith("_")])
770
782
  # Ignore imports
771
- exported_vars = list([x for x in exported_vars if x != "struct" and x != "collections" and x != "datetime" and x !=
772
- "sys" and x != "io" and x != "xrange" and x != "Hashable"])
783
+ ignore_vars = ["struct", "collections", "datetime", "sys", "io",
784
+ "xrange", "Hashable", "functools"]
785
+ exported_vars = [x for x in exported_vars if x not in ignore_vars]
773
786
 
774
787
  self.assertTrue(len(exported_vars) == len(exported_vars_test_vector))
775
788
  for var in exported_vars_test_vector:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: u-msgpack-python
3
- Version: 2.7.2
3
+ Version: 2.9.0
4
4
  Summary: A portable, lightweight MessagePack serializer and deserializer written in pure Python.
5
5
  Home-page: https://github.com/vsergeev/u-msgpack-python
6
6
  Author: vsergeev
@@ -15,6 +15,17 @@ Classifier: Programming Language :: Python :: 2
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: Implementation :: CPython
17
17
  Classifier: Programming Language :: Python :: Implementation :: PyPy
18
+ Description-Content-Type: text/x-rst
18
19
  License-File: LICENSE
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: keywords
27
+ Dynamic: license
28
+ Dynamic: license-file
29
+ Dynamic: summary
19
30
 
20
- u-msgpack-python is a lightweight `MessagePack <http://msgpack.org/>`_ serializer and deserializer module written in pure Python, compatible with both Python 2 and Python 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest `MessagePack specification <https://github.com/msgpack/msgpack/blob/master/spec.md>`_. In particular, it supports the new binary, UTF-8 string, and application-defined ext types. See https://github.com/vsergeev/u-msgpack-python for more information.
31
+ u-msgpack-python is a lightweight `MessagePack <http://msgpack.org/>`_ serializer and deserializer module written in pure Python, compatible with both Python 2 and Python 3, as well as CPython and PyPy implementations of Python. u-msgpack-python is fully compliant with the latest `MessagePack specification <https://github.com/msgpack/msgpack/blob/master/spec.md>`_. In particular, it supports the new binary, UTF-8 string, application-defined ext, and timestamp types. See https://github.com/vsergeev/u-msgpack-python for more information.
@@ -4,8 +4,10 @@ README.md
4
4
  setup.cfg
5
5
  setup.py
6
6
  test_umsgpack.py
7
- umsgpack.py
8
7
  u_msgpack_python.egg-info/PKG-INFO
9
8
  u_msgpack_python.egg-info/SOURCES.txt
10
9
  u_msgpack_python.egg-info/dependency_links.txt
11
- u_msgpack_python.egg-info/top_level.txt
10
+ u_msgpack_python.egg-info/top_level.txt
11
+ umsgpack/__init__.py
12
+ umsgpack/__init__.pyi
13
+ umsgpack/py.typed