Skip to content
Myr

Preserve the request context in debug mode.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This makes it possible to access request information in the interactive debugger. Closes #8.

authored by Armin Ronacher · committed by Armin Ronacher · parent 40e0024 · Browse files · 1 file+11 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−7 removed

  • other:+11 added−7 removed

1 file+11 added−7 removed

modified:flask.py+11 added-7 removed
12 unmodified lines
13import os14import sys1516from threading import local17from contextlib import contextmanager17from jinja2 import Environment, PackageLoader, FileSystemLoader18from werkzeug import Request as RequestBase, Response as ResponseBase, \19 LocalStack, LocalProxy, create_environ, cached_property, \20 SharedDataMiddleware
61 unmodified lines
82 self.session = app.open_session(self.request)83 self.g = _RequestGlobals()84 self.flashes = None8586 def __enter__(self):87 _request_ctx_stack.push(self)8889 def __exit__(self, exc_type, exc_value, tb):90 # do not pop the request stack if we are in debug mode and an91 # exception happened. This will allow the debugger to still92 # access the request object in the interactive shell.93 if tb is None or not self.app.debug:94 _request_ctx_stack.pop()959697def url_for(endpoint, **values):98 """Generates a URL to the given endpoint with the method provided.99100 :param endpoint: the endpoint of the URL (name of the function)
525 unmodified lines
626 response = self.make_response(rv)627 response = self.process_response(response)628 return response(environ, start_response)629621 @contextmanager630 def request_context(self, environ):631 """Creates a request context from the given environment and binds632 it to the current context. This must be used in combination with633 the `with` statement because the request is only bound to the
5 unmodified lines
639 do_something_with(request)640641 :params environ: a WSGI environment642 """635 _request_ctx_stack.push(_RequestContext(self, environ))636 try:637 yield638 finally:639 _request_ctx_stack.pop()643 return _RequestContext(self, environ)644645 def test_request_context(self, *args, **kwargs):646 """Creates a WSGI environment from the given values (see647 :func:`werkzeug.create_environ` for more information, this
15 unmodified lines