From 10425e109b4160e309fa8f32eabd13576b3ab5c7 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 28 Mar 2023 19:56:45 +0100 Subject: Use a list of middlewares instead of decorators --- paste/__init__.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/paste/__init__.py b/paste/__init__.py index 6e93923..c54791b 100644 --- a/paste/__init__.py +++ b/paste/__init__.py @@ -169,13 +169,7 @@ def authenticate(get_auth: Callable[[Env], Auth]) -> Middleware: return authenticate -@catch_exceptions -@validate_method -@options -@if_none_match -@open_database -@authenticate(lambda environ: Auth(environ["paste.db_conn"])) -def application(environ: Env, start_response: StartResponse) -> Response: +def application(environ: Env, start_response: StartResponse, /) -> Response: store = Store(environ["paste.db_conn"]) name = environ["PATH_INFO"] if environ["REQUEST_METHOD"] == "GET": @@ -243,3 +237,16 @@ def application(environ: Env, start_response: StartResponse) -> Response: return [] return simple_response(start_response, "404 Not Found") return simple_response(start_response, "500 Internal Server Error") + + +middlewares = [ + catch_exceptions, + validate_method, + options, + if_none_match, + open_database, + authenticate(lambda environ: Auth(environ["paste.db_conn"])), +] + +for m in reversed(middlewares): + application = m(application) -- cgit v1.2.3-54-g00ecf