msgpack-python/msgpack/exceptions.py

49 lines
1.1 KiB
Python
Raw Normal View History

2016-02-12 15:39:50 +02:00
class UnpackException(Exception):
"""Base class for some exceptions raised while unpacking.
2012-12-10 00:31:19 +09:00
NOTE: unpack may raise exception other than subclass of
UnpackException. If you want to catch all error, catch
Exception instead.
"""
2012-12-10 00:31:19 +09:00
2018-11-20 13:12:49 +09:00
2012-12-10 00:31:19 +09:00
class BufferFull(UnpackException):
pass
class OutOfData(UnpackException):
pass
2018-11-20 13:12:49 +09:00
class FormatError(ValueError, UnpackException):
"""Invalid msgpack format"""
class StackError(ValueError, UnpackException):
"""Too nested"""
# Deprecated. Use ValueError instead
UnpackValueError = ValueError
2012-12-10 00:31:19 +09:00
2016-02-14 11:46:28 +09:00
class ExtraData(UnpackValueError):
"""ExtraData is raised when there is trailing data.
This exception is raised while only one-shot (not streaming)
unpack.
"""
2018-11-20 13:12:49 +09:00
2012-12-10 00:31:19 +09:00
def __init__(self, unpacked, extra):
self.unpacked = unpacked
self.extra = extra
def __str__(self):
return "unpack(b) received extra data."
2012-12-11 22:15:21 +09:00
2016-02-12 15:39:50 +02:00
2018-11-20 13:12:49 +09:00
# Deprecated. Use Exception instead to catch all exception during packing.
PackException = Exception
PackValueError = ValueError
PackOverflowError = OverflowError