Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/flask_restx/_http.py: 97%

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

69 statements  

1# encoding: utf-8 

2""" 

3This file is backported from Python 3.5 http built-in module. 

4""" 

5 

6from enum import IntEnum 

7 

8 

9class HTTPStatus(IntEnum): 

10 """HTTP status codes and reason phrases 

11 

12 Status codes from the following RFCs are all observed: 

13 

14 * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616 

15 * RFC 6585: Additional HTTP Status Codes 

16 * RFC 3229: Delta encoding in HTTP 

17 * RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518 

18 * RFC 5842: Binding Extensions to WebDAV 

19 * RFC 7238: Permanent Redirect 

20 * RFC 2295: Transparent Content Negotiation in HTTP 

21 * RFC 2774: An HTTP Extension Framework 

22 """ 

23 

24 def __new__(cls, value, phrase, description=""): 

25 obj = int.__new__(cls, value) 

26 obj._value_ = value 

27 

28 obj.phrase = phrase 

29 obj.description = description 

30 return obj 

31 

32 def __str__(self): 

33 return str(self.value) 

34 

35 # informational 

36 CONTINUE = 100, "Continue", "Request received, please continue" 

37 SWITCHING_PROTOCOLS = ( 

38 101, 

39 "Switching Protocols", 

40 "Switching to new protocol; obey Upgrade header", 

41 ) 

42 PROCESSING = 102, "Processing" 

43 

44 # success 

45 OK = 200, "OK", "Request fulfilled, document follows" 

46 CREATED = 201, "Created", "Document created, URL follows" 

47 ACCEPTED = (202, "Accepted", "Request accepted, processing continues off-line") 

48 NON_AUTHORITATIVE_INFORMATION = ( 

49 203, 

50 "Non-Authoritative Information", 

51 "Request fulfilled from cache", 

52 ) 

53 NO_CONTENT = 204, "No Content", "Request fulfilled, nothing follows" 

54 RESET_CONTENT = 205, "Reset Content", "Clear input form for further input" 

55 PARTIAL_CONTENT = 206, "Partial Content", "Partial content follows" 

56 MULTI_STATUS = 207, "Multi-Status" 

57 ALREADY_REPORTED = 208, "Already Reported" 

58 IM_USED = 226, "IM Used" 

59 

60 # redirection 

61 MULTIPLE_CHOICES = ( 

62 300, 

63 "Multiple Choices", 

64 "Object has several resources -- see URI list", 

65 ) 

66 MOVED_PERMANENTLY = ( 

67 301, 

68 "Moved Permanently", 

69 "Object moved permanently -- see URI list", 

70 ) 

71 FOUND = 302, "Found", "Object moved temporarily -- see URI list" 

72 SEE_OTHER = 303, "See Other", "Object moved -- see Method and URL list" 

73 NOT_MODIFIED = (304, "Not Modified", "Document has not changed since given time") 

74 USE_PROXY = ( 

75 305, 

76 "Use Proxy", 

77 "You must use proxy specified in Location to access this resource", 

78 ) 

79 TEMPORARY_REDIRECT = ( 

80 307, 

81 "Temporary Redirect", 

82 "Object moved temporarily -- see URI list", 

83 ) 

84 PERMANENT_REDIRECT = ( 

85 308, 

86 "Permanent Redirect", 

87 "Object moved temporarily -- see URI list", 

88 ) 

89 

90 # client error 

91 BAD_REQUEST = (400, "Bad Request", "Bad request syntax or unsupported method") 

92 UNAUTHORIZED = (401, "Unauthorized", "No permission -- see authorization schemes") 

93 PAYMENT_REQUIRED = (402, "Payment Required", "No payment -- see charging schemes") 

94 FORBIDDEN = (403, "Forbidden", "Request forbidden -- authorization will not help") 

95 NOT_FOUND = (404, "Not Found", "Nothing matches the given URI") 

