0
|
1 import os
|
|
2
|
|
3 from dispatcher import Dispatcher
|
3
|
4 from dispatcher import Scrambler
|
0
|
5 from paste.httpexceptions import HTTPExceptionHandler
|
|
6 from paste.urlparser import StaticURLParser
|
|
7 from pkg_resources import resource_filename
|
|
8
|
|
9 class PassthroughFileserver(object):
|
|
10 """serve files if they exist"""
|
|
11
|
|
12 def __init__(self, app, directory):
|
|
13 self.app = app
|
|
14 self.directory = directory
|
|
15 self.fileserver = StaticURLParser(self.directory)
|
|
16
|
|
17 def __call__(self, environ, start_response):
|
|
18 path = environ['PATH_INFO'].strip('/')
|
|
19 if path and os.path.exists(os.path.join(self.directory, path)):
|
|
20 return self.fileserver(environ, start_response)
|
|
21 return self.app(environ, start_response)
|
|
22
|
|
23 def factory(global_conf, **app_conf):
|
|
24 """create a webob view and wrap it in middleware"""
|
|
25
|
|
26 keystr = 'wordstream.'
|
|
27 args = dict([(key.split(keystr, 1)[-1], value)
|
|
28 for key, value in app_conf.items()
|
|
29 if key.startswith(keystr) ])
|
|
30 app = Dispatcher(**args)
|
|
31 return HTTPExceptionHandler(PassthroughFileserver(app, resource_filename(__name__, 'static')))
|
|
32
|
3
|
33 def dissociate_factory(global_conf, **app_conf):
|
|
34 keystr = 'dissociate.'
|
|
35 args = dict([(key.split(keystr, 1)[-1], value)
|
|
36 for key, value in app_conf.items()
|
|
37 if key.startswith(keystr) ])
|
|
38 app = Scrambler(**args)
|
|
39 return HTTPExceptionHandler(app)
|
|
40 |