[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
Provenance
- Commit
fc214cc- Tree
abbb381- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
7977e5c
2 files changed+26 added−8 removed
modified:jinja/translators/python.py+7 added-5 removed
13 unmodified lines14 from jinja.nodes import get_nodes15 from jinja.parser import Parser16 from jinja.exceptions import TemplateSyntaxError17 from jinja.translators import Translator18-from jinja.utils import translate_exception18+from jinja.utils import translate_exception, capture_generator19 20 21 def _to_tuple(args):22 """48 unmodified lines71 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, traceback84 85 86 class PythonTranslator(Translator):775 unmodified linesmodified:jinja/utils.py+19 added-3 removed
54 unmodified lines55 yield node.lineno, node.singular, node.plural56 queue.extend(node.getChildNodes())57 58 59+# python2.4 and lower has a bug regarding joining of broken generators60+if sys.hexversion < (2, 5):61+ def capture_generator(gen):62+ """63+ Concatenate the generator output.64+ """65+ return u''.join(tuple(gen))66+67+# this should be faster and used in python2.5 and higher68+else:69+ def capture_generator(gen):70+ """71+ Concatenate the generator output72+ """73+ return u''.join(gen)74+75+76 def 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 wrapped84 85 86 def 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 lines113 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 traceback118 119 while startpos > 0:120 m = _debug_info_re.search(sourcelines[startpos])146 unmodified lines