'Called after the actual request dispatching and will
call every as :meth:`teardown_request` decorated function.  This is
not actually called by the :class:`Flask` object itself but is always
triggered when the request context is popped.  That way we have a
tighter control over certain resources under testing environments.
.. versionchanged:: 0.9
Added the `exc` argument.  Previously this was always using the
current exception information.'

def do_teardown_request(self, exc=_sentinel):

    if (exc is _sentinel):
        exc = sys.exc_info()[1]
    funcs = reversed(self.teardown_request_funcs.get(None, ()))
    bp = _request_ctx_stack.top.request.blueprint
    if ((bp is not None) and (bp in self.teardown_request_funcs)):
        funcs = chain(funcs, reversed(self.teardown_request_funcs[bp]))
    for func in funcs:
        func(exc)
    request_tearing_down.send(self, exc=exc)
