summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2018-11-12 02:33:31 +0900
committerGitHub <noreply@github.com>2018-11-12 02:33:31 +0900
commit39f8aa78c7bc6b6b18a1c814a0c296f55242f028 (patch)
treef20a20e929bb233fdc15e53d46ad06d9997fe251
parent07f0beeabb71828377f481ff83746997b3babf23 (diff)
downloadmsgpack-python-39f8aa78c7bc6b6b18a1c814a0c296f55242f028.tar.gz
Remove deprecated write_bytes option (#322)
-rw-r--r--msgpack/_unpacker.pyx35
-rw-r--r--msgpack/fallback.py20
-rw-r--r--test/test_unpack_raw.py29
3 files changed, 16 insertions, 68 deletions
diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx
index 2f99019..e168587 100644
--- a/msgpack/_unpacker.pyx
+++ b/msgpack/_unpacker.pyx
@@ -135,10 +135,10 @@ cdef inline int get_data_from_buffer(object obj,
if view.itemsize != 1:
PyBuffer_Release(view)
raise BufferError("cannot unpack from multi-byte object")
- if PyBuffer_IsContiguous(view, 'A') == 0:
+ if PyBuffer_IsContiguous(view, b'A') == 0:
PyBuffer_Release(view)
# create a contiguous copy and get buffer
- contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, 'C')
+ contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, b'C')
PyObject_GetBuffer(contiguous, view, PyBUF_SIMPLE)
# view must hold the only reference to contiguous,
# so memory is freed when view is released
@@ -440,14 +440,11 @@ cdef class Unpacker(object):
else:
self.file_like = None
- cdef object _unpack(self, execute_fn execute, object write_bytes, bint iter=0):
+ cdef object _unpack(self, execute_fn execute, bint iter=0):
cdef int ret
cdef object obj
cdef Py_ssize_t prev_head
- if write_bytes is not None:
- PyErr_WarnEx(DeprecationWarning, "`write_bytes` option is deprecated. Use `.tell()` instead.", 1)
-
if self.buf_head >= self.buf_tail and self.file_like is not None:
self.read_from_file()
@@ -461,8 +458,6 @@ cdef class Unpacker(object):
ret = execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head)
self.stream_offset += self.buf_head - prev_head
- if write_bytes is not None:
- write_bytes(PyBytes_FromStringAndSize(self.buf + prev_head, self.buf_head - prev_head))
if ret == 1:
obj = unpack_data(&self.ctx)
@@ -489,41 +484,35 @@ cdef class Unpacker(object):
ret += self.file_like.read(nbytes - len(ret))
return ret
- def unpack(self, object write_bytes=None):
+ def unpack(self):
"""Unpack one object
- If write_bytes is not None, it will be called with parts of the raw
- message as it is unpacked.
-
Raises `OutOfData` when there are no more bytes to unpack.
"""
- return self._unpack(unpack_construct, write_bytes)
+ return self._unpack(unpack_construct)
- def skip(self, object write_bytes=None):
+ def skip(self):
"""Read and ignore one object, returning None
- If write_bytes is not None, it will be called with parts of the raw
- message as it is unpacked.
-
Raises `OutOfData` when there are no more bytes to unpack.
"""
- return self._unpack(unpack_skip, write_bytes)
+ return self._unpack(unpack_skip)
- def read_array_header(self, object write_bytes=None):
+ def read_array_header(self):
"""assuming the next object is an array, return its size n, such that
the next n unpack() calls will iterate over its contents.
Raises `OutOfData` when there are no more bytes to unpack.
"""
- return self._unpack(read_array_header, write_bytes)
+ return self._unpack(read_array_header)
- def read_map_header(self, object write_bytes=None):
+ def read_map_header(self):
"""assuming the next object is a map, return its size n, such that the
next n * 2 unpack() calls will iterate over its key-value pairs.
Raises `OutOfData` when there are no more bytes to unpack.
"""
- return self._unpack(read_map_header, write_bytes)
+ return self._unpack(read_map_header)
def tell(self):
return self.stream_offset
@@ -532,7 +521,7 @@ cdef class Unpacker(object):
return self
def __next__(self):
- return self._unpack(unpack_construct, None, 1)
+ return self._unpack(unpack_construct, 1)
# for debug.
#def _buf(self):
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index 9d46171..b9ef296 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -640,34 +640,22 @@ class Unpacker(object):
next = __next__
- def skip(self, write_bytes=None):
+ def skip(self):
self._unpack(EX_SKIP)
- if write_bytes is not None:
- warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
- write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
self._consume()
- def unpack(self, write_bytes=None):
+ def unpack(self):
ret = self._unpack(EX_CONSTRUCT)
- if write_bytes is not None:
- warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
- write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
self._consume()
return ret
- def read_array_header(self, write_bytes=None):
+ def read_array_header(self):
ret = self._unpack(EX_READ_ARRAY_HEADER)
- if write_bytes is not None:
- warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
- write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
self._consume()
return ret
- def read_map_header(self, write_bytes=None):
+ def read_map_header(self):
ret = self._unpack(EX_READ_MAP_HEADER)
- if write_bytes is not None:
- warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
- write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
self._consume()
return ret
diff --git a/test/test_unpack_raw.py b/test/test_unpack_raw.py
deleted file mode 100644
index 7002601..0000000
--- a/test/test_unpack_raw.py
+++ /dev/null
@@ -1,29 +0,0 @@
-"""Tests for cases where the user seeks to obtain packed msgpack objects"""
-
-import io
-from msgpack import Unpacker, packb
-
-
-def test_write_bytes():
- unpacker = Unpacker()
- unpacker.feed(b'abc')
- f = io.BytesIO()
- assert unpacker.unpack(f.write) == ord('a')
- assert f.getvalue() == b'a'
- f = io.BytesIO()
- assert unpacker.skip(f.write) is None
- assert f.getvalue() == b'b'
- f = io.BytesIO()
- assert unpacker.skip() is None
- assert f.getvalue() == b''
-
-
-def test_write_bytes_multi_buffer():
- long_val = (5) * 100
- expected = packb(long_val)
- unpacker = Unpacker(io.BytesIO(expected), read_size=3, max_buffer_size=3)
-
- f = io.BytesIO()
- unpacked = unpacker.unpack(f.write)
- assert unpacked == long_val
- assert f.getvalue() == expected