Skip to content

Commit

Permalink
Use absolute paths in RequestHandler._static_hashes to allow for diff…
Browse files Browse the repository at this point in the history
…erent

static_paths.
  • Loading branch information
bdarnell committed Jan 3, 2011
1 parent adafcc0 commit daf9669
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tornado/web.py
Expand Up @@ -763,20 +763,21 @@ def static_url(self, path):
if not hasattr(RequestHandler, "_static_hashes"):
RequestHandler._static_hashes = {}
hashes = RequestHandler._static_hashes
if path not in hashes:
abs_path = os.path.join(self.application.settings["static_path"],
path)
if abs_path not in hashes:
try:
f = open(os.path.join(
self.application.settings["static_path"], path))
hashes[path] = hashlib.md5(f.read()).hexdigest()
f = open(abs_path)
hashes[abs_path] = hashlib.md5(f.read()).hexdigest()
f.close()
except:
logging.error("Could not open static file %r", path)
hashes[path] = None
hashes[abs_path] = None
base = self.request.protocol + "://" + self.request.host \
if getattr(self, "include_host", False) else ""
static_url_prefix = self.settings.get('static_url_prefix', '/static/')
if hashes.get(path):
return base + static_url_prefix + path + "?v=" + hashes[path][:5]
if hashes.get(abs_path):
return base + static_url_prefix + path + "?v=" + hashes[abs_path][:5]
else:
return base + static_url_prefix + path

Expand Down

0 comments on commit daf9669

Please sign in to comment.