8000 fallback: Remove old buffer protocol support by methane · Pull Request #384 · msgpack/msgpack-python · GitHub
[go: up one dir, main page]

Skip to content

fallback: Remove old buffer protocol support #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2019
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
16 changes: 1 addition & 15 deletions msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,7 @@ def _check_type_strict(obj, t, type=type, tuple=tuple):


def _get_data_from_buffer(obj):
try:
view = memoryview(obj)
except TypeError:
# try to use legacy buffer protocol if 2.7, otherwise re-raise
if PY2:
view = memoryview(buffer(obj))
warnings.warn(
"using old buffer interface to unpack %s; "
"this leads to unpacking errors if slicing is used and "
"will be removed in a future version" % type(obj),
RuntimeWarning,
stacklevel=3,
)
else:
raise
view = memoryview(obj)
if view.itemsize != 1:
raise ValueError("cannot unpack from multi-byte object")
return view
Expand Down
8 changes: 4 additions & 4 deletions test/test_buffer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env python
# coding: utf-8

import sys
import pytest
from msgpack import packb, unpackb


@pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 is not supported")
def test_unpack_buffer():
from array import array

buf = array("b")
try:
buf.frombytes(packb((b"foo", b"bar")))
except AttributeError: # PY2
buf.fromstring(packb((b"foo", b"bar")))
buf.frombytes(packb((b"foo", b"bar")))
obj = unpackb(buf, use_list=1)
assert [b"foo", b"bar"] == obj

Expand Down
0