exceptions.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """asyncio exceptions."""
  2. __all__ = ('BrokenBarrierError',
  3. 'CancelledError', 'InvalidStateError', 'TimeoutError',
  4. 'IncompleteReadError', 'LimitOverrunError',
  5. 'SendfileNotAvailableError')
  6. class CancelledError(BaseException):
  7. """The Future or Task was cancelled."""
  8. TimeoutError = TimeoutError # make local alias for the standard exception
  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)
  40. class BrokenBarrierError(RuntimeError):
  41. """Barrier is broken by barrier.abort() call."""