diff options
author | Jack Hindmarch <1750152+jackh-ncl@users.noreply.github.com> | 2022-10-19 10:38:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 10:38:59 (GMT) |
commit | b6e59d76c0e1214ca2c927be35f165ecd1f763df (patch) | |
tree | 18d1b378490ca962fc6e031d767d36b23022b2ff | |
parent | a3be8743348464364db9d513b22bcdd39a2c5fb5 (diff) | |
download | cpython-b6e59d76c0e1214ca2c927be35f165ecd1f763df.zip cpython-b6e59d76c0e1214ca2c927be35f165ecd1f763df.tar.gz cpython-b6e59d76c0e1214ca2c927be35f165ecd1f763df.tar.bz2 |
gh-92886: Replace assertion statements in `handlers.BaseHandler` to support running with optimizations (`-O`) (GH-93231)
-rw-r--r-- | Lib/wsgiref/handlers.py | 12 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-05-25-22-09-38.gh-issue-92886.ylwDSc.rst | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py index 6623b70..cd0916d 100644 --- a/Lib/wsgiref/handlers.py +++ b/Lib/wsgiref/handlers.py @@ -237,9 +237,7 @@ class BaseHandler: 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 @@ class BaseHandler: 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: 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 0000000..7854381 --- /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:`~wsgiref.BaseHandler` so that the tested behaviour is maintained running with optimizations ``(-O)``. |