MCPcopy Index your code
hub / github.com/encode/httpx / codes

Class codes

httpx/_status_codes.py:8–157  ·  view source on GitHub ↗

HTTP status codes and reason phrases Status codes from the following RFCs are all observed: * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616 * RFC 6585: Additional HTTP Status Codes * RFC 3229: Delta encoding in HTTP * RFC 4918: HTTP Extensions

Source from the content-addressed store, hash-verified

6
7
8class codes(IntEnum):
9 """HTTP status codes and reason phrases
10
11 Status codes from the following RFCs are all observed:
12
13 * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
14 * RFC 6585: Additional HTTP Status Codes
15 * RFC 3229: Delta encoding in HTTP
16 * RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518
17 * RFC 5842: Binding Extensions to WebDAV
18 * RFC 7238: Permanent Redirect
19 * RFC 2295: Transparent Content Negotiation in HTTP
20 * RFC 2774: An HTTP Extension Framework
21 * RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)
22 * RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)
23 * RFC 7725: An HTTP Status Code to Report Legal Obstacles
24 * RFC 8297: An HTTP Status Code for Indicating Hints
25 * RFC 8470: Using Early Data in HTTP
26 """
27
28 def __new__(cls, value: int, phrase: str = "") -> codes:
29 obj = int.__new__(cls, value)
30 obj._value_ = value
31
32 obj.phrase = phrase # type: ignore[attr-defined]
33 return obj
34
35 def __str__(self) -> str:
36 return str(self.value)
37
38 @classmethod
39 def get_reason_phrase(cls, value: int) -> str:
40 try:
41 return codes(value).phrase # type: ignore
42 except ValueError:
43 return ""
44
45 @classmethod
46 def is_informational(cls, value: int) -> bool:
47 """
48 Returns `True` for 1xx status codes, `False` otherwise.
49 """
50 return 100 <= value <= 199
51
52 @classmethod
53 def is_success(cls, value: int) -> bool:
54 """
55 Returns `True` for 2xx status codes, `False` otherwise.
56 """
57 return 200 <= value <= 299
58
59 @classmethod
60 def is_redirect(cls, value: int) -> bool:
61 """
62 Returns `True` for 3xx status codes, `False` otherwise.
63 """
64 return 300 <= value <= 399
65

Callers 1

get_reason_phraseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected