mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-29183: Fix double exceptions in wsgiref.handlers.BaseHandler (GH-12914)
This commit is contained in:
parent
f4e1babf44
commit
7c59362a15
3 changed files with 38 additions and 1 deletions
|
@ -806,6 +806,31 @@ class HandlerTests(TestCase):
|
|||
|
||||
self.assertFalse(stderr.getvalue())
|
||||
|
||||
def testDontResetInternalStateOnException(self):
|
||||
class CustomException(ValueError):
|
||||
pass
|
||||
|
||||
# We are raising CustomException here to trigger an exception
|
||||
# during the execution of SimpleHandler.finish_response(), so
|
||||
# we can easily test that the internal state of the handler is
|
||||
# preserved in case of an exception.
|
||||
class AbortingWriter:
|
||||
def write(self, b):
|
||||
raise CustomException
|
||||
|
||||
stderr = StringIO()
|
||||
environ = {"SERVER_PROTOCOL": "HTTP/1.0"}
|
||||
h = SimpleHandler(BytesIO(), AbortingWriter(), stderr, environ)
|
||||
h.run(hello_app)
|
||||
|
||||
self.assertIn("CustomException", stderr.getvalue())
|
||||
|
||||
# Test that the internal state of the handler is preserved.
|
||||
self.assertIsNotNone(h.result)
|
||||
self.assertIsNotNone(h.headers)
|
||||
self.assertIsNotNone(h.status)
|
||||
self.assertIsNotNone(h.environ)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue