This module implements thread-local utilities.
A container for thread-local objects.
Attributes are assigned or retrieved using the current thread.
Acts as a proxy for a local object.
Forwards all operations to a proxied object. The only operations not supported for forwarding are right handed operands and any kind of assignment.
Example usage:
from webapp2_extras import Local
l = Local()
# these are proxies
request = l('request')
user = l('user')
Whenever something is bound to l.user or l.request the proxy objects will forward all operations. If no object is bound a RuntimeError will be raised.
To create proxies to Local object, call the object as shown above. If you want to have a proxy to an object looked up by a function, you can pass a function to the LocalProxy constructor:
route_kwargs = LocalProxy(lambda: webapp2.get_request().route_kwargs)