Mercurial > piecrust2
changeset 14:395eb38f2dfb
Properly escape HTML characters in the debug info, add more options.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 18 Aug 2014 16:50:45 -0700 |
parents | a8f9c78a6608 |
children | dc8a6ff88f37 |
files | piecrust/data/debug.py |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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('<span style="%s">%s</span>' % (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):