From bb960d4b6c92a2d8922bfd5f8c350e99d378692e Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 12 Mar 2007 21:46:21 +0100 Subject: [PATCH] [svn] readded debug function --HG-- branch : trunk --- jinja/defaults.py | 4 +++- jinja/translators/python.py | 1 - jinja/utils.py | 10 ++++++++++ tests/exception.py | 2 +- tests/templates/error.html | 3 ++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/jinja/defaults.py b/jinja/defaults.py index 3abf938..ddcc82b 100644 --- a/jinja/defaults.py +++ b/jinja/defaults.py @@ -10,8 +10,10 @@ """ from jinja.filters import FILTERS as DEFAULT_FILTERS from jinja.tests import TESTS as DEFAULT_TESTS +from jinja.utils import debug_context DEFAULT_NAMESPACE = { - 'range': range + 'range': range, + 'debug': debug_context } diff --git a/jinja/translators/python.py b/jinja/translators/python.py index db78843..a71a4f5 100644 --- a/jinja/translators/python.py +++ b/jinja/translators/python.py @@ -302,7 +302,6 @@ class PythonTranslator(Translator): # the template body body_lines = [self.handle_node(n) for n in node] - print list(node) # add translation helpers if required if self.require_translations: diff --git a/jinja/utils.py b/jinja/utils.py index 832cfdb..311d905 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -56,6 +56,16 @@ def find_translations(environment, source): queue.extend(node.getChildNodes()) +def debug_context(): + """ + Use this function in templates to get a printed context. + Use this only in templates because it touches the stack. + """ + context = sys._getframe(2).f_locals['context'] + from pprint import pformat + return pformat(context.to_dict()) + + # python2.4 and lower has a bug regarding joining of broken generators if sys.hexversion < (2, 5): def capture_generator(gen): diff --git a/tests/exception.py b/tests/exception.py index 61a298d..fdcc7e1 100644 --- a/tests/exception.py +++ b/tests/exception.py @@ -7,4 +7,4 @@ def test(*args): tmpl = e.loader.load('error.html') tmpl.render(items=range(10)) -make_server("localhost", 7000, DebuggedApplication(test)).serve_forever() +make_server("localhost", 7000, DebuggedApplication(test, False)).serve_forever() diff --git a/tests/templates/error.html b/tests/templates/error.html index 2958d56..ef11dfb 100644 --- a/tests/templates/error.html +++ b/tests/templates/error.html @@ -1,5 +1,6 @@ -- 2.26.2