summaryrefslogtreecommitdiff
path: root/msgpack/_unpacker.pyx
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2016-02-14 17:08:13 +0900
committerINADA Naoki <methane@users.noreply.github.com>2016-02-14 17:08:13 +0900
commitf895517995754ce9bb758a77ea3db9ac7e6262c9 (patch)
tree66c3c4472ac6530cb861cab553d045dc716fd082 /msgpack/_unpacker.pyx
parent82b31215079bc47bd4d5a8f3c18d83ac73c8221b (diff)
parentb2a8ce6cbdbef80d1a89d02fa483f56862cf1efa (diff)
downloadmsgpack-python-f895517995754ce9bb758a77ea3db9ac7e6262c9.tar.gz
Merge pull request #172 from methane/palaviv-msgpack-exceptions
Organize Exceptions
Diffstat (limited to 'msgpack/_unpacker.pyx')
-rw-r--r--msgpack/_unpacker.pyx47
1 files changed, 25 insertions, 22 deletions
diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx
index 1aefc64..0443505 100644
--- a/msgpack/_unpacker.pyx
+++ b/msgpack/_unpacker.pyx
@@ -11,11 +11,11 @@ from libc.string cimport *
from libc.limits cimport *
from msgpack.exceptions import (
- BufferFull,
- OutOfData,
- UnpackValueError,
- ExtraData,
- )
+ BufferFull,
+ OutOfData,
+ UnpackValueError,
+ ExtraData,
+)
from msgpack import ExtType
@@ -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"""