summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2018-11-09 21:38:39 +0900
committerINADA Naoki <songofacandy@gmail.com>2018-11-09 21:38:39 +0900
commit30569c1bdb8aed9c114b1195a282ca4ba502679e (patch)
tree042608d7567d3144a03290398ef5fe5e24ed53dd
parent9e210bfc1a922031db67bf42e508b1b4550814c6 (diff)
downloadmsgpack-python-30569c1bdb8aed9c114b1195a282ca4ba502679e.tar.gz
Remove deprecated write_bytes option
-rw-r--r--msgpack/_unpacker.pyx35
-rw-r--r--msgpack/fallback.py20
2 files changed, 16 insertions, 39 deletions
diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx
index cc9e7f0..4c07e04 100644
--- a/msgpack/_unpacker.pyx
+++ b/msgpack/_unpacker.pyx
@@ -136,10 +136,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
@@ -441,14 +441,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()
@@ -463,8 +460,6 @@ cdef class Unpacker(object):
try:
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)
@@ -493,41 +488,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
@@ -536,7 +525,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 5b4d6ce..7c5e53e 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -643,34 +643,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