# HG changeset patch # User Ludovic Chabant # Date 1408405845 25200 # Node ID 395eb38f2dfbeecfcc10eea6739da0bd0c14ceb7 # Parent a8f9c78a66080f0244d67f8fb1c5962b1a2218bc Properly escape HTML characters in the debug info, add more options. diff -r a8f9c78a6608 -r 395eb38f2dfb piecrust/data/debug.py --- a/piecrust/data/debug.py Mon Aug 18 16:50:20 2014 -0700 +++ b/piecrust/data/debug.py Mon Aug 18 16:50:45 2014 -0700 @@ -1,9 +1,9 @@ import re -import cgi +import io +import html import logging -import io +import collections from piecrust import APP_VERSION, PIECRUST_URL -import collections logger = logging.getLogger(__name__) @@ -179,7 +179,7 @@ if len(data) > DebugDataRenderer.MAX_VALUE_LENGTH: data = data[:DebugDataRenderer.MAX_VALUE_LENGTH - 5] data += '[...]' - data = cgi.escape(data).encode('ascii', 'xmlcharrefreplace') + data = html.escape(data) self._write('%s' % (CSS_VALUE, data)) return @@ -275,17 +275,28 @@ name_gen = getattr(data, ng) invoke_attrs += name_gen() + redirects = {} + if hasattr(data.__class__, 'debug_render_redirect'): + redirects = data.__class__.debug_render_redirect + rendered_count = 0 for name in attr_names: value = None render_name = name should_call = name in invoke_attrs + if name in redirects: + name = redirects[name] + + query_instance = False try: attr = getattr(data.__class__, name) except AttributeError: # This could be an attribute on the instance itself, or some # dynamic attribute. + query_instance = True + + if query_instance: attr = getattr(data, name) if isinstance(attr, collections.Callable):