mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-91996: Add an HTTPMethod StrEnum to http (GH-91997)
* Add HTTPMethod enum to http Create a StrEnum for the 9 common HTTP methods. Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
bb35d6504a
commit
9a0a7b4868
4 changed files with 80 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
from enum import IntEnum, _simple_enum
|
||||
from enum import StrEnum, IntEnum, _simple_enum
|
||||
|
||||
__all__ = ['HTTPStatus']
|
||||
__all__ = ['HTTPStatus', 'HTTPMethod']
|
||||
|
||||
|
||||
@_simple_enum(IntEnum)
|
||||
|
@ -149,3 +149,32 @@ class HTTPStatus:
|
|||
NETWORK_AUTHENTICATION_REQUIRED = (511,
|
||||
'Network Authentication Required',
|
||||
'The client needs to authenticate to gain network access')
|
||||
|
||||
|
||||
@_simple_enum(StrEnum)
|
||||
class HTTPMethod:
|
||||
"""HTTP methods and descriptions
|
||||
|
||||
Methods from the following RFCs are all observed:
|
||||
|
||||
* RFC 7231: Hypertext Transfer Protocol (HTTP/1.1), obsoletes 2616
|
||||
* RFC 5789: PATCH Method for HTTP
|
||||
"""
|
||||
def __new__(cls, value, description):
|
||||
obj = str.__new__(cls, value)
|
||||
obj._value_ = value
|
||||
obj.description = description
|
||||
return obj
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s.%s>" % (self.__class__.__name__, self._name_)
|
||||
|
||||
CONNECT = 'CONNECT', 'Establish a connection to the server.'
|
||||
DELETE = 'DELETE', 'Remove the target.'
|
||||
GET = 'GET', 'Retrieve the target.'
|
||||
HEAD = 'HEAD', 'Same as GET, but only retrieve the status line and header section.'
|
||||
OPTIONS = 'OPTIONS', 'Describe the communication options for the target.'
|
||||
PATCH = 'PATCH', 'Apply partial modifications to a target.'
|
||||
POST = 'POST', 'Perform target-specific processing with the request payload.'
|
||||
PUT = 'PUT', 'Replace the target with the request payload.'
|
||||
TRACE = 'TRACE', 'Perform a message loop-back test along the path to the target.'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue