0
|
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 = 'SimpleWiki.'
|
|
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
|