File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -656,40 +656,27 @@ def app(e, s):
656656 b"data" ,
657657 h .stdout .getvalue ())
658658
659- # This epilogue is needed for compatibility with the Python 2.5 regrtest module
659+ def testCloseOnError (self ):
660+ side_effects = {'close_called' : False }
661+ MSG = b"Some output has been sent"
662+ def error_app (e ,s ):
663+ s ("200 OK" ,[])(MSG )
664+ class CrashyIterable (object ):
665+ def __iter__ (self ):
666+ while True :
667+ yield b'blah'
668+ raise AssertionError ("This should be caught by handler" )
669+ def close (self ):
670+ side_effects ['close_called' ] = True
671+ return CrashyIterable ()
672+
673+ h = ErrorHandler ()
674+ h .run (error_app )
675+ self .assertEqual (side_effects ['close_called' ], True )
676+
660677
661678def test_main ():
662679 support .run_unittest (__name__ )
663680
664681if __name__ == "__main__" :
665682 test_main ()
666-
667-
668-
669-
670-
671-
672-
673-
674-
675-
676-
677-
678-
679-
680-
681-
682-
683-
684-
685-
686-
687-
688-
689-
690-
691-
692-
693-
694-
695- # the above lines intentionally left blank
Original file line number Diff line number Diff line change @@ -174,11 +174,13 @@ def finish_response(self):
174174 in the event loop to iterate over the data, and to call
175175 'self.close()' once the response is finished.
176176 """
177- if not self .result_is_file () or not self .sendfile ():
178- for data in self .result :
179- self .write (data )
180- self .finish_content ()
181- self .close ()
177+ try :
178+ if not self .result_is_file () or not self .sendfile ():
179+ for data in self .result :
180+ self .write (data )
181+ self .finish_content ()
182+ finally :
183+ self .close ()
182184
183185
184186 def get_scheme (self ):
Original file line number Diff line number Diff line change @@ -1067,6 +1067,7 @@ Richard Townsend
10671067Laurence Tratt
10681068John Tromp
10691069Jason Trowbridge
1070+ Brent Tubbs
10701071Anthony Tuininga
10711072Erno Tukia
10721073David Turner
Original file line number Diff line number Diff line change @@ -132,6 +132,9 @@ Core and Builtins
132132Library
133133-------
134134
135+ - Issue #16220: wsgiref now always calls close() on an iterable response.
136+ Patch by Brent Tubbs.
137+
135138- Issue #16270: urllib may hang when used for retrieving files via FTP by using
136139 a context manager. Patch by Giampaolo Rodola'.
137140
You can’t perform that action at this time.
0 commit comments