Andrew Svetlov | 0baa72f | 2018-09-11 10:13:04 -0700 | [diff] [blame] | 1 | """asyncio exceptions.""" |
| 2 | |
| 3 | |
| 4 | __all__ = ('CancelledError', 'InvalidStateError', 'TimeoutError', |
| 5 | 'IncompleteReadError', 'LimitOverrunError', |
| 6 | 'SendfileNotAvailableError') |
| 7 | |
Andrew Svetlov | 0baa72f | 2018-09-11 10:13:04 -0700 | [diff] [blame] | 8 | |
Yury Selivanov | 431b540 | 2019-05-27 14:45:12 +0200 | [diff] [blame] | 9 | class CancelledError(BaseException): |
Andrew Svetlov | 0baa72f | 2018-09-11 10:13:04 -0700 | [diff] [blame] | 10 | """The Future or Task was cancelled.""" |
| 11 | |
| 12 | |
Yury Selivanov | 431b540 | 2019-05-27 14:45:12 +0200 | [diff] [blame] | 13 | class TimeoutError(Exception): |
Andrew Svetlov | 0baa72f | 2018-09-11 10:13:04 -0700 | [diff] [blame] | 14 | """The operation exceeded the given deadline.""" |
| 15 | |
| 16 | |
Yury Selivanov | 431b540 | 2019-05-27 14:45:12 +0200 | [diff] [blame] | 17 | class InvalidStateError(Exception): |
Andrew Svetlov | 0baa72f | 2018-09-11 10:13:04 -0700 | [diff] [blame] | 18 | """The operation is not allowed in this state.""" |
| 19 | |
| 20 | |
| 21 | class SendfileNotAvailableError(RuntimeError): |
| 22 | """Sendfile syscall is not available. |
| 23 | |
| 24 | Raised if OS does not support sendfile syscall for given socket or |
| 25 | file type. |
| 26 | """ |
| 27 | |
| 28 | |
| 29 | class IncompleteReadError(EOFError): |
| 30 | """ |
| 31 | Incomplete read error. Attributes: |
| 32 | |
| 33 | - partial: read bytes string before the end of stream was reached |
| 34 | - expected: total number of expected bytes (or None if unknown) |
| 35 | """ |
| 36 | def __init__(self, partial, expected): |
| 37 | super().__init__(f'{len(partial)} bytes read on a total of ' |
| 38 | f'{expected!r} expected bytes') |
| 39 | self.partial = partial |
| 40 | self.expected = expected |
| 41 | |
| 42 | def __reduce__(self): |
| 43 | return type(self), (self.partial, self.expected) |
| 44 | |
| 45 | |
| 46 | class LimitOverrunError(Exception): |
| 47 | """Reached the buffer limit while looking for a separator. |
| 48 | |
| 49 | Attributes: |
| 50 | - consumed: total number of to be consumed bytes. |
| 51 | """ |
| 52 | def __init__(self, message, consumed): |
| 53 | super().__init__(message) |
| 54 | self.consumed = consumed |
| 55 | |
| 56 | def __reduce__(self): |
| 57 | return type(self), (self.args[0], self.consumed) |