Coverage for nexios\status.py: 92%

1"""

2 HTTP codes

3 See HTTP Status Code Registry:

4 https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

5

6 And RFC 2324 - https://tools.ietf.org/html/rfc2324

7"""

8

9 from __future__ import annotations

10

11 import warnings

12

13 __all__ = (

14 "HTTP_100_CONTINUE",

15 "HTTP_101_SWITCHING_PROTOCOLS",

16 "HTTP_102_PROCESSING",

17 "HTTP_103_EARLY_HINTS",

18 "HTTP_200_OK",

19 "HTTP_201_CREATED",

20 "HTTP_202_ACCEPTED",

21 "HTTP_203_NON_AUTHORITATIVE_INFORMATION",

22 "HTTP_204_NO_CONTENT",

23 "HTTP_205_RESET_CONTENT",

24 "HTTP_206_PARTIAL_CONTENT",

25 "HTTP_207_MULTI_STATUS",

26 "HTTP_208_ALREADY_REPORTED",

27 "HTTP_226_IM_USED",

28 "HTTP_300_MULTIPLE_CHOICES",

29 "HTTP_301_MOVED_PERMANENTLY",

30 "HTTP_302_FOUND",

31 "HTTP_303_SEE_OTHER",

32 "HTTP_304_NOT_MODIFIED",

33 "HTTP_305_USE_PROXY",

34 "HTTP_306_RESERVED",

35 "HTTP_307_TEMPORARY_REDIRECT",

36 "HTTP_308_PERMANENT_REDIRECT",

37 "HTTP_400_BAD_REQUEST",

38 "HTTP_401_UNAUTHORIZED",

39 "HTTP_402_PAYMENT_REQUIRED",

40 "HTTP_403_FORBIDDEN",

41 "HTTP_404_NOT_FOUND",

42 "HTTP_405_METHOD_NOT_ALLOWED",

43 "HTTP_406_NOT_ACCEPTABLE",

44 "HTTP_407_PROXY_AUTHENTICATION_REQUIRED",

45 "HTTP_408_REQUEST_TIMEOUT",

46 "HTTP_409_CONFLICT",

47 "HTTP_410_GONE",

48 "HTTP_411_LENGTH_REQUIRED",

49 "HTTP_412_PRECONDITION_FAILED",

50 "HTTP_413_REQUEST_ENTITY_TOO_LARGE",

51 "HTTP_414_REQUEST_URI_TOO_LONG",

52 "HTTP_415_UNSUPPORTED_MEDIA_TYPE",

53 "HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE",

54 "HTTP_417_EXPECTATION_FAILED",

55 "HTTP_418_IM_A_TEAPOT",

56 "HTTP_421_MISDIRECTED_REQUEST",

57 "HTTP_422_UNPROCESSABLE_ENTITY",

58 "HTTP_423_LOCKED",

59 "HTTP_424_FAILED_DEPENDENCY",

60 "HTTP_425_TOO_EARLY",

61 "HTTP_426_UPGRADE_REQUIRED",

62 "HTTP_428_PRECONDITION_REQUIRED",

63 "HTTP_429_TOO_MANY_REQUESTS",

64 "HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE",

65 "HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS",

66 "HTTP_500_INTERNAL_SERVER_ERROR",

67 "HTTP_501_NOT_IMPLEMENTED",

68 "HTTP_502_BAD_GATEWAY",

69 "HTTP_503_SERVICE_UNAVAILABLE",

70 "HTTP_504_GATEWAY_TIMEOUT",

71 "HTTP_505_HTTP_VERSION_NOT_SUPPORTED",

72 "HTTP_506_VARIANT_ALSO_NEGOTIATES",

73 "HTTP_507_INSUFFICIENT_STORAGE",

74 "HTTP_508_LOOP_DETECTED",

75 "HTTP_510_NOT_EXTENDED",

76 "HTTP_511_NETWORK_AUTHENTICATION_REQUIRED",

77 "WS_1000_NORMAL_CLOSURE",

78 "WS_1001_GOING_AWAY",

79 "WS_1002_PROTOCOL_ERROR",

80 "WS_1003_UNSUPPORTED_DATA",

81 "WS_1005_NO_STATUS_RCVD",

82 "WS_1006_ABNORMAL_CLOSURE",

83 "WS_1007_INVALID_FRAME_PAYLOAD_DATA",

84 "WS_1008_POLICY_VIOLATION",

85 "WS_1009_MESSAGE_TOO_BIG",

86 "WS_1010_MANDATORY_EXT",

87 "WS_1011_INTERNAL_ERROR",

88 "WS_1012_SERVICE_RESTART",

89 "WS_1013_TRY_AGAIN_LATER",

90 "WS_1014_BAD_GATEWAY",

91 "WS_1015_TLS_HANDSHAKE",

92)

93

94 HTTP_100_CONTINUE = 100

95 HTTP_101_SWITCHING_PROTOCOLS = 101

96 HTTP_102_PROCESSING = 102

97 HTTP_103_EARLY_HINTS = 103

98 HTTP_200_OK = 200

99 HTTP_201_CREATED = 201

