summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2012-08-15 01:29:05 -0700
committerAlex Gaynor <alex.gaynor@rd.io>2012-08-15 01:29:05 -0700
commitd674bd603ee39721a6b22d8e28a16f46502dff35 (patch)
treedf8a37a9b2f9b1b0e21fa5c6a1f9343fa0e6771f
parent2048bbee8c17495d5156d40073715cb9d7511c5a (diff)
Final explicit closing for staticfiles, they now pass on python3 with -Wall and there are no warnings about unclosed files
-rw-r--r--django/contrib/staticfiles/storage.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 1c841e9889..4be7540c6e 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -87,6 +87,7 @@ class CachedFilesMixin(object):
def hashed_name(self, name, content=None):
parsed_name = urlsplit(unquote(name))
clean_name = parsed_name.path.strip()
+ opened = False
if content is None:
if not self.exists(clean_name):
raise ValueError("The file '%s' could not be found with %r." %
@@ -96,9 +97,14 @@ class CachedFilesMixin(object):
except IOError:
# Handle directory paths and fragments
return name
+ opened = True
+ try:
+ file_hash = self.file_hash(clean_name, content)
+ finally:
+ if opened:
+ content.close()
path, filename = os.path.split(clean_name)
root, ext = os.path.splitext(filename)
- file_hash = self.file_hash(clean_name, content)
if file_hash is not None:
file_hash = ".%s" % file_hash
hashed_name = os.path.join(path, "%s%s%s" %