From 859efe06de590f58899eb88dbfa81ef1b1f73c58 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 5 Apr 2007 22:38:44 +0200 Subject: [PATCH] [svn] added ugly, ugly, ugly even more ugly but working hack to jinja to patch the template sources into linecache in order to support broken traceback formatters which go unnamed. --HG-- branch : trunk --- CHANGES | 1 + jinja/utils.py | 48 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 77aee3f..1fb0393 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ Version 1.1 - blocks now support ``{{ super() }}`` to render the parent output. - debugging system improved, smaller filesize for the cached files. + Debugging works now well for any module using linecache. - added whitespace management system for the template designer. diff --git a/jinja/utils.py b/jinja/utils.py index cb21986..b3dce7b 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -274,13 +274,25 @@ def fake_template_exception(exception, filename, lineno, source, env = context_or_env namespace = {} + # generate an jinja unique filename used so that linecache + # gets data that doesn't interferes with other modules + if filename is None: + from random import randrange + vfilename = 'jinja://~%d' % randrange(0, 10000) + filename = '' + else: + vfilename = 'jinja://%s' % filename + offset = '\n' * (lineno - 1) code = compile(offset + 'raise __exception_to_raise__', - filename or '