From: Ben Darnell Date: Wed, 7 Dec 2011 08:36:33 +0000 (-0800) Subject: A different approach to template stack traces: X-Git-Tag: v2.2.0~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=597f70b31815f64ca382089b012d9eb0277e6cc1;p=thirdparty%2Ftornado.git A different approach to template stack traces: Include the template source line as a comment in the generated code, and add the magic necessary for python's normal stack traces to print the (generated) source. --- diff --git a/tornado/template.py b/tornado/template.py index fda7e5fdf..01927d60c 100644 --- a/tornado/template.py +++ b/tornado/template.py @@ -173,16 +173,15 @@ from __future__ import with_statement import cStringIO import datetime +import linecache import logging import os.path import posixpath import re import threading -import sys -import traceback from tornado import escape -from tornado.util import bytes_type +from tornado.util import bytes_type, ObjectDict _DEFAULT_AUTOESCAPE = "xhtml_escape" _UNSET = object() @@ -195,7 +194,6 @@ class Template(object): """ def __init__(self, template_string, name="", loader=None, compress_whitespace=None, autoescape=_UNSET): - self.template_string = template_string self.name = name if compress_whitespace is None: compress_whitespace = name.endswith(".html") or \ @@ -207,14 +205,17 @@ class Template(object): else: self.autoescape = _DEFAULT_AUTOESCAPE self.namespace = loader.namespace if loader else {} - reader = _TemplateReader(name, escape.native_str(self.template_string)) + reader = _TemplateReader(name, escape.native_str(template_string)) self.file = _File(self, _parse(reader, self)) - self.code, self.line_numbers = self._generate_python( - loader, compress_whitespace) + self.code = self._generate_python(loader, compress_whitespace) self.loader = loader try: - self.compiled = compile(escape.to_unicode(self.code), - "