[Web-SIG] PEP 444 (aka Web3)

Ian Bicking ianb at colorstudy.com
Mon Sep 20 00:41:51 CEST 2010


On Sun, Sep 19, 2010 at 11:32 AM, Chris McDonough <chrism at plope.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/web-sig/attachments/20100919/5c837903/attachment.html>


More information about the Web-SIG mailing list