• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from enum import IntEnum
2
3__all__ = ['HTTPStatus']
4
5class HTTPStatus(IntEnum):
6    """HTTP status codes and reason phrases
7
8    Status codes from the following RFCs are all observed:
9
10        * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
11        * RFC 6585: Additional HTTP Status Codes
12        * RFC 3229: Delta encoding in HTTP
13        * RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518
14        * RFC 5842: Binding Extensions to WebDAV
15        * RFC 7238: Permanent Redirect
16        * RFC 2295: Transparent Content Negotiation in HTTP
17        * RFC 2774: An HTTP Extension Framework
18    """
19    def __new__(cls, value, phrase, description=''):
20        obj = int.__new__(cls, value)
21        obj._value_ = value
22
23        obj.phrase = phrase
24        obj.description = description
25        return obj
26
27    # informational
28    CONTINUE = 100, 'Continue', 'Request received, please continue'
29    SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
30            'Switching to new protocol; obey Upgrade header')
31    PROCESSING = 102, 'Processing'
32
33    # success
34    OK = 200, 'OK', 'Request fulfilled, document follows'
35    CREATED = 201, 'Created', 'Document created, URL follows'
36    ACCEPTED = (202, 'Accepted',
37        'Request accepted, processing continues off-line')
38    NON_AUTHORITATIVE_INFORMATION = (203,
39        'Non-Authoritative Information', 'Request fulfilled from cache')
40    NO_CONTENT = 204, 'No Content', 'Request fulfilled, nothing follows'
41    RESET_CONTENT = 205, 'Reset Content', 'Clear input form for further input'
42    PARTIAL_CONTENT = 206, 'Partial Content', 'Partial content follows'
43    MULTI_STATUS = 207, 'Multi-Status'
44    ALREADY_REPORTED = 208, 'Already Reported'
45    IM_USED = 226, 'IM Used'
46
47    # redirection
48    MULTIPLE_CHOICES = (300, 'Multiple Choices',
49        'Object has several resources -- see URI list')
50    MOVED_PERMANENTLY = (301, 'Moved Permanently',
51        'Object moved permanently -- see URI list')
52    FOUND = 302, 'Found', 'Object moved temporarily -- see URI list'
53    SEE_OTHER = 303, 'See Other', 'Object moved -- see Method and URL list'
54    NOT_MODIFIED = (304, 'Not Modified',
55        'Document has not changed since given time')
56    USE_PROXY = (305, 'Use Proxy',
57        'You must use proxy specified in Location to access this resource')
58    TEMPORARY_REDIRECT = (307, 'Temporary Redirect',
59        'Object moved temporarily -- see URI list')
60    PERMANENT_REDIRECT = (308, 'Permanent Redirect',
61        'Object moved temporarily -- see URI list')
62
63    # client error
64    BAD_REQUEST = (400, 'Bad Request',
65        'Bad request syntax or unsupported method')
66    UNAUTHORIZED = (401, 'Unauthorized',
67        'No permission -- see authorization schemes')
68    PAYMENT_REQUIRED = (402, 'Payment Required',
69        'No payment -- see charging schemes')
70    FORBIDDEN = (403, 'Forbidden',
71        'Request forbidden -- authorization will not help')
72    NOT_FOUND = (404, 'Not Found',
73        'Nothing matches the given URI')
74    METHOD_NOT_ALLOWED = (405, 'Method Not Allowed',
75        'Specified method is invalid for this resource')
76    NOT_ACCEPTABLE = (406, 'Not Acceptable',
77        'URI not available in preferred format')
78    PROXY_AUTHENTICATION_REQUIRED = (407,
79        'Proxy Authentication Required',
80        'You must authenticate with this proxy before proceeding')
81    REQUEST_TIMEOUT = (408, 'Request Timeout',
82        'Request timed out; try again later')
83    CONFLICT = 409, 'Conflict', 'Request conflict'
84    GONE = (410, 'Gone',
85        'URI no longer exists and has been permanently removed')
86    LENGTH_REQUIRED = (411, 'Length Required',
87        'Client must specify Content-Length')
88    PRECONDITION_FAILED = (412, 'Precondition Failed',
89        'Precondition in headers is false')
90    REQUEST_ENTITY_TOO_LARGE = (413, 'Request Entity Too Large',
91        'Entity is too large')
92    REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long',
93        'URI is too long')
94    UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type',
95        'Entity body in unsupported format')
96    REQUESTED_RANGE_NOT_SATISFIABLE = (416,
97        'Requested Range Not Satisfiable',
98        'Cannot satisfy request range')
99    EXPECTATION_FAILED = (417, 'Expectation Failed',
100        'Expect condition could not be satisfied')
101    UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity'
102    LOCKED = 423, 'Locked'
103    FAILED_DEPENDENCY = 424, 'Failed Dependency'
104    UPGRADE_REQUIRED = 426, 'Upgrade Required'
105    PRECONDITION_REQUIRED = (428, 'Precondition Required',
106        'The origin server requires the request to be conditional')
107    TOO_MANY_REQUESTS = (429, 'Too Many Requests',
108        'The user has sent too many requests in '
109        'a given amount of time ("rate limiting")')
110    REQUEST_HEADER_FIELDS_TOO_LARGE = (431,
111        'Request Header Fields Too Large',
112        'The server is unwilling to process the request because its header '
113        'fields are too large')
114
115    # server errors
116    INTERNAL_SERVER_ERROR = (500, 'Internal Server Error',
117        'Server got itself in trouble')
118    NOT_IMPLEMENTED = (501, 'Not Implemented',
119        'Server does not support this operation')
120    BAD_GATEWAY = (502, 'Bad Gateway',
121        'Invalid responses from another server/proxy')
122    SERVICE_UNAVAILABLE = (503, 'Service Unavailable',
123        'The server cannot process the request due to a high load')
124    GATEWAY_TIMEOUT = (504, 'Gateway Timeout',
125        'The gateway server did not receive a timely response')
126    HTTP_VERSION_NOT_SUPPORTED = (505, 'HTTP Version Not Supported',
127        'Cannot fulfill request')
128    VARIANT_ALSO_NEGOTIATES = 506, 'Variant Also Negotiates'
129    INSUFFICIENT_STORAGE = 507, 'Insufficient Storage'
130    LOOP_DETECTED = 508, 'Loop Detected'
131    NOT_EXTENDED = 510, 'Not Extended'
132    NETWORK_AUTHENTICATION_REQUIRED = (511,
133        'Network Authentication Required',
134        'The client needs to authenticate to gain network access')
135