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