summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpalaviv <palaviv@gmail.com>2016-02-12 15:37:39 +0200
committerpalaviv <palaviv@gmail.com>2016-02-12 15:37:39 +0200
commit1183eff688189b0e94ea9e15c5ae13c2f757d745 (patch)
treee487287c80e3fcee4b67c2ecc498d2369f841a1b
parentd44063119bf11fa5c4b559f9e246df60058bfe31 (diff)
downloadmsgpack-python-1183eff688189b0e94ea9e15c5ae13c2f757d745.tar.gz
reraising ValueError from unpack.h as UnpackValueError
-rw-r--r--msgpack/_unpacker.pyx37
1 files changed, 20 insertions, 17 deletions
diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx
index 1aefc64..90ebf7d 100644
--- a/msgpack/_unpacker.pyx
+++ b/msgpack/_unpacker.pyx
@@ -397,24 +397,27 @@ cdef class Unpacker(object):
else:
raise OutOfData("No more data to unpack.")
- 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))
-
- if ret == 1:
- obj = unpack_data(&self.ctx)
- unpack_init(&self.ctx)
- return obj
- elif ret == 0:
- if self.file_like is not None:
- self.read_from_file()
- continue
- if iter:
- raise StopIteration("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))
+
+ if ret == 1:
+ obj = unpack_data(&self.ctx)
+ unpack_init(&self.ctx)
+ return obj
+ elif ret == 0:
+ if self.file_like is not None:
+ self.read_from_file()
+ continue
+ if iter:
+ raise StopIteration("No more data to unpack.")
+ else:
+ raise OutOfData("No more data to unpack.")
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"""