[twill] Access to the WSGI environment with wsgi_intercept

Titus Brown titus at caltech.edu
Fri Jan 4 17:11:13 PST 2008

-> > For example, you may want to have multiple WSGI apps in play, in which
-> > case your global environ hack would cause problems.  (This is why
-> > _wsgi_intercept, which contains the apps, is the only global one.)
-> >
-> > And why not use middleware instead of a solid hook?  Something like
-> > this:
-> >
-> > --
-> > # install 'simple_app' with an environment printer under 'foo_name'
-> > app_fn = lambda: twill.wsgi.env_printer('foo_name', simple_app)
-> > twill.add_wsgi_intercept('localhost', 8001, lambda: app_fn)
-> > --
-> >
-> I was thinking that the global hack would only impact multiple
-> wsgi_intercept calls, which would be less of a problem.  I believe you when
-> you say it's more than that, though, and I agree that doing it as middleware
-> is less hackish.
-> I'll need to play around with it a bit though, because right now the double
-> lambdas around app_fn are over my head.   Should the middleware be added to
-> wsgi_intercept so that other potential users can use it?

You can replace the lambdas with a function that returns a WSGI
application object, suitably wrapped.

Ping me if you run into difficulties; it shouldn't take me very long to
whip something basic up.


More information about the twill mailing list