Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Final explicit closing for staticfiles, they now pass on python3 with…

… -Wall and there are no warnings about unclosed files
  • Loading branch information...
commit d674bd603ee39721a6b22d8e28a16f46502dff35 1 parent 2048bbe
@alex alex authored Alex Gaynor committed
Showing with 7 additions and 1 deletion.
  1. +7 −1 django/contrib/staticfiles/storage.py
View
8 django/contrib/staticfiles/storage.py
@@ -87,6 +87,7 @@ def file_hash(self, name, content=None):
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 @@ def hashed_name(self, name, content=None):
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" %
Please sign in to comment.
Something went wrong with that request. Please try again.