1# -*- coding: utf-8 -*- 2""" 3hyperframe/exceptions 4~~~~~~~~~~~~~~~~~~~~~ 5 6Defines the exceptions that can be thrown by hyperframe. 7""" 8 9 10class HyperframeError(Exception): 11 """ 12 The base class for all exceptions for the hyperframe module. 13 14 .. versionadded:: 6.0.0 15 """ 16 17 18class UnknownFrameError(HyperframeError): 19 """ 20 A frame of unknown type was received. 21 22 .. versionchanged:: 6.0.0 23 Changed base class from `ValueError` to :class:`HyperframeError` 24 """ 25 def __init__(self, frame_type, length): 26 #: The type byte of the unknown frame that was received. 27 self.frame_type = frame_type 28 29 #: The length of the data portion of the unknown frame. 30 self.length = length 31 32 def __str__(self): 33 return ( 34 "UnknownFrameError: Unknown frame type 0x%X received, " 35 "length %d bytes" % (self.frame_type, self.length) 36 ) 37 38 39class InvalidPaddingError(HyperframeError): 40 """ 41 A frame with invalid padding was received. 42 43 .. versionchanged:: 6.0.0 44 Changed base class from `ValueError` to :class:`HyperframeError` 45 """ 46 pass 47 48 49class InvalidFrameError(HyperframeError): 50 """ 51 Parsing a frame failed because the data was not laid out appropriately. 52 53 .. versionadded:: 3.0.2 54 55 .. versionchanged:: 6.0.0 56 Changed base class from `ValueError` to :class:`HyperframeError` 57 """ 58 pass 59 60 61class InvalidDataError(HyperframeError): 62 """ 63 Content or data of a frame was is invalid or violates the specification. 64 65 .. versionadded:: 6.0.0 66 """ 67 pass 68