summaryrefslogtreecommitdiff
path: root/django/http/multipartparser.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/http/multipartparser.py')
-rw-r--r--django/http/multipartparser.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
index 20232cb7c6..1bcace94cd 100644
--- a/django/http/multipartparser.py
+++ b/django/http/multipartparser.py
@@ -228,6 +228,7 @@ class MultiPartParser(object):
break
except SkipFile:
+ self._close_files()
# Just use up the rest of this file...
exhaust(field_stream)
else:
@@ -237,6 +238,7 @@ class MultiPartParser(object):
# If this is neither a FIELD or a FILE, just exhaust the stream.
exhaust(stream)
except StopUpload as e:
+ self._close_files()
if not e.connection_reset:
exhaust(self._input_data)
else:
@@ -268,6 +270,14 @@ class MultiPartParser(object):
"""Cleanup filename from Internet Explorer full paths."""
return filename and filename[filename.rfind("\\") + 1:].strip()
+ def _close_files(self):
+ # Free up all file handles.
+ # FIXME: this currently assumes that upload handlers store the file as 'file'
+ # We should document that... (Maybe add handler.free_file to complement new_file)
+ for handler in self._upload_handlers:
+ if hasattr(handler, 'file'):
+ handler.file.close()
+
class LazyStream(six.Iterator):
"""