Kaydet (Commit) ae247a5f authored tarafından Antoine Pitrou's avatar Antoine Pitrou

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

Patch by Brent Tubbs.
üst 2778d0d1
...@@ -656,40 +656,27 @@ class HandlerTests(TestCase): ...@@ -656,40 +656,27 @@ class HandlerTests(TestCase):
b"data", b"data",
h.stdout.getvalue()) 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():
support.run_unittest(__name__) support.run_unittest(__name__)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
# the above lines intentionally left blank
...@@ -174,11 +174,13 @@ class BaseHandler: ...@@ -174,11 +174,13 @@ class BaseHandler:
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):
......
...@@ -1067,6 +1067,7 @@ Richard Townsend ...@@ -1067,6 +1067,7 @@ Richard Townsend
Laurence Tratt Laurence Tratt
John Tromp John Tromp
Jason Trowbridge Jason Trowbridge
Brent Tubbs
Anthony Tuininga Anthony Tuininga
Erno Tukia Erno Tukia
David Turner David Turner
......
...@@ -132,6 +132,9 @@ Core and Builtins ...@@ -132,6 +132,9 @@ Core and Builtins
Library Library
------- -------
- Issue #16220: wsgiref now always calls close() on an iterable response.
Patch by Brent Tubbs.
- Issue #16270: urllib may hang when used for retrieving files via FTP by using - Issue #16270: urllib may hang when used for retrieving files via FTP by using
a context manager. Patch by Giampaolo Rodola'. a context manager. Patch by Giampaolo Rodola'.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment