blob: cac31a54d2531adacba9b5c6930629e5ca70b4fd [file] [log] [blame]
Andrew Svetlov0baa72f2018-09-11 10:13:04 -07001"""asyncio exceptions."""
2
3
4__all__ = ('CancelledError', 'InvalidStateError', 'TimeoutError',
5 'IncompleteReadError', 'LimitOverrunError',
6 'SendfileNotAvailableError')
7
8import concurrent.futures
9from . import base_futures
10
11
12class CancelledError(concurrent.futures.CancelledError):
13 """The Future or Task was cancelled."""
14
15
16class TimeoutError(concurrent.futures.TimeoutError):
17 """The operation exceeded the given deadline."""
18
19
20class InvalidStateError(concurrent.futures.InvalidStateError):
21 """The operation is not allowed in this state."""
22
23
24class 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
32class 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
49class 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)