Documented more changes
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 2 Apr 2009 12:04:41 +0000 (14:04 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 2 Apr 2009 12:04:41 +0000 (14:04 +0200)
--HG--
branch : trunk

jinja2/debug.py
jinja2/environment.py

index ce794e243b38e8ae558957c9e235eae2a7f48ade..ad7453e9581afb4250b586f29972174897ad5894 100644 (file)
@@ -65,6 +65,14 @@ class ProcessedTraceback(object):
                                            self.frames[0], limit=limit)
         return ''.join(lines).rstrip()
 
+    def render_as_html(self, full=False):
+        """Return a unicode string with the traceback as rendered HTML."""
+        from jinja2.debugrenderer import render_traceback
+        return u'%s\n\n<!--\n%s\n-->' % (
+            render_traceback(self, full=full),
+            self.render_as_text().decode('utf-8', 'replace')
+        )
+
     @property
     def is_template_syntax_error(self):
         """`True` if this is a template syntax error."""
index 803e7a8326fd3d6b904b22a800d01c4ed3bf5051..f163ab57671e75051e340c8b6bad017a046be2e1 100644 (file)
@@ -194,6 +194,7 @@ class Environment(object):
     #: must not be modified
     shared = False
 
+    #: these are currently EXPERIMENTAL undocumented features.
     exception_handler = None
     exception_formatter = None
 
@@ -475,13 +476,21 @@ class Environment(object):
         global _make_traceback
         if exc_info is None:
             exc_info = sys.exc_info()
+
+        # the debugging module is imported when it's used for the first time.
+        # we're doing a lot of stuff there and for applications that do not
+        # get any exceptions in template rendering there is no need to load
+        # all of that.
         if _make_traceback is None:
             from jinja2.debug import make_traceback as _make_traceback
+
         traceback = _make_traceback(exc_info, source_hint)
+
         if rendered and self.exception_formatter is not None:
             return self.exception_formatter(traceback)
         if self.exception_handler is not None:
             self.exception_handler(traceback)
+
         exc_type, exc_value, tb = traceback.standard_exc_info
         raise exc_type, exc_value, tb