|
| 1 | +""" |
| 2 | +This file is backported from Python 3.5 http built-in module. |
| 3 | +""" |
| 4 | + |
| 5 | +from enum import IntEnum |
| 6 | + |
| 7 | + |
| 8 | +class HTTPStatus(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 | + """ |
| 22 | + |
| 23 | + def __new__(cls, value, phrase, description=""): |
| 24 | + obj = int.__new__(cls, value) |
| 25 | + obj._value_ = value |
| 26 | + |
| 27 | + obj.phrase = phrase |
| 28 | + obj.description = description |
| 29 | + return obj |
| 30 | + |
| 31 | + def __str__(self): |
| 32 | + return str(self.value) |
| 33 | + |
| 34 | + # informational |
| 35 | + CONTINUE = 100, "Continue", "Request received, please continue" |
| 36 | + SWITCHING_PROTOCOLS = ( |
| 37 | + 101, |
| 38 | + "Switching Protocols", |
| 39 | + "Switching to new protocol; obey Upgrade header", |
| 40 | + ) |
| 41 | + PROCESSING = 102, "Processing" |
| 42 | + |
| 43 | + # success |
| 44 | + OK = 200, "OK", "Request fulfilled, document follows" |
| 45 | + CREATED = 201, "Created", "Document created, URL follows" |
| 46 | + ACCEPTED = (202, "Accepted", "Request accepted, processing continues off-line") |
| 47 | + NON_AUTHORITATIVE_INFORMATION = ( |
| 48 | + 203, |
| 49 | + "Non-Authoritative Information", |
| 50 | + "Request fulfilled from cache", |
| 51 | + ) |
| 52 | + NO_CONTENT = 204, "No Content", "Request fulfilled, nothing follows" |
| 53 | + RESET_CONTENT = 205, "Reset Content", "Clear input form for further input" |
| 54 | + PARTIAL_CONTENT = 206, "Partial Content", "Partial content follows" |
| 55 | + MULTI_STATUS = 207, "Multi-Status" |
| 56 | + ALREADY_REPORTED = 208, "Already Reported" |
| 57 | + IM_USED = 226, "IM Used" |
| 58 | + |
| 59 | + # redirection |
| 60 | + MULTIPLE_CHOICES = ( |
| 61 | + 300, |
| 62 | + "Multiple Choices", |
| 63 | + "Object has several resources -- see URI list", |
| 64 | + ) |
| 65 | + MOVED_PERMANENTLY = ( |
| 66 | + 301, |
| 67 | + "Moved Permanently", |
| 68 | + "Object moved permanently -- see URI list", |
| 69 | + ) |
| 70 | + FOUND = 302, "Found", "Object moved temporarily -- see URI list" |
| 71 | + SEE_OTHER = 303, "See Other", "Object moved -- see Method and URL list" |
| 72 | + NOT_MODIFIED = (304, "Not Modified", "Document has not changed since given time") |
| 73 | + USE_PROXY = ( |
| 74 | + 305, |
| 75 | + "Use Proxy", |
| 76 | + "You must use proxy specified in Location to access this resource", |
| 77 | + ) |
| 78 | + TEMPORARY_REDIRECT = ( |
| 79 | + 307, |
| 80 | + "Temporary Redirect", |
| 81 | + "Object moved temporarily -- see URI list", |
| 82 | + ) |
| 83 | + PERMANENT_REDIRECT = ( |
| 84 | + 308, |
| 85 | + "Permanent Redirect", |
| 86 | + "Object moved temporarily -- see URI list", |
| 87 | + ) |
| 88 | + |
| 89 | + # client error |
| 90 | + BAD_REQUEST = (400, "Bad Request", "Bad request syntax or unsupported method") |
| 91 | + UNAUTHORIZED = (401, "Unauthorized", "No permission -- see authorization schemes") |
| 92 | + PAYMENT_REQUIRED = (402, "Payment Required", "No payment -- see charging schemes") |
| 93 | + FORBIDDEN = (403, "Forbidden", "Request forbidden -- authorization will not help") |
| 94 | + NOT_FOUND = (404, "Not Found", "Nothing matches the given URI") |
| 95 | + METHOD_NOT_ALLOWED = ( |
| 96 | + 405, |
| 97 | + "Method Not Allowed", |
| 98 | + "Specified method is invalid for this resource", |
| 99 | + ) |
| 100 | + NOT_ACCEPTABLE = (406, "Not Acceptable", "URI not available in preferred format") |
| 101 | + PROXY_AUTHENTICATION_REQUIRED = ( |
| 102 | + 407, |
| 103 | + "Proxy Authentication Required", |
| 104 | + "You must authenticate with this proxy before proceeding", |
| 105 | + ) |
| 106 | + REQUEST_TIMEOUT = (408, "Request Timeout", "Request timed out; try again later") |
| 107 | + CONFLICT = 409, "Conflict", "Request conflict" |
| 108 | + GONE = (410, "Gone", "URI no longer exists and has been permanently removed") |
| 109 | + LENGTH_REQUIRED = (411, "Length Required", "Client must specify Content-Length") |
| 110 | + PRECONDITION_FAILED = ( |
| 111 | + 412, |
| 112 | + "Precondition Failed", |
| 113 | + "Precondition in headers is false", |
| 114 | + ) |
| 115 | + REQUEST_ENTITY_TOO_LARGE = (413, "Request Entity Too Large", "Entity is too large") |
| 116 | + REQUEST_URI_TOO_LONG = (414, "Request-URI Too Long", "URI is too long") |
| 117 | + UNSUPPORTED_MEDIA_TYPE = ( |
| 118 | + 415, |
| 119 | + "Unsupported Media Type", |
| 120 | + "Entity body in unsupported format", |
| 121 | + ) |
| 122 | + REQUESTED_RANGE_NOT_SATISFIABLE = ( |
| 123 | + 416, |
| 124 | + "Requested Range Not Satisfiable", |
| 125 | + "Cannot satisfy request range", |
| 126 | + ) |
| 127 | + EXPECTATION_FAILED = ( |
| 128 | + 417, |
| 129 | + "Expectation Failed", |
| 130 | + "Expect condition could not be satisfied", |
| 131 | + ) |
| 132 | + UNPROCESSABLE_ENTITY = 422, "Unprocessable Entity" |
| 133 | + LOCKED = 423, "Locked" |
| 134 | + FAILED_DEPENDENCY = 424, "Failed Dependency" |
| 135 | + UPGRADE_REQUIRED = 426, "Upgrade Required" |
| 136 | + PRECONDITION_REQUIRED = ( |
| 137 | + 428, |
| 138 | + "Precondition Required", |
| 139 | + "The origin server requires the request to be conditional", |
| 140 | + ) |
| 141 | + TOO_MANY_REQUESTS = ( |
| 142 | + 429, |
| 143 | + "Too Many Requests", |
| 144 | + "The user has sent too many requests in " |
| 145 | + 'a given amount of time ("rate limiting")', |
| 146 | + ) |
| 147 | + REQUEST_HEADER_FIELDS_TOO_LARGE = ( |
| 148 | + 431, |
| 149 | + "Request Header Fields Too Large", |
| 150 | + "The server is unwilling to process the request because its header " |
| 151 | + "fields are too large", |
| 152 | + ) |
| 153 | + |
| 154 | + # server errors |
| 155 | + INTERNAL_SERVER_ERROR = ( |
| 156 | + 500, |
| 157 | + "Internal Server Error", |
| 158 | + "Server got itself in trouble", |
| 159 | + ) |
| 160 | + NOT_IMPLEMENTED = (501, "Not Implemented", "Server does not support this operation") |
| 161 | + BAD_GATEWAY = (502, "Bad Gateway", "Invalid responses from another server/proxy") |
| 162 | + SERVICE_UNAVAILABLE = ( |
| 163 | + 503, |
| 164 | + "Service Unavailable", |
| 165 | + "The server cannot process the request due to a high load", |
| 166 | + ) |
| 167 | + GATEWAY_TIMEOUT = ( |
| 168 | + 504, |
| 169 | + "Gateway Timeout", |
| 170 | + "The gateway server did not receive a timely response", |
| 171 | + ) |
| 172 | + HTTP_VERSION_NOT_SUPPORTED = ( |
| 173 | + 505, |
| 174 | + "HTTP Version Not Supported", |
| 175 | + "Cannot fulfill request", |
| 176 | + ) |
| 177 | + VARIANT_ALSO_NEGOTIATES = 506, "Variant Also Negotiates" |
| 178 | + INSUFFICIENT_STORAGE = 507, "Insufficient Storage" |
| 179 | + LOOP_DETECTED = 508, "Loop Detected" |
| 180 | + NOT_EXTENDED = 510, "Not Extended" |
| 181 | + NETWORK_AUTHENTICATION_REQUIRED = ( |
| 182 | + 511, |
| 183 | + "Network Authentication Required", |
| 184 | + "The client needs to authenticate to gain network access", |
| 185 | + ) |
0 commit comments