Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-92886: Replace assertion statements in handlers.BaseHandler to support running with optimizations (-O) #93231

Merged
merged 6 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Lib/wsgiref/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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)``.
jackh-ncl marked this conversation as resolved.
Show resolved Hide resolved