summaryrefslogtreecommitdiff
path: root/bottle.py
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2022-06-29 09:36:25 +0200
committerMarcel Hellkamp <marc@gsites.de>2022-06-29 09:36:57 +0200
commit1677de087ee6517eb3f09a4cffe6f91758ef07ba (patch)
tree4f691a224378ff176e8d10e43dd5a1dba9b1b24a /bottle.py
parente14127d88a3b633ebc0a56f7ef48c3be5f9e899c (diff)
downloadbottle-1677de087ee6517eb3f09a4cffe6f91758ef07ba.tar.gz
Avoid "ResourceWarning: unclosed file"
Python implements __del__ for NamedTemporaryFile (with some additional tricks) to make sure these are closed (and unlinked) if they are no longer referenced. This avoids the ResourceWarning you'd normally get if an unclosed file is garbage-collected.
Diffstat (limited to 'bottle.py')
-rwxr-xr-xbottle.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/bottle.py b/bottle.py
index 6c852ab..1f78812 100755
--- a/bottle.py
+++ b/bottle.py
@@ -74,7 +74,7 @@ import base64, calendar, cgi, email.utils, functools, hmac, itertools,\
from types import FunctionType
from datetime import date as datedate, datetime, timedelta
-from tempfile import TemporaryFile
+from tempfile import NamedTemporaryFile
from traceback import format_exc, print_exc
from unicodedata import normalize
@@ -258,6 +258,7 @@ class lazy_attribute(object):
setattr(cls, self.__name__, value)
return value
+
###############################################################################
# Exceptions and Events #######################################################
###############################################################################
@@ -1355,7 +1356,7 @@ class BaseRequest(object):
body.write(part)
body_size += len(part)
if not is_temp_file and body_size > self.MEMFILE_MAX:
- body, tmp = TemporaryFile(mode='w+b'), body
+ body, tmp = NamedTemporaryFile(mode='w+b'), body
body.write(tmp.getvalue())
del tmp
is_temp_file = True