Skip to content
Myr

[svn] fixed weird python2.4 debugging problem

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 7977e5c · Browse files · 2 files+26 added−8 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+26 added−8 removed

  • other:+26 added−8 removed

2 files+26 added−8 removed

modified:jinja/translators/python.py+7 added-5 removed
13 unmodified lines
14from jinja.nodes import get_nodes15from jinja.parser import Parser16from jinja.exceptions import TemplateSyntaxError17from jinja.translators import Translator18from jinja.utils import translate_exception18from jinja.utils import translate_exception, capture_generator192021def _to_tuple(args):22 """
48 unmodified lines
71 exec self.code in ns72 self.generate_func = ns['generate']73 ctx = self.environment.context_class(self.environment, *args, **kwargs)74 try:75 return u''.join(self.generate_func(ctx))75 return capture_generator(self.generate_func(ctx))76 except:77 exc_type, exc_value, traceback = sys.exc_info()78 traceback = translate_exception(self, exc_type,79 exc_value, traceback.tb_next,80 ctx)78 # translate the exception, We skip two frames. One79 # frame that is the "capture_generator" frame, and another80 # one which is the frame of this function81 traceback = translate_exception(self, exc_type, exc_value,82 traceback.tb_next.tb_next, ctx)83 raise exc_type, exc_value, traceback848586class PythonTranslator(Translator):
775 unmodified lines
modified:jinja/utils.py+19 added-3 removed
54 unmodified lines
55 yield node.lineno, node.singular, node.plural56 queue.extend(node.getChildNodes())575859# python2.4 and lower has a bug regarding joining of broken generators60if sys.hexversion < (2, 5):61 def capture_generator(gen):62 """63 Concatenate the generator output.64 """65 return u''.join(tuple(gen))6667# this should be faster and used in python2.5 and higher68else:69 def capture_generator(gen):70 """71 Concatenate the generator output72 """73 return u''.join(gen)747576def buffereater(f):77 """78 Used by the python translator to capture output of substreams.79 (macros, filter sections etc)80 """81 def wrapped(*args, **kwargs):65 return u''.join(f(*args, **kwargs))82 return capture_generator(f(*args, **kwargs))83 return wrapped848586def raise_template_exception(template, exception, filename, lineno, context):87 """88 Raise an exception "in a template". Return a traceback89 object.90 """74 offset = '\n'.join([''] * lineno)91 offset = '\n' * (lineno - 1)92 code = compile(offset + 'raise __exception_to_raise__', filename, 'exec')93 namespace = context.to_dict()94 globals = {95 '__name__': filename,
17 unmodified lines
113 args = None114 # looks like we loaded the template from string. we cannot115 # do anything here.116 if startpos > len(sourcelines):100 print startpos, len(sourcelines)117 return traceback118119 while startpos > 0:120 m = _debug_info_re.search(sourcelines[startpos])
146 unmodified lines