summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorcibofo <53799417+cibofo@users.noreply.github.com>2022-05-05 22:39:02 (GMT)
committerGitHub <noreply@github.com>2022-05-05 22:39:02 (GMT)
commit9a0a7b4868c1e40a1863394bc475132b47d8926f (patch)
tree17206e43f3e347093d75ef3744cc94fbc6e3f76e /Lib/http
parentbb35d6504aca0348c212281efbdde2caf84cd116 (diff)
downloadcpython-9a0a7b4868c1e40a1863394bc475132b47d8926f.zip
cpython-9a0a7b4868c1e40a1863394bc475132b47d8926f.tar.gz
cpython-9a0a7b4868c1e40a1863394bc475132b47d8926f.tar.bz2
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>
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/__init__.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/Lib/http/__init__.py b/Lib/http/__init__.py
index 8b980e2..cd2885d 100644
--- a/Lib/http/__init__.py
+++ b/Lib/http/__init__.py
@@ -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.'