[Python-checkins] cpython: Issue #18394: Document that cgi.FieldStorage now cleans up after its

brett.cannon python-checkins at python.org
Fri Jan 17 17:03:28 CET 2014


http://hg.python.org/cpython/rev/13d04a8713ad
changeset: 88522:13d04a8713ad
user: Brett Cannon <brett at python.org>
date: Fri Jan 17 11:03:19 2014 -0500
summary:
 Issue #18394: Document that cgi.FieldStorage now cleans up after its
'file' attribute properly in Python 3.4.
Thanks to Marcel Hellkamp for pointing out the oversight.
files:
 Doc/library/cgi.rst | 13 ++++++++++---
 Doc/whatsnew/3.4.rst | 7 +++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/Doc/library/cgi.rst b/Doc/library/cgi.rst
--- a/Doc/library/cgi.rst
+++ b/Doc/library/cgi.rst
@@ -142,9 +142,11 @@
 method reads the entire file in memory as bytes. This may not be what you
 want. You can test for an uploaded file by testing either the
 :attr:`~FieldStorage.filename` attribute or the :attr:`~FieldStorage.file`
-attribute. You can then read the data at leisure from the :attr:`!file`
-attribute (the :func:`~io.RawIOBase.read` and :func:`~io.IOBase.readline`
-methods will return bytes)::
+attribute. You can then read the data from the :attr:`!file`
+attribute before it is automatically closed as part of the garbage collection of
+the :class:`FieldStorage` instance
+(the :func:`~io.RawIOBase.read` and :func:`~io.IOBase.readline` methods will
+return bytes)::
 
 fileitem = form["userfile"]
 if fileitem.file:
@@ -176,6 +178,11 @@
 A form submitted via POST that also has a query string will contain both
 :class:`FieldStorage` and :class:`MiniFieldStorage` items.
 
+.. versionchanged:: 3.4
+ The :attr:`~FieldStorage.file` attribute is automatically closed upon the
+ garbage collection of the creating :class:`FieldStorage` instance.
+
+
 Higher Level Interface
 ----------------------
 
diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst
--- a/Doc/whatsnew/3.4.rst
+++ b/Doc/whatsnew/3.4.rst
@@ -1560,6 +1560,13 @@
 :issue:`18011`.) Note: this change was also inadvertently applied in Python
 3.3.3.
 
+* The :attr:`~cgi.FieldStorage.file` attribute is now automatically closed when
+ the creating :class:`cgi.FieldStorage` instance is garbage collected. If you
+ were pulling the file object out separately from the :class:`cgi.FieldStorage`
+ instance and not keeping the instance alive, then you should either store the
+ entire :class:`cgi.FieldStorage` instance or read the contents of the file
+ before the :class:`cgi.FieldStorage` instance is garbage collected.
+
 
 Changes in the C API
 --------------------
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /