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 | |
| 8 | import concurrent.futures |
| 9 | from . import base_futures |
| 10 | |
| 11 | |
| 12 | class CancelledError(concurrent.futures.CancelledError): |
| 13 | """The Future or Task was cancelled.""" |
| 14 | |
| 15 | |
| 16 | class TimeoutError(concurrent.futures.TimeoutError): |
| 17 | """The operation exceeded the given deadline.""" |
| 18 | |
| 19 | |
| 20 | class InvalidStateError(concurrent.futures.InvalidStateError): |
| 21 | """The operation is not allowed in this state.""" |
| 22 | |
| 23 | |
| 24 | class SendfileNotAvailableError(RuntimeError): |
| 25 | """Sendfile syscall is not available. |
| 26 | |
| 27 | Raised if OS does not support sendfile syscall for given socket or |
| 28 | file type. |
| 29 | """ |
| 30 | |
| 31 | |
| 32 | class IncompleteReadError(EOFError): |
| 33 | """ |
| 34 | Incomplete read error. Attributes: |
| 35 | |
| 36 | - partial: read bytes string before the end of stream was reached |
| 37 | - expected: total number of expected bytes (or None if unknown) |
| 38 | """ |
| 39 | def __init__(self, partial, expected): |
| 40 | super().__init__(f'{len(partial)} bytes read on a total of ' |
| 41 | f'{expected!r} expected bytes') |
| 42 | self.partial = partial |
| 43 | self.expected = expected |
| 44 | |
| 45 | def __reduce__(self): |
| 46 | return type(self), (self.partial, self.expected) |
| 47 | |
| 48 | |
| 49 | class LimitOverrunError(Exception): |
| 50 | """Reached the buffer limit while looking for a separator. |
| 51 | |
| 52 | Attributes: |
| 53 | - consumed: total number of to be consumed bytes. |
| 54 | """ |
| 55 | def __init__(self, message, consumed): |
| 56 | super().__init__(message) |
| 57 | self.consumed = consumed |
| 58 | |
| 59 | def __reduce__(self): |
| 60 | return type(self), (self.args[0], self.consumed) |