2016-02-12 15:39:50 +02:00
|
|
|
class UnpackException(Exception):
|
2018-11-12 02:19:01 +09:00
|
|
|
"""Base class for some exceptions raised while unpacking.
|
2012-12-10 00:31:19 +09:00
|
|
|
|
2018-11-12 02:19:01 +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"""
|
|
|
|
|
|
|
|
|
2018-11-12 02:19:01 +09:00
|
|
|
# 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):
|
2018-11-12 02:19:01 +09:00
|
|
|
"""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):
|
2013-09-13 13:47:13 +02:00
|
|
|
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.
|
2018-11-12 02:19:01 +09:00
|
|
|
PackException = Exception
|
|
|
|
PackValueError = ValueError
|
|
|
|
PackOverflowError = OverflowError
|