|
|
|
@ -181,11 +181,13 @@ class AppContext(object):
|
|
|
|
|
|
|
|
|
|
def pop(self, exc=_sentinel): |
|
|
|
|
"""Pops the app context.""" |
|
|
|
|
try: |
|
|
|
|
self._refcnt -= 1 |
|
|
|
|
if self._refcnt <= 0: |
|
|
|
|
if exc is _sentinel: |
|
|
|
|
exc = sys.exc_info()[1] |
|
|
|
|
self.app.do_teardown_appcontext(exc) |
|
|
|
|
finally: |
|
|
|
|
rv = _app_ctx_stack.pop() |
|
|
|
|
assert rv is self, 'Popped wrong app context. (%r instead of %r)' \ |
|
|
|
|
% (rv, self) |
|
|
|
@ -341,6 +343,7 @@ class RequestContext(object):
|
|
|
|
|
""" |
|
|
|
|
app_ctx = self._implicit_app_ctx_stack.pop() |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
clear_request = False |
|
|
|
|
if not self._implicit_app_ctx_stack: |
|
|
|
|
self.preserved = False |
|
|
|
@ -360,10 +363,8 @@ class RequestContext(object):
|
|
|
|
|
if request_close is not None: |
|
|
|
|
request_close() |
|
|
|
|
clear_request = True |
|
|
|
|
|
|
|
|
|
finally: |
|
|
|
|
rv = _request_ctx_stack.pop() |
|
|
|
|
assert rv is self, 'Popped wrong request context. (%r instead of %r)' \ |
|
|
|
|
% (rv, self) |
|
|
|
|
|
|
|
|
|
# get rid of circular dependencies at the end of the request |
|
|
|
|
# so that we don't require the GC to be active. |
|
|
|
@ -374,6 +375,9 @@ class RequestContext(object):
|
|
|
|
|
if app_ctx is not None: |
|
|
|
|
app_ctx.pop(exc) |
|
|
|
|
|
|
|
|
|
assert rv is self, 'Popped wrong request context. ' \ |
|
|
|
|
'(%r instead of %r)' % (rv, self) |
|
|
|
|
|
|
|
|
|
def auto_pop(self, exc): |
|
|
|
|
if self.request.environ.get('flask._preserve_context') or \ |
|
|
|
|
(exc is not None and self.app.preserve_context_on_exception): |
|
|
|
|