diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-10-21 12:09:05 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-10-21 12:09:05 (GMT) |
commit | e97a24d06a09bfda5b1bec41ecbbbeff63a9e492 (patch) | |
tree | 789ca55321d28419514c35289f91e8ab1a3ed635 | |
parent | c859bd2b2845ac1ac58b5674e54689172ff4df1a (diff) | |
download | cpython-e97a24d06a09bfda5b1bec41ecbbbeff63a9e492.zip cpython-e97a24d06a09bfda5b1bec41ecbbbeff63a9e492.tar.gz cpython-e97a24d06a09bfda5b1bec41ecbbbeff63a9e492.tar.bz2 |
Issue #16220: wsgiref now always calls close() on an iterable response.
Patch by Brent Tubbs.
-rw-r--r-- | Lib/test/test_wsgiref.py | 50 | ||||
-rw-r--r-- | Lib/wsgiref/handlers.py | 12 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 30 insertions, 36 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 45ca620..123eae8 100644 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -591,40 +591,28 @@ class HandlerTests(TestCase): (stdpat%(version,sw), h.stdout.getvalue()) ) -# This epilogue is needed for compatibility with the Python 2.5 regrtest module + def testCloseOnError(self): + side_effects = {'close_called': False} + MSG = b"Some output has been sent" + def error_app(e,s): + s("200 OK",[])(MSG) + class CrashyIterable(object): + def __iter__(self): + while True: + yield b'blah' + raise AssertionError("This should be caught by handler") + + def close(self): + side_effects['close_called'] = True + return CrashyIterable() + + h = ErrorHandler() + h.run(error_app) + self.assertEqual(side_effects['close_called'], True) + def test_main(): test_support.run_unittest(__name__) if __name__ == "__main__": test_main() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# the above lines intentionally left blank diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py index ae1e8cc..8cb57e2 100644 --- a/Lib/wsgiref/handlers.py +++ b/Lib/wsgiref/handlers.py @@ -122,11 +122,13 @@ class BaseHandler: in the event loop to iterate over the data, and to call 'self.close()' once the response is finished. """ - if not self.result_is_file() or not self.sendfile(): - for data in self.result: - self.write(data) - self.finish_content() - self.close() + try: + if not self.result_is_file() or not self.sendfile(): + for data in self.result: + self.write(data) + self.finish_content() + finally: + self.close() def get_scheme(self): @@ -985,6 +985,7 @@ Richard Townsend Laurence Tratt John Tromp Jason Trowbridge +Brent Tubbs Anthony Tuininga David Turner Stephen Turner @@ -122,6 +122,9 @@ Core and Builtins Library ------- +- Issue #16220: wsgiref now always calls close() on an iterable response. + Patch by Brent Tubbs. + - Issue #16176: Properly identify Windows 8 via platform.platform() - Issue #15756: subprocess.poll() now properly handles errno.ECHILD to |