100 HTTP_202_ACCEPTED = 202

101 HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203

102 HTTP_204_NO_CONTENT = 204

103 HTTP_205_RESET_CONTENT = 205

104 HTTP_206_PARTIAL_CONTENT = 206

105 HTTP_207_MULTI_STATUS = 207

106 HTTP_208_ALREADY_REPORTED = 208

107 HTTP_226_IM_USED = 226

108 HTTP_300_MULTIPLE_CHOICES = 300

109 HTTP_301_MOVED_PERMANENTLY = 301

110 HTTP_302_FOUND = 302

111 HTTP_303_SEE_OTHER = 303

112 HTTP_304_NOT_MODIFIED = 304

113 HTTP_305_USE_PROXY = 305

114 HTTP_306_RESERVED = 306

115 HTTP_307_TEMPORARY_REDIRECT = 307

116 HTTP_308_PERMANENT_REDIRECT = 308

117 HTTP_400_BAD_REQUEST = 400

118 HTTP_401_UNAUTHORIZED = 401

119 HTTP_402_PAYMENT_REQUIRED = 402

120 HTTP_403_FORBIDDEN = 403

121 HTTP_404_NOT_FOUND = 404

122 HTTP_405_METHOD_NOT_ALLOWED = 405

123 HTTP_406_NOT_ACCEPTABLE = 406

124 HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407

125 HTTP_408_REQUEST_TIMEOUT = 408

126 HTTP_409_CONFLICT = 409

127 HTTP_410_GONE = 410

128 HTTP_411_LENGTH_REQUIRED = 411

129 HTTP_412_PRECONDITION_FAILED = 412

130 HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413

131 HTTP_414_REQUEST_URI_TOO_LONG = 414

132 HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415

133 HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416

134 HTTP_417_EXPECTATION_FAILED = 417

135 HTTP_418_IM_A_TEAPOT = 418

136 HTTP_421_MISDIRECTED_REQUEST = 421

137 HTTP_422_UNPROCESSABLE_ENTITY = 422

138 HTTP_423_LOCKED = 423

139 HTTP_424_FAILED_DEPENDENCY = 424

140 HTTP_425_TOO_EARLY = 425

141 HTTP_426_UPGRADE_REQUIRED = 426

142 HTTP_428_PRECONDITION_REQUIRED = 428

143 HTTP_429_TOO_MANY_REQUESTS = 429

144 HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE = 431

145 HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS = 451

146 HTTP_500_INTERNAL_SERVER_ERROR = 500

147 HTTP_501_NOT_IMPLEMENTED = 501

148 HTTP_502_BAD_GATEWAY = 502

149 HTTP_503_SERVICE_UNAVAILABLE = 503

150 HTTP_504_GATEWAY_TIMEOUT = 504

151 HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505

152 HTTP_506_VARIANT_ALSO_NEGOTIATES = 506

153 HTTP_507_INSUFFICIENT_STORAGE = 507

154 HTTP_508_LOOP_DETECTED = 508

155 HTTP_510_NOT_EXTENDED = 510

156 HTTP_511_NETWORK_AUTHENTICATION_REQUIRED = 511

157

158

159"""

160 WebSocket codes

161 https://www.iana.org/assignments/websocket/websocket.xml#close-code-number

162 https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent

163"""

164 WS_1000_NORMAL_CLOSURE = 1000

165 WS_1001_GOING_AWAY = 1001

166 WS_1002_PROTOCOL_ERROR = 1002

167 WS_1003_UNSUPPORTED_DATA = 1003

168 WS_1005_NO_STATUS_RCVD = 1005

169 WS_1006_ABNORMAL_CLOSURE = 1006

170 WS_1007_INVALID_FRAME_PAYLOAD_DATA = 1007

171 WS_1008_POLICY_VIOLATION = 1008

172 WS_1009_MESSAGE_TOO_BIG = 1009

173 WS_1010_MANDATORY_EXT = 1010

174 WS_1011_INTERNAL_ERROR = 1011

175 WS_1012_SERVICE_RESTART = 1012

176 WS_1013_TRY_AGAIN_LATER = 1013

177 WS_1014_BAD_GATEWAY = 1014

178 WS_1015_TLS_HANDSHAKE = 1015

179

180

181 __deprecated__ = {"WS_1004_NO_STATUS_RCVD": 1004, "WS_1005_ABNORMAL_CLOSURE": 1005}

182

183

184 def __getattr__(name: str) -> int:

185 deprecation_changes = {

186 "WS_1004_NO_STATUS_RCVD": "WS_1005_NO_STATUS_RCVD",

187 "WS_1005_ABNORMAL_CLOSURE": "WS_1006_ABNORMAL_CLOSURE",

188 }

189 deprecated = __deprecated__.get(name)

190 if deprecated:

191 warnings.warn(

192 f"'{name}' is deprecated. Use '{deprecation_changes[name]}' instead.",

193 category=DeprecationWarning,

194 stacklevel=3,

195 )

196 return deprecated

197 raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

198

199

200 def __dir__() -> list[str]:

201 return sorted(list(__all__) + list(__deprecated__.keys()))