Mercurial > hg > discussions
comparison discusssions/factory.py @ 0:c904249afb04
initial commit of discussions
author | k0s <k0scist@gmail.com> |
---|---|
date | Sat, 02 Jan 2010 13:36:23 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c904249afb04 |
---|---|
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 = 'discusssions.' | |
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 |