Browse Source

DRY globals definition

pull/1486/head
Ignacio Carbajo 10 years ago
parent
commit
015d221d14
  1. 15
      flask/globals.py

15
flask/globals.py

@ -45,17 +45,14 @@ def _lookup_app_object(name):
return getattr(top, name) return getattr(top, name)
def _find_app(): def _proxy_attr(fn, name):
top = _app_ctx_stack.top return LocalProxy(partial(fn, name))
if top is None:
raise RuntimeError(_app_ctx_err_msg)
return top.app
# context locals # context locals
_request_ctx_stack = LocalStack() _request_ctx_stack = LocalStack()
_app_ctx_stack = LocalStack() _app_ctx_stack = LocalStack()
current_app = LocalProxy(_find_app) current_app = _proxy_attr(_lookup_app_object, 'app')
request = LocalProxy(partial(_lookup_req_object, 'request')) g = _proxy_attr(_lookup_app_object, 'g')
session = LocalProxy(partial(_lookup_req_object, 'session')) request = _proxy_attr(_lookup_req_object, 'request')
g = LocalProxy(partial(_lookup_app_object, 'g')) session = _proxy_attr(_lookup_req_object, 'session')

Loading…
Cancel
Save