Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions msgpack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def __new__(cls, 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):
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions msgpack/_unpacker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 5 additions & 16 deletions msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -224,11 +221,7 @@ def __init__(self, file_like=None, read_size=0, use_list=True, raw=True,
"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:
Expand Down Expand Up @@ -708,7 +701,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,
Expand All @@ -722,10 +715,6 @@ def __init__(self, default=None, encoding=None, unicode_errors=None,

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
Expand Down