From: Armin Ronacher Date: Thu, 5 Apr 2007 20:38:44 +0000 (+0200) Subject: [svn] added ugly, ugly, ugly even more ugly but working hack to jinja to patch the... X-Git-Tag: 2.0rc1~371 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=859efe06de590f58899eb88dbfa81ef1b1f73c58;p=jinja2.git [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 --- 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 '