forked from orbit-oss/flask
Made errors for working outside of contexts clearer.
This commit is contained in:
parent
5693b9d730
commit
1b77a3fb11
1 changed files with 20 additions and 3 deletions
|
|
@ -14,24 +14,41 @@ from functools import partial
|
||||||
from werkzeug.local import LocalStack, LocalProxy
|
from werkzeug.local import LocalStack, LocalProxy
|
||||||
|
|
||||||
|
|
||||||
|
_request_ctx_err_msg = '''\
|
||||||
|
Working outside of request context.
|
||||||
|
|
||||||
|
This typically means that you attempted to use functionality that needed
|
||||||
|
an active HTTP request. Consult the documentation on testing for
|
||||||
|
information about how to avoid this problem.\
|
||||||
|
'''
|
||||||
|
_app_ctx_err_msg = '''\
|
||||||
|
Working outside of application context.
|
||||||
|
|
||||||
|
This typically means that you attempted to use functionality that needed
|
||||||
|
to interface with the current application object in a way. To solve
|
||||||
|
this set up an application context with app.app_context(). See the
|
||||||
|
documentation for more information.\
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
def _lookup_req_object(name):
|
def _lookup_req_object(name):
|
||||||
top = _request_ctx_stack.top
|
top = _request_ctx_stack.top
|
||||||
if top is None:
|
if top is None:
|
||||||
raise RuntimeError('working outside of request context')
|
raise RuntimeError(_request_ctx_err_msg)
|
||||||
return getattr(top, name)
|
return getattr(top, name)
|
||||||
|
|
||||||
|
|
||||||
def _lookup_app_object(name):
|
def _lookup_app_object(name):
|
||||||
top = _app_ctx_stack.top
|
top = _app_ctx_stack.top
|
||||||
if top is None:
|
if top is None:
|
||||||
raise RuntimeError('working outside of application context')
|
raise RuntimeError(_app_ctx_err_msg)
|
||||||
return getattr(top, name)
|
return getattr(top, name)
|
||||||
|
|
||||||
|
|
||||||
def _find_app():
|
def _find_app():
|
||||||
top = _app_ctx_stack.top
|
top = _app_ctx_stack.top
|
||||||
if top is None:
|
if top is None:
|
||||||
raise RuntimeError('working outside of application context')
|
raise RuntimeError(_app_ctx_err_msg)
|
||||||
return top.app
|
return top.app
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue