Coverage for /usr/local/lib/python3.12/site-packages/prefect/_internal/compatibility/starlette.py: 65%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 10:48 +0000

1""" 

2Compatibility wrapper for starlette status codes. 

3 

4Starlette 0.48.0 renamed several status codes per RFC 9110. 

5This module provides backwards-compatible access to these codes. 

6""" 

7 

8from starlette import status as _starlette_status 1a

9 

10 

11class _StatusCompatibility: 1a

12 """ 

13 Compatibility wrapper that maintains old status code names while using new ones where available. 

14 

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 """ 

21 

22 def __getattr__(self, name: str) -> int: 1a

23 mapping = { 1abfcgde

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 } 

29 

30 if name in mapping: 1abfcgde

31 new_name = mapping[name] 1bcde

32 if hasattr(_starlette_status, new_name): 32 ↛ 34line 32 didn't jump to line 34 because the condition on line 32 was always true1bcde

33 return getattr(_starlette_status, new_name) 1bcde

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] 

44 

45 return getattr(_starlette_status, name) 1abfcgde

46 

47 

48status = _StatusCompatibility() 1a