mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
Deprecate implementation module's unpack() (#290)
This commit is contained in:
parent
f38c1a3674
commit
ae3a6ba0b0
3 changed files with 23 additions and 25 deletions
|
@ -19,13 +19,13 @@ class ExtType(namedtuple('ExtType', 'code data')):
|
|||
|
||||
import os
|
||||
if os.environ.get('MSGPACK_PUREPYTHON'):
|
||||
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
|
||||
from msgpack.fallback import Packer, unpackb, Unpacker
|
||||
else:
|
||||
try:
|
||||
from msgpack._packer import Packer
|
||||
from msgpack._unpacker import unpack, unpackb, Unpacker
|
||||
from msgpack._unpacker import unpackb, Unpacker
|
||||
except ImportError:
|
||||
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
|
||||
from msgpack.fallback import Packer, unpackb, Unpacker
|
||||
|
||||
|
||||
def pack(o, stream, **kwargs):
|
||||
|
@ -46,6 +46,18 @@ def packb(o, **kwargs):
|
|||
"""
|
||||
return Packer(**kwargs).pack(o)
|
||||
|
||||
|
||||
def unpack(stream, **kwargs):
|
||||
"""
|
||||
Unpack an object from `stream`.
|
||||
|
||||
Raises `ExtraData` when `stream` contains extra bytes.
|
||||
See :class:`Unpacker` for options.
|
||||
"""
|
||||
data = stream.read()
|
||||
return unpackb(data, **kwargs)
|
||||
|
||||
|
||||
# alias for compatibility to simplejson/marshal/pickle.
|
||||
load = unpack
|
||||
loads = unpackb
|
||||
|
|
|
@ -212,12 +212,9 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
|
|||
|
||||
|
||||
def unpack(object stream, **kwargs):
|
||||
"""
|
||||
Unpack an object from `stream`.
|
||||
|
||||
Raises `ValueError` when `stream` has extra bytes.
|
||||
See :class:`Unpacker` for options.
|
||||
"""
|
||||
PyErr_WarnEx(
|
||||
PendingDeprecationWarning,
|
||||
"Direct calling implementation's unpack() is deprecated, Use msgpack.unpack() or unpackb() instead.", 1)
|
||||
data = stream.read()
|
||||
return unpackb(data, **kwargs)
|
||||
|
||||
|
|
|
@ -101,12 +101,9 @@ def _get_data_from_buffer(obj):
|
|||
|
||||
|
||||
def unpack(stream, **kwargs):
|
||||
"""
|
||||
Unpack an object from `stream`.
|
||||
|
||||
Raises `ExtraData` when `packed` contains extra bytes.
|
||||
See :class:`Unpacker` for options.
|
||||
"""
|
||||
warnings.warn(
|
||||
"Direct calling implementation's unpack() is deprecated, Use msgpack.unpack() or unpackb() instead.",
|
||||
PendingDeprecationWarning)
|
||||
data = stream.read()
|
||||
return unpackb(data, **kwargs)
|
||||
|
||||
|
@ -224,11 +221,7 @@ class Unpacker(object):
|
|||
"encoding is deprecated, Use raw=False instead.",
|
||||
PendingDeprecationWarning)
|
||||
|
||||
if unicode_errors is not None:
|
||||
warnings.warn(
|
||||
"unicode_errors is deprecated.",
|
||||
PendingDeprecationWarning)
|
||||
else:
|
||||
if unicode_errors is None:
|
||||
unicode_errors = 'strict'
|
||||
|
||||
if file_like is None:
|
||||
|
@ -713,7 +706,7 @@ class Packer(object):
|
|||
(deprecated) Convert unicode to bytes with this encoding. (default: 'utf-8')
|
||||
|
||||
:param str unicode_errors:
|
||||
(deprecated) Error handler for encoding unicode. (default: 'strict')
|
||||
Error handler for encoding unicode. (default: 'strict')
|
||||
"""
|
||||
def __init__(self, default=None, encoding=None, unicode_errors=None,
|
||||
use_single_float=False, autoreset=True, use_bin_type=False,
|
||||
|
@ -727,10 +720,6 @@ class Packer(object):
|
|||
|
||||
if unicode_errors is None:
|
||||
unicode_errors = 'strict'
|
||||
else:
|
||||
warnings.warn(
|
||||
"unicode_errors is deprecated.",
|
||||
PendingDeprecationWarning)
|
||||
|
||||
self._strict_types = strict_types
|
||||
self._use_float = use_single_float
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue