From e55acbbffd735bbc0c7b87dc94da56cc4d91a1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:20:57 +0100 Subject: [PATCH 1/4] wsgiref: indicate that `start_response` objects should follow a specific protocol --- Doc/library/wsgiref.rst | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst index 8d4c5eb6600e8b..6e97c753533ee2 100644 --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -119,7 +119,8 @@ in type annotations. applications to set up dummy environments. It should NOT be used by actual WSGI servers or applications, since the data is fake! - Example usage:: + Example usage, where the *start_response* callable should follow the + :class:`StartResponse` protocol:: from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server @@ -312,6 +313,9 @@ request. (E.g., using the :func:`shift_path_info` function from as :mod:`wsgiref.simple_server`) is able to run a simple WSGI application correctly. + The *start_response* callable should follow the :class:`StartResponse` + protocol. + .. class:: WSGIServer(server_address, RequestHandlerClass) @@ -679,7 +683,9 @@ input, output, and error streams. This method can access the current error using ``sys.exception()``, and should pass that information to *start_response* when calling it (as - described in the "Error Handling" section of :pep:`3333`). + described in the "Error Handling" section of :pep:`3333`). In particular, + the *start_response* callable should follow the :class:`StartResponse` + protocol. The default implementation just uses the :attr:`error_status`, :attr:`error_headers`, and :attr:`error_body` attributes to generate an output @@ -781,7 +787,7 @@ in :pep:`3333`. .. versionadded:: 3.11 -.. class:: StartResponse() +.. class:: StartResponse A :class:`typing.Protocol` describing :pep:`start_response() <3333#the-start-response-callable>` @@ -816,7 +822,8 @@ in :pep:`3333`. Examples -------- -This is a working "Hello World" WSGI application:: +This is a working "Hello World" WSGI application, where the *start_response* +callable should follow the :class:`StartResponse` protocol:: """ Every WSGI application must have an application object - a callable From 60244129c1c1d6c31a04d535a9e55089513e6acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:33:20 +0100 Subject: [PATCH 2/4] Update wsgiref.rst The `StartResponse` class is documented under `wsgiref.types.StartResponse` and not `wsgiref.StartResponse`. --- Doc/library/wsgiref.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst index 6e97c753533ee2..32a7654d0411d4 100644 --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -120,7 +120,7 @@ in type annotations. servers or applications, since the data is fake! Example usage, where the *start_response* callable should follow the - :class:`StartResponse` protocol:: + :class:`.StartResponse` protocol:: from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server @@ -313,8 +313,7 @@ request. (E.g., using the :func:`shift_path_info` function from as :mod:`wsgiref.simple_server`) is able to run a simple WSGI application correctly. - The *start_response* callable should follow the :class:`StartResponse` - protocol. + The *start_response* callable should follow the :class:`.StartResponse` protocol. .. class:: WSGIServer(server_address, RequestHandlerClass) @@ -684,7 +683,7 @@ input, output, and error streams. This method can access the current error using ``sys.exception()``, and should pass that information to *start_response* when calling it (as described in the "Error Handling" section of :pep:`3333`). In particular, - the *start_response* callable should follow the :class:`StartResponse` + the *start_response* callable should follow the :class:`.StartResponse` protocol. The default implementation just uses the :attr:`error_status`, @@ -823,7 +822,7 @@ Examples -------- This is a working "Hello World" WSGI application, where the *start_response* -callable should follow the :class:`StartResponse` protocol:: +callable should follow the :class:`.StartResponse` protocol:: """ Every WSGI application must have an application object - a callable From 3122a3976774530a20d8cccb0d0c6e6e57ee9363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 11 Jan 2025 11:15:23 +0100 Subject: [PATCH 3/4] update wording --- Doc/library/wsgiref.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst index 32a7654d0411d4..c8bcb1ed0eaf42 100644 --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -119,8 +119,7 @@ in type annotations. applications to set up dummy environments. It should NOT be used by actual WSGI servers or applications, since the data is fake! - Example usage, where the *start_response* callable should follow the - :class:`.StartResponse` protocol:: + Example usage (see also :func:`demo_app` for another example):: from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server From a4a9e4434cbf081d5d8d1aa7a202f2b5e92fb3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 22 Feb 2025 11:34:27 +0100 Subject: [PATCH 4/4] fix ref --- Doc/library/wsgiref.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst index c8bcb1ed0eaf42..381c993834753d 100644 --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -119,7 +119,8 @@ in type annotations. applications to set up dummy environments. It should NOT be used by actual WSGI servers or applications, since the data is fake! - Example usage (see also :func:`demo_app` for another example):: + Example usage (see also :func:`~wsgiref.simple_server.demo_app` + for another example):: from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server