Mercurial > hg > simpypi
view simpypi/factory.py @ 2:b03602153de2
removing more cruft
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 27 Feb 2012 16:05:34 -0800 |
parents | 24b8d06eae53 |
children | f5360bb59e41 |
line wrap: on
line source
import os from dispatcher import Dispatcher from paste.httpexceptions import HTTPExceptionHandler from paste.urlparser import StaticURLParser from pkg_resources import resource_filename class PassthroughFileserver(object): """serve files if they exist""" def __init__(self, app, directory): self.app = app self.directory = directory self.fileserver = StaticURLParser(self.directory) def __call__(self, environ, start_response): path = environ['PATH_INFO'].strip('/') if path and os.path.exists(os.path.join(self.directory, path)): return self.fileserver(environ, start_response) return self.app(environ, start_response) def factory(**app_conf): """create a webob view and wrap it in middleware""" app = Dispatcher(**app_conf) return HTTPExceptionHandler(PassthroughFileserver(app, resource_filename(__name__, 'static'))) if __name__ == '__main__': import shutil import tempfile from wsgiref import simple_server tempdir = tempfile.mkdtemp() try: app = factory finally: shutil.rmtree(tempdir)