__init__.py 6.0 KB

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