Werkzeug is the Swiss Army knife of Python web development.
It provides useful classes and functions for any WSGI application to make the life of a python web developer much easier. All of the provided classes are independed from each other so you can mix it with any other library.
Local objects cannot manage themselves. For that you need a local manager. You can pass a local manager multiple locals or add them later by appending them to manager.locals. Everytime the manager cleans up it, will clean up all the data left in the locals for this context.
Like make_middleware but for decorating functions.
@manager.middleware def application(environ, start_response): ...
The difference to make_middleware is that the function passed will have all the arguments copied from the inner application (name, docstring, module).
Acts as a proxy for a werkzeug local. Forwards all operations to a proxied object. The only operations not supported for forwarding are right handed operands and any kind of assignment.
from werkzeug import Local l = Local() request = l('request') user = l('user')
Whenever something is bound to l.user / l.request the proxy objects will forward all operations. If no object is bound a RuntimeError will be raised.
Keep in mind that repr() is also forwarded, so if you want to find out if you are dealing with a proxy you can do an isinstance() check:
>>> from werkzeug import LocalProxy >>> isinstance(request, LocalProxy) True
You can also create proxy objects by hand:
from werkzeug import Local, LocalProxy local = Local() request = LocalProxy(local, 'request')