On Sun, Sep 19, 2010 at 11:32 AM, Chris McDonough <span dir="ltr">&lt;<a href="mailto:chrism@plope.com">chrism@plope.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">&gt; I propose to write in the PEP that a middleware should provide an<br>
&gt; &quot;app&quot; attribute to get the wrapped application or middleware.<br>
&gt; It seems to be the most common name used out there.<br>
<br>
</div>We can&#39;t really mandate this because middleware is not required to be an<br>
instance.  It can be a function.<br></blockquote><div><br>We could suggest it, and suggest the attribute name.  Composites, lazy loading middleware, or a bunch of other situations can break it... but it&#39;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&#39;s a function, I believe, so you could still do:<br>

<br>def caps(app):<br>    def replacement_app(environ):<br>        status, headers, body = app(environ)<br>        body = [&#39;&#39;.join(body).upper()]<br>        return status, headers, body<br>    replacement_app.app = app<br>

    return replacement_app<br><br></div></div>-- <br>Ian Bicking  |  <a href="http://blog.ianbicking.org">http://blog.ianbicking.org</a><br>