exceptions.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """asyncio exceptions."""
  2. __all__ = ('CancelledError', 'InvalidStateError', 'TimeoutError',
  3. 'IncompleteReadError', 'LimitOverrunError',
  4. 'SendfileNotAvailableError')
  5. class CancelledError(BaseException):
  6. """The Future or Task was cancelled."""
  7. class TimeoutError(Exception):
  8. """The operation exceeded the given deadline."""
  9. class InvalidStateError(Exception):
  10. """The operation is not allowed in this state."""
  11. class SendfileNotAvailableError(RuntimeError):
  12. """Sendfile syscall is not available.
  13. Raised if OS does not support sendfile syscall for given socket or
  14. file type.
  15. """
  16. class IncompleteReadError(EOFError):
  17. """
  18. Incomplete read error. Attributes:
  19. - partial: read bytes string before the end of stream was reached
  20. - expected: total number of expected bytes (or None if unknown)
  21. """
  22. def __init__(self, partial, expected):
  23. r_expected = 'undefined' if expected is None else repr(expected)
  24. super().__init__(f'{len(partial)} bytes read on a total of '
  25. f'{r_expected} expected bytes')
  26. self.partial = partial
  27. self.expected = expected
  28. def __reduce__(self):
  29. return type(self), (self.partial, self.expected)
  30. class LimitOverrunError(Exception):
  31. """Reached the buffer limit while looking for a separator.
  32. Attributes:
  33. - consumed: total number of to be consumed bytes.
  34. """
  35. def __init__(self, message, consumed):
  36. super().__init__(message)
  37. self.consumed = consumed
  38. def __reduce__(self):
  39. return type(self), (self.args[0], self.consumed)