Skip to content

Commit ae3a6ba

Browse files
authored
Deprecate implementation module's unpack() (#290)
1 parent f38c1a3 commit ae3a6ba

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

msgpack/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def __new__(cls, code, data):
1919

2020
import os
2121
if os.environ.get('MSGPACK_PUREPYTHON'):
22-
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
22+
from msgpack.fallback import Packer, unpackb, Unpacker
2323
else:
2424
try:
2525
from msgpack._packer import Packer
26-
from msgpack._unpacker import unpack, unpackb, Unpacker
26+
from msgpack._unpacker import unpackb, Unpacker
2727
except ImportError:
28-
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
28+
from msgpack.fallback import Packer, unpackb, Unpacker
2929

3030

3131
def pack(o, stream, **kwargs):
@@ -46,6 +46,18 @@ def packb(o, **kwargs):
4646
"""
4747
return Packer(**kwargs).pack(o)
4848

49+
50+
def unpack(stream, **kwargs):
51+
"""
52+
Unpack an object from `stream`.
53+
54+
Raises `ExtraData` when `stream` contains extra bytes.
55+
See :class:`Unpacker` for options.
56+
"""
57+
data = stream.read()
58+
return unpackb(data, **kwargs)
59+
60+
4961
# alias for compatibility to simplejson/marshal/pickle.
5062
load = unpack
5163
loads = unpackb

msgpack/_unpacker.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,9 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
212212

213213

214214
def unpack(object stream, **kwargs):
215-
"""
216-
Unpack an object from `stream`.
217-
218-
Raises `ValueError` when `stream` has extra bytes.
219-
See :class:`Unpacker` for options.
220-
"""
215+
PyErr_WarnEx(
216+
PendingDeprecationWarning,
217+
"Direct calling implementation's unpack() is deprecated, Use msgpack.unpack() or unpackb() instead.", 1)
221218
data = stream.read()
222219
return unpackb(data, **kwargs)
223220

msgpack/fallback.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,9 @@ def _get_data_from_buffer(obj):
101101

102102

103103
def unpack(stream, **kwargs):
104-
"""
105-
Unpack an object from `stream`.
106-
107-
Raises `ExtraData` when `packed` contains extra bytes.
108-
See :class:`Unpacker` for options.
109-
"""
104+
warnings.warn(
105+
"Direct calling implementation's unpack() is deprecated, Use msgpack.unpack() or unpackb() instead.",
106+
PendingDeprecationWarning)
110107
data = stream.read()
111108
return unpackb(data, **kwargs)
112109

@@ -224,11 +221,7 @@ def __init__(self, file_like=None, read_size=0, use_list=True, raw=True,
224221
"encoding is deprecated, Use raw=False instead.",
225222
PendingDeprecationWarning)
226223

227-
if unicode_errors is not None:
228-
warnings.warn(
229-
"unicode_errors is deprecated.",
230-
PendingDeprecationWarning)
231-
else:
224+
if unicode_errors is None:
232225
unicode_errors = 'strict'
233226

234227
if file_like is None:
@@ -713,7 +706,7 @@ class Packer(object):
713706
(deprecated) Convert unicode to bytes with this encoding. (default: 'utf-8')
714707
715708
:param str unicode_errors:
716-
(deprecated) Error handler for encoding unicode. (default: 'strict')
709+
Error handler for encoding unicode. (default: 'strict')
717710
"""
718711
def __init__(self, default=None, encoding=None, unicode_errors=None,
719712
use_single_float=False, autoreset=True, use_bin_type=False,
@@ -727,10 +720,6 @@ def __init__(self, default=None, encoding=None, unicode_errors=None,
727720

728721
if unicode_errors is None:
729722
unicode_errors = 'strict'
730-
else:
731-
warnings.warn(
732-
"unicode_errors is deprecated.",
733-
PendingDeprecationWarning)
734723

735724
self._strict_types = strict_types
736725
self._use_float = use_single_float

0 commit comments

Comments
 (0)