reraising ValueError from unpack.h as UnpackValueError

This commit is contained in:
palaviv 2016-02-12 15:37:39 +02:00
parent d44063119b
commit 1183eff688
1 changed files with 19 additions and 16 deletions

View File

@ -397,6 +397,7 @@ cdef class Unpacker(object):
else:
raise OutOfData("No more data to unpack.")
try:
ret = execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head)
if write_bytes is not None:
write_bytes(PyBytes_FromStringAndSize(self.buf + prev_head, self.buf_head - prev_head))
@ -414,7 +415,9 @@ cdef class Unpacker(object):
else:
raise OutOfData("No more data to unpack.")
else:
raise ValueError("Unpack failed: error = %d" % (ret,))
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
except ValueError as e:
raise UnpackValueError(e)
def read_bytes(self, Py_ssize_t nbytes):
"""Read a specified number of raw bytes from the stream"""