On Sun, Sep 19, 2010 at 11:32 AM, Chris McDonough <[email protected]> wrote:
> > I propose to write in the PEP that a middleware should provide an
> > "app" attribute to get the wrapped application or middleware.
> > It seems to be the most common name used out there.
>
> We can't really mandate this because middleware is not required to be an
> instance. It can be a function.
>
We could suggest it, and suggest the attribute name. Composites, lazy
loading middleware, or a bunch of other situations can break it... but it's
nice for introspection tools to at least be able to attempt to run down the
chain. Middleware is almost always a closure if it's a function, I believe,
so you could still do:
def caps(app):
def replacement_app(environ):
status, headers, body = app(environ)
body = [''.join(body).upper()]
return status, headers, body
replacement_app.app = app
return replacement_app
--
Ian Bicking | http://blog.ianbicking.org
_______________________________________________
Web-SIG mailing list
[email protected]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe:
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com