Implemented a separate application context.

This commit is contained in:
Armin Ronacher 2012-04-09 14:34:12 +01:00
parent a1305973bf
commit 47288231fe
3 changed files with 78 additions and 3 deletions

View file

@ -20,9 +20,17 @@ def _lookup_object(name):
return getattr(top, name)
def _find_app():
top = _app_ctx_stack.top
if top is None:
raise RuntimeError('working outside of application context')
return top.app
# context locals
_request_ctx_stack = LocalStack()
current_app = LocalProxy(partial(_lookup_object, 'app'))
_app_ctx_stack = LocalStack()
current_app = LocalProxy(_find_app)
request = LocalProxy(partial(_lookup_object, 'request'))
session = LocalProxy(partial(_lookup_object, 'session'))
g = LocalProxy(partial(_lookup_object, 'g'))