Skip to content

Commit b6e59d7

Browse files
authored
gh-92886: Replace assertion statements in handlers.BaseHandler to support running with optimizations (-O) (GH-93231)
1 parent a3be874 commit b6e59d7

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Lib/wsgiref/handlers.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def start_response(self, status, headers,exc_info=None):
237237
self.status = status
238238
self.headers = self.headers_class(headers)
239239
status = self._convert_string_type(status, "Status")
240-
assert len(status)>=4,"Status must be at least 4 characters"
241-
assert status[:3].isdigit(), "Status message must begin w/3-digit code"
242-
assert status[3]==" ", "Status message must have a space after code"
240+
self._validate_status(status)
243241

244242
if __debug__:
245243
for name, val in headers:
@@ -250,6 +248,14 @@ def start_response(self, status, headers,exc_info=None):
250248

251249
return self.write
252250

251+
def _validate_status(self, status):
252+
if len(status) < 4:
253+
raise AssertionError("Status must be at least 4 characters")
254+
if not status[:3].isdigit():
255+
raise AssertionError("Status message must begin w/3-digit code")
256+
if status[3] != " ":
257+
raise AssertionError("Status message must have a space after code")
258+
253259
def _convert_string_type(self, value, title):
254260
"""Convert/check value type."""
255261
if type(value) is str:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace ``assert`` statements with ``raise AssertionError()`` in :class:`~wsgiref.BaseHandler` so that the tested behaviour is maintained running with optimizations ``(-O)``.

0 commit comments

Comments
 (0)