-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to flexible lightweight template system (#49)
* move to flexible lightweight template system * Typos
- Loading branch information
1 parent
4649a36
commit 340cd65
Showing
12 changed files
with
103 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
import tornado.web | ||
|
||
|
||
class MultiStaticFileHandler(tornado.web.StaticFileHandler): | ||
"""A static file handler that 'merges' a list of directories | ||
If initialized like this:: | ||
application = web.Application([ | ||
(r"/content/(.*)", web.MultiStaticFileHandler, {"paths": ["/var/1", "/var/2"]}), | ||
]) | ||
A file will be looked up in /var/1 first, then in /var/2. | ||
""" | ||
|
||
def initialize(self, paths, default_filename=None): | ||
self.roots = paths | ||
super(MultiStaticFileHandler, self).initialize(path=paths[0], default_filename=default_filename) | ||
|
||
def get_absolute_path(self, root, path): | ||
# find the first absolute path that exists | ||
self.root = self.roots[0] | ||
for root in self.roots: | ||
abspath = os.path.abspath(os.path.join(root, path)) | ||
if os.path.exists(abspath): | ||
self.root = root # make sure all the other methods in the base class know how to find the file | ||
break | ||
return abspath |