]> granicus.if.org Git - python/commitdiff
Issue #18394: Explicitly close the file object cgi.FieldStorage
authorBrett Cannon <brett@python.org>
Fri, 23 Aug 2013 19:15:48 +0000 (15:15 -0400)
committerBrett Cannon <brett@python.org>
Fri, 23 Aug 2013 19:15:48 +0000 (15:15 -0400)
caches.

Eliminates the ResoureWarning raised during testing.

Patch also independently written by Vajrasky Kok.

Lib/cgi.py
Misc/NEWS

index 4de82ea6df90fbb2d200b8f5e8e723ab4242dd49..b6fd4074546dbbd83c9a6302a903b223b815e87c 100755 (executable)
@@ -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)" % (
index 431674abbd5366e7d071a8232750cd488b9e7b47..125d604697cf4ae1df264bdbfd78a2eb3dc92bdc 100644 (file)
--- 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.