[Python-checkins] cpython: Issue #18394: Explicitly close the file object cgi.FieldStorage

brett.cannon python-checkins at python.org
Fri Aug 23 21:16:00 CEST 2013


http://hg.python.org/cpython/rev/c0e9ba7b26d5
changeset:   85348:c0e9ba7b26d5
user:        Brett Cannon <brett at python.org>
date:        Fri Aug 23 15:15:48 2013 -0400
summary:
  Issue #18394: Explicitly close the file object cgi.FieldStorage
caches.

Eliminates the ResoureWarning raised during testing.

Patch also independently written by Vajrasky Kok.

files:
  Lib/cgi.py |  6 ++++++
  Misc/NEWS  |  2 ++
  2 files changed, 8 insertions(+), 0 deletions(-)


diff --git a/Lib/cgi.py b/Lib/cgi.py
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -552,6 +552,12 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,8 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list