Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f79126f

Browse files
committed
Issue #18394: Explicitly close the file object cgi.FieldStorage
caches. Eliminates the ResoureWarning raised during testing. Patch also independently written by Vajrasky Kok.
1 parent 9c7eb55 commit f79126f

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lib/cgi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ def __init__(self, fp=None, headers=None, outerboundary=b'',
552552
else:
553553
self.read_single()
554554

555+
def __del__(self):
556+
try:
557+
self.file.close()
558+
except AttributeError:
559+
pass
560+
555561
def __repr__(self):
556562
"""Return a printable representation."""
557563
return "FieldStorage(%r, %r, %r)" % (

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Core and Builtins
3838
Library
3939
-------
4040

41+
- Issue #18394: Close cgi.FieldStorage's optional file.
42+
4143
- Issue #17702: On error, os.environb now removes suppress the except context
4244
when raising a new KeyError with the original key.
4345

0 commit comments

Comments
 (0)