Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/starlette/exceptions.py: 44%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

25 statements  

1from __future__ import annotations 

2 

3import http 

4from collections.abc import Mapping 

5 

6 

7class HTTPException(Exception): 

8 def __init__(self, status_code: int, detail: str | None = None, headers: Mapping[str, str] | None = None) -> None: 

9 if detail is None: 

10 detail = http.HTTPStatus(status_code).phrase 

11 self.status_code = status_code 

12 self.detail = detail 

13 self.headers = headers 

14 

15 def __str__(self) -> str: 

16 return f"{self.status_code}: {self.detail}" 

17 

18 def __repr__(self) -> str: 

19 class_name = self.__class__.__name__ 

20 return f"{class_name}(status_code={self.status_code!r}, detail={self.detail!r})" 

21 

22 

23class WebSocketException(Exception): 

24 def __init__(self, code: int, reason: str | None = None) -> None: 

25 self.code = code 

26 self.reason = reason or "" 

27 

28 def __str__(self) -> str: 

29 return f"{self.code}: {self.reason}" 

30 

31 def __repr__(self) -> str: 

32 class_name = self.__class__.__name__ 

33 return f"{class_name}(code={self.code!r}, reason={self.reason!r})"