mongodol.utils.werk_local#
Vendored from werkzeug’s local.py module, edited to our needs. That single need is have a LocalProxy to subclass in making TrackedObj (see tracking_methods.py).
Classes
|
A proxy to the object bound to a |
- class mongodol.utils.werk_local.LocalProxy(local, name=None)[source]#
Bases:
objectA proxy to the object bound to a
Local. All operations on the proxy are forwarded to the bound object. If no object is bound, aRuntimeErroris raised.from werkzeug.local import Local l = Local() # a proxy to whatever l.user is set to user = l("user") from werkzeug.local import LocalStack _request_stack = LocalStack() # a proxy to _request_stack.top request = _request_stack() # a proxy to the session attribute of the request proxy session = LocalProxy(lambda: request.session)
__repr__and__class__are forwarded, sorepr(x)andisinstance(x, cls)will look like the proxied object. Useissubclass(type(x), LocalProxy)to check if an object is a proxy.repr(user) # <User admin> isinstance(user, User) # True issubclass(type(user), LocalProxy) # True
- Parameters:
Changed in version 2.0: Updated proxied attributes and methods to reflect the current data model.
Changed in version 0.6.1: The class can be instantiated with a callable.