Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/starlette/exceptions.py: 48%
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
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
1from __future__ import annotations
3import http
4from collections.abc import Mapping
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
15 def __str__(self) -> str:
16 return f"{self.status_code}: {self.detail}"
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})"
23class WebSocketException(Exception):
24 def __init__(self, code: int, reason: str | None = None) -> None:
25 self.code = code
26 self.reason = reason or ""
28 def __str__(self) -> str:
29 return f"{self.code}: {self.reason}"
31 def __repr__(self) -> str:
32 class_name = self.__class__.__name__
33 return f"{class_name}(code={self.code!r}, reason={self.reason!r})"
36class StarletteDeprecationWarning(UserWarning):
37 """A custom deprecation warning for Starlette.
39 Unlike the built-in DeprecationWarning, this inherits from UserWarning to ensure it is visible by default, helping
40 users discover deprecated features without needing to enable warnings explicitly.
42 Reference: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries
43 """