Mercurial > hg > MakeItSo
comparison makeitso/factory.py @ 14:bf1ce840d0f0
make this a genshi view (should be: tempita view)
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Mon, 15 Nov 2010 08:05:55 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 13:99588f138993 | 14:bf1ce840d0f0 |
|---|---|
| 1 import os | |
| 2 | |
| 3 from dispatcher import Dispatcher | |
| 4 from paste.httpexceptions import HTTPExceptionHandler | |
| 5 from paste.urlparser import StaticURLParser | |
| 6 from pkg_resources import resource_filename | |
| 7 | |
| 8 class PassthroughFileserver(object): | |
| 9 """serve files if they exist""" | |
| 10 | |
| 11 def __init__(self, app, directory): | |
| 12 self.app = app | |
| 13 self.directory = directory | |
| 14 self.fileserver = StaticURLParser(self.directory) | |
| 15 | |
| 16 def __call__(self, environ, start_response): | |
| 17 path = environ['PATH_INFO'].strip('/') | |
| 18 if path and os.path.exists(os.path.join(self.directory, path)): | |
| 19 return self.fileserver(environ, start_response) | |
| 20 return self.app(environ, start_response) | |
| 21 | |
| 22 def factory(global_conf, **app_conf): | |
| 23 """create a webob view and wrap it in middleware""" | |
| 24 | |
| 25 keystr = 'MakeItSo/.' | |
| 26 args = dict([(key.split(keystr, 1)[-1], value) | |
| 27 for key, value in app_conf.items() | |
| 28 if key.startswith(keystr) ]) | |
| 29 app = Dispatcher(**args) | |
| 30 return HTTPExceptionHandler(PassthroughFileserver(app, resource_filename(__name__, 'static'))) | |
| 31 |
