Coverage for /usr/local/lib/python3.12/site-packages/prefect/_internal/compatibility/starlette.py: 40%
14 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 11:21 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 11:21 +0000
1"""
2Compatibility wrapper for starlette status codes.
4Starlette 0.48.0 renamed several status codes per RFC 9110.
5This module provides backwards-compatible access to these codes.
6"""
8from starlette import status as _starlette_status 1a
11class _StatusCompatibility: 1a
12 """
13 Compatibility wrapper that maintains old status code names while using new ones where available.
15 Maps these renamed codes from RFC 9110:
16 - HTTP_422_UNPROCESSABLE_ENTITY -> HTTP_422_UNPROCESSABLE_CONTENT
17 - HTTP_413_REQUEST_ENTITY_TOO_LARGE -> HTTP_413_CONTENT_TOO_LARGE
18 - HTTP_414_REQUEST_URI_TOO_LONG -> HTTP_414_URI_TOO_LONG
19 - HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE -> HTTP_416_RANGE_NOT_SATISFIABLE
20 """
22 def __getattr__(self, name: str) -> int: 1a
23 mapping = { 1a
24 "HTTP_422_UNPROCESSABLE_ENTITY": "HTTP_422_UNPROCESSABLE_CONTENT",
25 "HTTP_413_REQUEST_ENTITY_TOO_LARGE": "HTTP_413_CONTENT_TOO_LARGE",
26 "HTTP_414_REQUEST_URI_TOO_LONG": "HTTP_414_URI_TOO_LONG",
27 "HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE": "HTTP_416_RANGE_NOT_SATISFIABLE",
28 }
30 if name in mapping: 30 ↛ 31line 30 didn't jump to line 31 because the condition on line 30 was never true1a
31 new_name = mapping[name]
32 if hasattr(_starlette_status, new_name):
33 return getattr(_starlette_status, new_name)
34 elif hasattr(_starlette_status, name):
35 return getattr(_starlette_status, name)
36 else:
37 fallback_values = {
38 "HTTP_422_UNPROCESSABLE_ENTITY": 422,
39 "HTTP_413_REQUEST_ENTITY_TOO_LARGE": 413,
40 "HTTP_414_REQUEST_URI_TOO_LONG": 414,
41 "HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE": 416,
42 }
43 return fallback_values[name]
45 return getattr(_starlette_status, name) 1a
48status = _StatusCompatibility() 1a