From: Brett Cannon Date: Fri, 23 Aug 2013 19:15:48 +0000 (-0400) Subject: Issue #18394: Explicitly close the file object cgi.FieldStorage X-Git-Tag: v3.4.0a2~138 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f79126f373a9d5c9b584a8db736fe490fcbfa77a;p=python Issue #18394: Explicitly close the file object cgi.FieldStorage caches. Eliminates the ResoureWarning raised during testing. Patch also independently written by Vajrasky Kok. --- diff --git a/Lib/cgi.py b/Lib/cgi.py index 4de82ea6df..b6fd407454 100755 --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -552,6 +552,12 @@ class FieldStorage: else: self.read_single() + def __del__(self): + try: + self.file.close() + except AttributeError: + pass + def __repr__(self): """Return a printable representation.""" return "FieldStorage(%r, %r, %r)" % ( diff --git a/Misc/NEWS b/Misc/NEWS index 431674abbd..125d604697 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -38,6 +38,8 @@ Core and Builtins Library ------- +- Issue #18394: Close cgi.FieldStorage's optional file. + - Issue #17702: On error, os.environb now removes suppress the except context when raising a new KeyError with the original key.