96 METHOD_NOT_ALLOWED = ( 

97 405, 

98 "Method Not Allowed", 

99 "Specified method is invalid for this resource", 

100 ) 

101 NOT_ACCEPTABLE = (406, "Not Acceptable", "URI not available in preferred format") 

102 PROXY_AUTHENTICATION_REQUIRED = ( 

103 407, 

104 "Proxy Authentication Required", 

105 "You must authenticate with this proxy before proceeding", 

106 ) 

107 REQUEST_TIMEOUT = (408, "Request Timeout", "Request timed out; try again later") 

108 CONFLICT = 409, "Conflict", "Request conflict" 

109 GONE = (410, "Gone", "URI no longer exists and has been permanently removed") 

110 LENGTH_REQUIRED = (411, "Length Required", "Client must specify Content-Length") 

111 PRECONDITION_FAILED = ( 

112 412, 

113 "Precondition Failed", 

114 "Precondition in headers is false", 

115 ) 

116 REQUEST_ENTITY_TOO_LARGE = (413, "Request Entity Too Large", "Entity is too large") 

117 REQUEST_URI_TOO_LONG = (414, "Request-URI Too Long", "URI is too long") 

118 UNSUPPORTED_MEDIA_TYPE = ( 

119 415, 

120 "Unsupported Media Type", 

121 "Entity body in unsupported format", 

122 ) 

123 REQUESTED_RANGE_NOT_SATISFIABLE = ( 

124 416, 

125 "Requested Range Not Satisfiable", 

126 "Cannot satisfy request range", 

127 ) 

128 EXPECTATION_FAILED = ( 

129 417, 

130 "Expectation Failed", 

131 "Expect condition could not be satisfied", 

132 ) 

133 UNPROCESSABLE_ENTITY = 422, "Unprocessable Entity" 

134 LOCKED = 423, "Locked" 

135 FAILED_DEPENDENCY = 424, "Failed Dependency" 

136 UPGRADE_REQUIRED = 426, "Upgrade Required" 

137 PRECONDITION_REQUIRED = ( 

138 428, 

139 "Precondition Required", 

140 "The origin server requires the request to be conditional", 

141 ) 

142 TOO_MANY_REQUESTS = ( 

143 429, 

144 "Too Many Requests", 

145 "The user has sent too many requests in " 

146 'a given amount of time ("rate limiting")', 

147 ) 

148 REQUEST_HEADER_FIELDS_TOO_LARGE = ( 

149 431, 

150 "Request Header Fields Too Large", 

151 "The server is unwilling to process the request because its header " 

152 "fields are too large", 

153 ) 

154 

155 # server errors 

156 INTERNAL_SERVER_ERROR = ( 

157 500, 

158 "Internal Server Error", 

159 "Server got itself in trouble", 

160 ) 

161 NOT_IMPLEMENTED = (501, "Not Implemented", "Server does not support this operation") 

162 BAD_GATEWAY = (502, "Bad Gateway", "Invalid responses from another server/proxy") 

163 SERVICE_UNAVAILABLE = ( 

164 503, 

165 "Service Unavailable", 

166 "The server cannot process the request due to a high load", 

167 ) 

168 GATEWAY_TIMEOUT = ( 

169 504, 

170 "Gateway Timeout", 

171 "The gateway server did not receive a timely response", 

172 ) 

173 HTTP_VERSION_NOT_SUPPORTED = ( 

174 505, 

175 "HTTP Version Not Supported", 

176 "Cannot fulfill request", 

177 ) 

178 VARIANT_ALSO_NEGOTIATES = 506, "Variant Also Negotiates" 

179 INSUFFICIENT_STORAGE = 507, "Insufficient Storage" 

180 LOOP_DETECTED = 508, "Loop Detected" 

181 NOT_EXTENDED = 510, "Not Extended" 

182 NETWORK_AUTHENTICATION_REQUIRED = ( 

183 511, 

184 "Network Authentication Required", 

185 "The client needs to authenticate to gain network access", 

186 )