8000 Remove deprecated write_bytes option (#322) · Anthchirp/msgpack-python@39f8aa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39f8aa7

Browse files
authored
Remove deprecated write_bytes option (msgpack#322)
1 parent 07f0bee commit 39f8aa7

File tree

3 files changed

+16
-68
lines changed

3 files changed

+16
-68
lines changed

msgpack/_unpacker.pyx

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ cdef inline int get_data_from_buffer(object obj,
135135
if view.itemsize != 1:
136136
PyBuffer_Release(view)
137137
raise BufferError("cannot unpack from multi-byte object")
138-
if PyBuffer_IsContiguous(view, 'A') == 0:
138+
if PyBuffer_IsContiguous(view, b'A') == 0:
139139
PyBuffer_Release(view)
140140
# create a contiguous copy and get buffer
141-
contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, 'C')
141+
contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, b'C')
142142
PyObject_GetBuffer(contiguous, view, PyBUF_SIMPLE)
143143
# view must hold the only reference to contiguous,
144144
# so memory is freed when view is released
@@ -440,14 +440,11 @@ cdef class Unpacker(object):
440440
else:
441441
self.file_like = None
442442

443-
cdef object _unpack(self, execute_fn execute, object write_bytes, bint iter=0):
443+
cdef object _unpack(self, execute_fn execute, bint iter=0):
444444
cdef int ret
445445
cdef object obj
446446
cdef Py_ssize_t prev_head
447447

448-
if write_bytes is not None:
449-
PyErr_WarnEx(DeprecationWarning, "`write_bytes` option is deprecated. Use `.tell()` instead.", 1)
450-
451448
if self.buf_head >= self.buf_tail and self.file_like is not None:
452449
self.read_from_file()
453450

@@ -461,8 +458,6 @@ cdef class Unpacker(object):
461458

462459
ret = execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head)
463460
self.stream_offset += self.buf_head - prev_head
464-
if write_bytes is not None:
465-
write_bytes(PyBytes_FromStringAndSize(self.buf + prev_head, self.buf_head - prev_head))
466461

467462
if ret == 1:
468463
obj = unpack_data(&self.ctx)
@@ -489,41 +484,35 @@ cdef class Unpacker(object):
489484
ret += self.file_like.read(nbytes - len(ret))
490485
return ret
491486

492-
def unpack(self, object write_bytes=None):
487+
def unpack(self):
493488
"""Unpack one object
494489
495-
If write_bytes is not None, it will be called with parts of the raw
496-
message as it is unpacked.
497-
498490
Raises `OutOfData` when there are no more bytes to unpack.
499491
"""
500-
return self._unpack(unpack_construct, write_bytes)
492+
return self._unpack(unpack_construct)
501493

502-
def skip(self, object write_bytes=None):
494+
def skip(self):
503495
"""Read and ignore one object, returning None
504496
505-
If write_bytes is not None, it will be called with parts of the raw
506-
message as it is unpacked.
507-
508497
Raises `OutOfData` when there are no more bytes to unpack.
509498
"""
510-
return self._unpack(unpack_skip, write_bytes)
499+
return self._unpack(unpack_skip)
511500

512-
def read_array_header(self, object write_bytes=None):
501+
def read_array_header(self):
513502
"""assuming the next object is an array, return its size n, such that
514503
the next n unpack() calls will iterate over its contents.
515504
516505
Raises `OutOfData` when there are no more bytes to unpack.
517506
"""
518-
return self._unpack(read_array_header, write_bytes)
507+
return self._unpack(read_array_header)
519508

520-
def read_map_header(self, object write_bytes=None):
509+
def read_map_header(self):
521510
"""assuming the next object is a map, return its size n, such that the
522511
next n * 2 unpack() calls will iterate over its key-value pairs.
523512
524513
Raises `OutOfData` when there are no more bytes to unpack.
525514
"""
526-
return self._unpack(read_map_header, write_bytes)
515+
return self._unpack(read_map_header)
527516

528517
def tell(self):
529518
return self.stream_offset
@@ -532,7 +521,7 @@ cdef class Unpacker(object):
532521
return self
533522

534523
def __next__(self):
535-
return self._unpack(unpack_construct, None, 1)
524+
return self._unpack(unpack_construct, 1)
536525

537526
# for debug.
538527
#def _buf(self):

msgpack/fallback.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -640,34 +640,22 @@ def __next__(self):
640640

641641
next = __next__
642642

643-
def skip(self, write_bytes=None):
643+
def skip(self):
644644
self._unpack(EX_SKIP)
645-
if write_bytes is not None:
646-
warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
647-
write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
648645
self._consume()
649646

650-
def unpack(self, write_bytes=None):
647+
def unpack(self):
651648
ret = self._unpack(EX_CONSTRUCT)
652-
if write_bytes is not None:
653-
warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
654-
write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
655649
self._consume()
656650
return ret
657651

658-
def read_array_header(self, write_bytes=None):
652+
def read_array_header(self):
659653
ret = self._unpack(EX_READ_ARRAY_HEADER)
660-
if write_bytes is not None:
661-
warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
662-
write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
663654
self._consume()
664655
return ret
665656

666-
def read_map_header(self, write_bytes=None):
657+
def read_map_header(self):
667658
ret = self._unpack(EX_READ_MAP_HEADER)
668-
if write_bytes is not None:
669-
warnings.warn("`write_bytes` option is deprecated. Use `.tell()` instead.", DeprecationWarning)
670-
write_bytes(self._buffer[self._buf_checkpoint:self._buff_i])
671659
self._consume()
672660
return ret
673661

test/test_unpack_raw.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0