Issue #16220: wsgiref now always calls close() on an iterable response.

Patch by Brent Tubbs.
This commit is contained in:
Antoine Pitrou 2012-10-21 14:09:05 +02:00
parent c859bd2b28
commit e97a24d06a
4 changed files with 30 additions and 36 deletions

View File

@ -591,40 +591,28 @@ def non_error_app(e,s):
(stdpat%(version,sw), h.stdout.getvalue()) (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(): def test_main():
test_support.run_unittest(__name__) test_support.run_unittest(__name__)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
# the above lines intentionally left blank

View File

@ -122,11 +122,13 @@ def finish_response(self):
in the event loop to iterate over the data, and to call in the event loop to iterate over the data, and to call
'self.close()' once the response is finished. 'self.close()' once the response is finished.
""" """
if not self.result_is_file() or not self.sendfile(): try:
for data in self.result: if not self.result_is_file() or not self.sendfile():
self.write(data) for data in self.result:
self.finish_content() self.write(data)
self.close() self.finish_content()
finally:
self.close()
def get_scheme(self): def get_scheme(self):

View File

@ -985,6 +985,7 @@ Richard Townsend
Laurence Tratt Laurence Tratt
John Tromp John Tromp
Jason Trowbridge Jason Trowbridge
Brent Tubbs
Anthony Tuininga Anthony Tuininga
David Turner David Turner
Stephen Turner Stephen Turner

View File

@ -122,6 +122,9 @@ Core and Builtins
Library 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 #16176: Properly identify Windows 8 via platform.platform()
- Issue #15756: subprocess.poll() now properly handles errno.ECHILD to - Issue #15756: subprocess.poll() now properly handles errno.ECHILD to