replace nested middleware calls with reduce and partials

This commit is contained in:
Martin Zimmermann 2013-11-25 13:38:51 +01:00
parent c9c0df229a
commit 6405f258f3

View File

@ -46,6 +46,7 @@ import tempfile
from os.path import dirname, join
from argparse import ArgumentParser
from functools import partial, reduce
from itsdangerous import URLSafeTimedSerializer
@ -56,6 +57,7 @@ from werkzeug.wsgi import SharedDataMiddleware
from werkzeug.local import Local, LocalManager
from werkzeug.serving import run_simple
from werkzeug.contrib.fixers import ProxyFix
from werkzeug.contrib.profiler import ProfilerMiddleware
local = Local()
local_manager = LocalManager([local])
@ -158,23 +160,22 @@ def make_app(conf=None):
else:
logger.warn("unable to connect to HTTP server")
wrapper = [local_manager.make_middleware]
if isso.conf.getboolean("server", "profile"):
from werkzeug.contrib.profiler import ProfilerMiddleware as Profiler
ProfilerMiddleware = lambda app: Profiler(app, sort_by=("cumtime", ), restrictions=("isso/(?!lib)", 10))
else:
ProfilerMiddleware = lambda app: app
wrapper.append(partial(ProfilerMiddleware,
sort_by=("cumtime", ), restrictions=("isso/(?!lib)", 10)))
app = ProxyFix(
wsgi.SubURI(
wsgi.CORSMiddleware(
SharedDataMiddleware(
ProfilerMiddleware(
local_manager.make_middleware(isso)), {
'/js': join(dirname(__file__), 'js/'),
'/css': join(dirname(__file__), 'css/')}),
origin(isso.conf.getiter("general", "host")))))
wrapper.append(partial(SharedDataMiddleware, exports={
'/js': join(dirname(__file__), 'js/'),
'/css': join(dirname(__file__), 'css/')}))
return app
wrapper.append(partial(wsgi.CORSMiddleware,
origin=origin(isso.conf.getiter("general", "host"))))
wrapper.extend([wsgi.SubURI, ProxyFix])
return reduce(lambda x, f: f(x), wrapper, isso)
def main():