Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/_core/_exceptions.py: 73%

26 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 06:12 +0000

1from traceback import format_exception 

2from typing import List 

3 

4 

5class BrokenResourceError(Exception): 

6 """ 

7 Raised when trying to use a resource that has been rendered unusable due to external causes 

8 (e.g. a send stream whose peer has disconnected). 

9 """ 

10 

11 

12class BrokenWorkerProcess(Exception): 

13 """ 

14 Raised by :func:`run_sync_in_process` if the worker process terminates abruptly or otherwise 

15 misbehaves. 

16 """ 

17 

18 

19class BusyResourceError(Exception): 

20 """Raised when two tasks are trying to read from or write to the same resource concurrently.""" 

21 

22 def __init__(self, action: str): 

23 super().__init__(f"Another task is already {action} this resource") 

24 

25 

26class ClosedResourceError(Exception): 

27 """Raised when trying to use a resource that has been closed.""" 

28 

29 

30class DelimiterNotFound(Exception): 

31 """ 

32 Raised during :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_until` if the 

33 maximum number of bytes has been read without the delimiter being found. 

34 """ 

35 

36 def __init__(self, max_bytes: int) -> None: 

37 super().__init__( 

38 f"The delimiter was not found among the first {max_bytes} bytes" 

39 ) 

40 

41 

42class EndOfStream(Exception): 

43 """Raised when trying to read from a stream that has been closed from the other end.""" 

44 

45 

46class ExceptionGroup(BaseException): 

47 """ 

48 Raised when multiple exceptions have been raised in a task group. 

49 

50 :var ~typing.Sequence[BaseException] exceptions: the sequence of exceptions raised together 

51 """ 

52 

53 SEPARATOR = "----------------------------\n" 

54 

55 exceptions: List[BaseException] 

56 

57 def __str__(self) -> str: 

58 tracebacks = [ 

59 "".join(format_exception(type(exc), exc, exc.__traceback__)) 

60 for exc in self.exceptions 

61 ] 

62 return ( 

63 f"{len(self.exceptions)} exceptions were raised in the task group:\n" 

64 f"{self.SEPARATOR}{self.SEPARATOR.join(tracebacks)}" 

65 ) 

66 

67 def __repr__(self) -> str: 

68 exception_reprs = ", ".join(repr(exc) for exc in self.exceptions) 

69 return f"<{self.__class__.__name__}: {exception_reprs}>" 

70 

71 

72class IncompleteRead(Exception): 

73 """ 

74 Raised during :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_exactly` or 

75 :meth:`~anyio.streams.buffered.BufferedByteReceiveStream.receive_until` if the 

76 connection is closed before the requested amount of bytes has been read. 

77 """ 

78 

79 def __init__(self) -> None: 

80 super().__init__( 

81 "The stream was closed before the read operation could be completed" 

82 ) 

83 

84 

85class TypedAttributeLookupError(LookupError): 

86 """ 

87 Raised by :meth:`~anyio.TypedAttributeProvider.extra` when the given typed attribute is not 

88 found and no default value has been given. 

89 """ 

90 

91 

92class WouldBlock(Exception): 

93 """Raised by ``X_nowait`` functions if ``X()`` would block."""