python (3.12.0)

(root)/
lib/
python3.12/
http/
__init__.py
       1  from enum import StrEnum, IntEnum, _simple_enum
       2  
       3  __all__ = ['HTTPStatus', 'HTTPMethod']
       4  
       5  
       6  @_simple_enum(IntEnum)
       7  class ESC[4;38;5;81mHTTPStatus:
       8      """HTTP status codes and reason phrases
       9  
      10      Status codes from the following RFCs are all observed:
      11  
      12          * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
      13          * RFC 6585: Additional HTTP Status Codes
      14          * RFC 3229: Delta encoding in HTTP
      15          * RFC 4918: HTTP Extensions for WebDAV, obsoletes 2518
      16          * RFC 5842: Binding Extensions to WebDAV
      17          * RFC 7238: Permanent Redirect
      18          * RFC 2295: Transparent Content Negotiation in HTTP
      19          * RFC 2774: An HTTP Extension Framework
      20          * RFC 7725: An HTTP Status Code to Report Legal Obstacles
      21          * RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)
      22          * RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)
      23          * RFC 8297: An HTTP Status Code for Indicating Hints
      24          * RFC 8470: Using Early Data in HTTP
      25      """
      26      def __new__(cls, value, phrase, description=''):
      27          obj = int.__new__(cls, value)
      28          obj._value_ = value
      29  
      30          obj.phrase = phrase
      31          obj.description = description
      32          return obj
      33  
      34      @property
      35      def is_informational(self):
      36          return 100 <= self <= 199
      37  
      38      @property
      39      def is_success(self):
      40          return 200 <= self <= 299
      41  
      42      @property
      43      def is_redirection(self):
      44          return 300 <= self <= 399
      45  
      46      @property
      47      def is_client_error(self):
      48          return 400 <= self <= 499
      49  
      50      @property
      51      def is_server_error(self):
      52          return 500 <= self <= 599
      53  
      54      # informational
      55      CONTINUE = 100, 'Continue', 'Request received, please continue'
      56      SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
      57              'Switching to new protocol; obey Upgrade header')
      58      PROCESSING = 102, 'Processing'
      59      EARLY_HINTS = 103, 'Early Hints'
      60  
      61      # success
      62      OK = 200, 'OK', 'Request fulfilled, document follows'
      63      CREATED = 201, 'Created', 'Document created, URL follows'
      64      ACCEPTED = (202, 'Accepted',
      65          'Request accepted, processing continues off-line')
      66      NON_AUTHORITATIVE_INFORMATION = (203,
      67          'Non-Authoritative Information', 'Request fulfilled from cache')
      68      NO_CONTENT = 204, 'No Content', 'Request fulfilled, nothing follows'
      69      RESET_CONTENT = 205, 'Reset Content', 'Clear input form for further input'
      70      PARTIAL_CONTENT = 206, 'Partial Content', 'Partial content follows'
      71      MULTI_STATUS = 207, 'Multi-Status'
      72      ALREADY_REPORTED = 208, 'Already Reported'
      73      IM_USED = 226, 'IM Used'
      74  
      75      # redirection
      76      MULTIPLE_CHOICES = (300, 'Multiple Choices',
      77          'Object has several resources -- see URI list')
      78      MOVED_PERMANENTLY = (301, 'Moved Permanently',
      79          'Object moved permanently -- see URI list')
      80      FOUND = 302, 'Found', 'Object moved temporarily -- see URI list'
      81      SEE_OTHER = 303, 'See Other', 'Object moved -- see Method and URL list'
      82      NOT_MODIFIED = (304, 'Not Modified',
      83          'Document has not changed since given time')
      84      USE_PROXY = (305, 'Use Proxy',
      85          'You must use proxy specified in Location to access this resource')
      86      TEMPORARY_REDIRECT = (307, 'Temporary Redirect',
      87          'Object moved temporarily -- see URI list')
      88      PERMANENT_REDIRECT = (308, 'Permanent Redirect',
      89          'Object moved permanently -- see URI list')
      90  
      91      # client error
      92      BAD_REQUEST = (400, 'Bad Request',
      93          'Bad request syntax or unsupported method')
      94      UNAUTHORIZED = (401, 'Unauthorized',
      95          'No permission -- see authorization schemes')
      96      PAYMENT_REQUIRED = (402, 'Payment Required',
      97          'No payment -- see charging schemes')
      98      FORBIDDEN = (403, 'Forbidden',
      99          'Request forbidden -- authorization will not help')
     100      NOT_FOUND = (404, 'Not Found',
     101          'Nothing matches the given URI')
     102      METHOD_NOT_ALLOWED = (405, 'Method Not Allowed',
     103          'Specified method is invalid for this resource')
     104      NOT_ACCEPTABLE = (406, 'Not Acceptable',
     105          'URI not available in preferred format')
     106      PROXY_AUTHENTICATION_REQUIRED = (407,
     107          'Proxy Authentication Required',
     108          'You must authenticate with this proxy before proceeding')
     109      REQUEST_TIMEOUT = (408, 'Request Timeout',
     110          'Request timed out; try again later')
     111      CONFLICT = 409, 'Conflict', 'Request conflict'
     112      GONE = (410, 'Gone',
     113          'URI no longer exists and has been permanently removed')
     114      LENGTH_REQUIRED = (411, 'Length Required',
     115          'Client must specify Content-Length')
     116      PRECONDITION_FAILED = (412, 'Precondition Failed',
     117          'Precondition in headers is false')
     118      REQUEST_ENTITY_TOO_LARGE = (413, 'Request Entity Too Large',
     119          'Entity is too large')
     120      REQUEST_URI_TOO_LONG = (414, 'Request-URI Too Long',
     121          'URI is too long')
     122      UNSUPPORTED_MEDIA_TYPE = (415, 'Unsupported Media Type',
     123          'Entity body in unsupported format')
     124      REQUESTED_RANGE_NOT_SATISFIABLE = (416,
     125          'Requested Range Not Satisfiable',
     126          'Cannot satisfy request range')
     127      EXPECTATION_FAILED = (417, 'Expectation Failed',
     128          'Expect condition could not be satisfied')
     129      IM_A_TEAPOT = (418, 'I\'m a Teapot',
     130          'Server refuses to brew coffee because it is a teapot.')
     131      MISDIRECTED_REQUEST = (421, 'Misdirected Request',
     132          'Server is not able to produce a response')
     133      UNPROCESSABLE_ENTITY = 422, 'Unprocessable Entity'
     134      LOCKED = 423, 'Locked'
     135      FAILED_DEPENDENCY = 424, 'Failed Dependency'
     136      TOO_EARLY = 425, 'Too Early'
     137      UPGRADE_REQUIRED = 426, 'Upgrade Required'
     138      PRECONDITION_REQUIRED = (428, 'Precondition Required',
     139          'The origin server requires the request to be conditional')
     140      TOO_MANY_REQUESTS = (429, 'Too Many Requests',
     141          'The user has sent too many requests in '
     142          'a given amount of time ("rate limiting")')
     143      REQUEST_HEADER_FIELDS_TOO_LARGE = (431,
     144          'Request Header Fields Too Large',
     145          'The server is unwilling to process the request because its header '
     146          'fields are too large')
     147      UNAVAILABLE_FOR_LEGAL_REASONS = (451,
     148          'Unavailable For Legal Reasons',
     149          'The server is denying access to the '
     150          'resource as a consequence of a legal demand')
     151  
     152      # server errors
     153      INTERNAL_SERVER_ERROR = (500, 'Internal Server Error',
     154          'Server got itself in trouble')
     155      NOT_IMPLEMENTED = (501, 'Not Implemented',
     156          'Server does not support this operation')
     157      BAD_GATEWAY = (502, 'Bad Gateway',
     158          'Invalid responses from another server/proxy')
     159      SERVICE_UNAVAILABLE = (503, 'Service Unavailable',
     160          'The server cannot process the request due to a high load')
     161      GATEWAY_TIMEOUT = (504, 'Gateway Timeout',
     162          'The gateway server did not receive a timely response')
     163      HTTP_VERSION_NOT_SUPPORTED = (505, 'HTTP Version Not Supported',
     164          'Cannot fulfill request')
     165      VARIANT_ALSO_NEGOTIATES = 506, 'Variant Also Negotiates'
     166      INSUFFICIENT_STORAGE = 507, 'Insufficient Storage'
     167      LOOP_DETECTED = 508, 'Loop Detected'
     168      NOT_EXTENDED = 510, 'Not Extended'
     169      NETWORK_AUTHENTICATION_REQUIRED = (511,
     170          'Network Authentication Required',
     171          'The client needs to authenticate to gain network access')
     172  
     173  
     174  @_simple_enum(StrEnum)
     175  class ESC[4;38;5;81mHTTPMethod:
     176      """HTTP methods and descriptions
     177  
     178      Methods from the following RFCs are all observed:
     179  
     180          * RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
     181          * RFC 5789: PATCH Method for HTTP
     182      """
     183      def __new__(cls, value, description):
     184          obj = str.__new__(cls, value)
     185          obj._value_ = value
     186          obj.description = description
     187          return obj
     188  
     189      def __repr__(self):
     190          return "<%s.%s>" % (self.__class__.__name__, self._name_)
     191  
     192      CONNECT = 'CONNECT', 'Establish a connection to the server.'
     193      DELETE = 'DELETE', 'Remove the target.'
     194      GET = 'GET', 'Retrieve the target.'
     195      HEAD = 'HEAD', 'Same as GET, but only retrieve the status line and header section.'
     196      OPTIONS = 'OPTIONS', 'Describe the communication options for the target.'
     197      PATCH = 'PATCH', 'Apply partial modifications to a target.'
     198      POST = 'POST', 'Perform target-specific processing with the request payload.'
     199      PUT = 'PUT', 'Replace the target with the request payload.'
     200      TRACE = 'TRACE', 'Perform a message loop-back test along the path to the target.'