Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Lib/asyncio/exceptions.py
12 views
1
"""asyncio exceptions."""
2
3
4
__all__ = ('BrokenBarrierError',
5
'CancelledError', 'InvalidStateError', 'TimeoutError',
6
'IncompleteReadError', 'LimitOverrunError',
7
'SendfileNotAvailableError')
8
9
10
class CancelledError(BaseException):
11
"""The Future or Task was cancelled."""
12
13
14
TimeoutError = TimeoutError # make local alias for the standard exception
15
16
17
class InvalidStateError(Exception):
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
r_expected = 'undefined' if expected is None else repr(expected)
38
super().__init__(f'{len(partial)} bytes read on a total of '
39
f'{r_expected} expected bytes')
40
self.partial = partial
41
self.expected = expected
42
43
def __reduce__(self):
44
return type(self), (self.partial, self.expected)
45
46
47
class LimitOverrunError(Exception):
48
"""Reached the buffer limit while looking for a separator.
49
50
Attributes:
51
- consumed: total number of to be consumed bytes.
52
"""
53
def __init__(self, message, consumed):
54
super().__init__(message)
55
self.consumed = consumed
56
57
def __reduce__(self):
58
return type(self), (self.args[0], self.consumed)
59
60
61
class BrokenBarrierError(RuntimeError):
62
"""Barrier is broken by barrier.abort() call."""
63
64