Final explicit closing for staticfiles, they now pass on python3 with -Wall and there are no warnings about unclosed files
This commit is contained in:
parent
2048bbee8c
commit
d674bd603e
|
@ -87,6 +87,7 @@ class CachedFilesMixin(object):
|
||||||
def hashed_name(self, name, content=None):
|
def hashed_name(self, name, content=None):
|
||||||
parsed_name = urlsplit(unquote(name))
|
parsed_name = urlsplit(unquote(name))
|
||||||
clean_name = parsed_name.path.strip()
|
clean_name = parsed_name.path.strip()
|
||||||
|
opened = False
|
||||||
if content is None:
|
if content is None:
|
||||||
if not self.exists(clean_name):
|
if not self.exists(clean_name):
|
||||||
raise ValueError("The file '%s' could not be found with %r." %
|
raise ValueError("The file '%s' could not be found with %r." %
|
||||||
|
@ -96,9 +97,14 @@ class CachedFilesMixin(object):
|
||||||
except IOError:
|
except IOError:
|
||||||
# Handle directory paths and fragments
|
# Handle directory paths and fragments
|
||||||
return name
|
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)
|
path, filename = os.path.split(clean_name)
|
||||||
root, ext = os.path.splitext(filename)
|
root, ext = os.path.splitext(filename)
|
||||||
file_hash = self.file_hash(clean_name, content)
|
|
||||||
if file_hash is not None:
|
if file_hash is not None:
|
||||||
file_hash = ".%s" % file_hash
|
file_hash = ".%s" % file_hash
|
||||||
hashed_name = os.path.join(path, "%s%s%s" %
|
hashed_name = os.path.join(path, "%s%s%s" %
|
||||||
|
|
Loading…
Reference in New Issue