Skip to content
Myr

[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.

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 1f1823c · Browse files · 2 files+42 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

2 files+42 added−7 removed

  • other:+42 added−7 removed

2 files+42 added−7 removed

modified:jinja/utils.py+41 added-7 removed
272 unmodified lines
273 else:274 env = context_or_env275 namespace = {}276277 # generate an jinja unique filename used so that linecache278 # gets data that doesn't interferes with other modules279 if filename is None:280 from random import randrange281 vfilename = 'jinja://~%d' % randrange(0, 10000)282 filename = '<string>'283 else:284 vfilename = 'jinja://%s' % filename285286 offset = '\n' * (lineno - 1)287 code = compile(offset + 'raise __exception_to_raise__',279 filename or '<template>', 'exec')288 vfilename or '<template>', 'exec')289290 loader = TracebackLoader(env, source, filename)291 loader.update_linecache(vfilename)292 globals = {281 '__name__': filename,282 '__file__': filename,283 '__loader__': TracebackLoader(env, source, filename),293 '__name__': vfilename,294 '__file__': vfilename,295 '__loader__': loader,296 '__exception_to_raise__': exception297 }298 try:299 exec code in globals, namespace
72 unmodified lines
372 self.loader = environment.loader373 self.source = source374 self.filename = filename375376 def update_linecache(self, virtual_filename):377 """378 Hacky way to let traceback systems know about the379 Jinja template sourcecode. Very hackish indeed.380 """381 # check for linecache, not every implementation of python382 # might have such an module.383 try:384 from linecache import cache385 except ImportError:386 return387 data = self.get_source(None)388 cache[virtual_filename] = (389 len(data),390 None,391 data.splitlines(True),392 virtual_filename393 )394395 def get_source(self, impname):396 source = ''397 if self.source is not None:366 return self.source398 source = self.source399 elif self.loader is not None:400 try:369 return self.loader.get_source(self.filename)401 source = self.loader.get_source(self.filename)402 except TemplateNotFound:403 pass372 return ''404 if isinstance(source, unicode):405 source = source.encode('utf-8')406 return source407408409class CacheDict(object):410 """
175 unmodified lines
modified:CHANGES+1 added
6 unmodified lines
78- blocks now support ``{{ super() }}`` to render the parent output.910- debugging system improved, smaller filesize for the cached files.11 Debugging works now well for any module using linecache.1213- added whitespace management system for the template designer.1415- some small bugfixes.
25 unmodified lines