From 1e8e482dfb690b20fbc57be28c2b7b6cd1e58f32 Mon Sep 17 00:00:00 2001 From: Jack Hindmarch Date: Wed, 25 May 2022 22:58:44 +0100 Subject: [PATCH 1/3] Replace status assertion statements in `handlers.py` Replace assert statements with `raise AssertionError()` so that behaviour is maintained and `test_wsgiref.py` tests pass while running with optimizations (`-O`). --- Lib/wsgiref/handlers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py index 6623b700537cf9..cd0916dc5553fb 100644 --- a/Lib/wsgiref/handlers.py +++ b/Lib/wsgiref/handlers.py @@ -237,9 +237,7 @@ def start_response(self, status, headers,exc_info=None): self.status = status self.headers = self.headers_class(headers) status = self._convert_string_type(status, "Status") - assert len(status)>=4,"Status must be at least 4 characters" - assert status[:3].isdigit(), "Status message must begin w/3-digit code" - assert status[3]==" ", "Status message must have a space after code" + self._validate_status(status) if __debug__: for name, val in headers: @@ -250,6 +248,14 @@ def start_response(self, status, headers,exc_info=None): return self.write + def _validate_status(self, status): + if len(status) < 4: + raise AssertionError("Status must be at least 4 characters") + if not status[:3].isdigit(): + raise AssertionError("Status message must begin w/3-digit code") + if status[3] != " ": + raise AssertionError("Status message must have a space after code") + def _convert_string_type(self, value, title): """Convert/check value type.""" if type(value) is str: From 994ca363e05b10235266a30dd1ac0a333a2978c7 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 25 May 2022 22:09:38 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst b/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst new file mode 100644 index 00000000000000..4825ec2d3f97fd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst @@ -0,0 +1 @@ +Replace ``assert`` statements with ``raise AssertionError()`` in :class:`BaseHandler` so that behaviour is maintained and tests in ``test_wsgiref.py`` pass when running with optimizations ``(-O)``. From 539de23e3cf6b9a4d7d32e9ad063ac28eda8fcd8 Mon Sep 17 00:00:00 2001 From: Jack Hindmarch <1750152+jackh-ncl@users.noreply.github.com> Date: Tue, 18 Oct 2022 17:08:08 +0100 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst b/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst index 4825ec2d3f97fd..7854381de30f21 100644 --- a/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst +++ b/Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst @@ -1 +1 @@ -Replace ``assert`` statements with ``raise AssertionError()`` in :class:`BaseHandler` so that behaviour is maintained and tests in ``test_wsgiref.py`` pass when running with optimizations ``(-O)``. +Replace ``assert`` statements with ``raise AssertionError()`` in :class:`~wsgiref.BaseHandler` so that the tested behaviour is maintained running with optimizations ``(-O)``.