exceptions.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """
  2. Exceptions that can be thrown by hyperframe.
  3. """
  4. from __future__ import annotations
  5. class HyperframeError(Exception):
  6. """
  7. The base class for all exceptions for the hyperframe module.
  8. .. versionadded:: 6.0.0
  9. """
  10. class UnknownFrameError(HyperframeError):
  11. """
  12. A frame of unknown type was received.
  13. .. versionchanged:: 6.0.0
  14. Changed base class from `ValueError` to :class:`HyperframeError`
  15. """
  16. def __init__(self, frame_type: int, length: int) -> None:
  17. #: The type byte of the unknown frame that was received.
  18. self.frame_type = frame_type
  19. #: The length of the data portion of the unknown frame.
  20. self.length = length
  21. def __str__(self) -> str:
  22. return (
  23. f"UnknownFrameError: Unknown frame type 0x{self.frame_type:X} received, length {self.length} bytes"
  24. )
  25. class InvalidPaddingError(HyperframeError):
  26. """
  27. A frame with invalid padding was received.
  28. .. versionchanged:: 6.0.0
  29. Changed base class from `ValueError` to :class:`HyperframeError`
  30. """
  31. class InvalidFrameError(HyperframeError):
  32. """
  33. Parsing a frame failed because the data was not laid out appropriately.
  34. .. versionadded:: 3.0.2
  35. .. versionchanged:: 6.0.0
  36. Changed base class from `ValueError` to :class:`HyperframeError`
  37. """
  38. class InvalidDataError(HyperframeError):
  39. """
  40. Content or data of a frame was is invalid or violates the specification.
  41. .. versionadded:: 6.0.0
  42. """