Mercurial > piecrust2
comparison piecrust/data/debug.py @ 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 | 343d08ef5668 |
children | 0445a2232de7 |
comparison
equal
deleted
inserted
replaced
13:a8f9c78a6608 | 14:395eb38f2dfb |
---|---|
1 import re | 1 import re |
2 import cgi | 2 import io |
3 import html | |
3 import logging | 4 import logging |
4 import io | 5 import collections |
5 from piecrust import APP_VERSION, PIECRUST_URL | 6 from piecrust import APP_VERSION, PIECRUST_URL |
6 import collections | |
7 | 7 |
8 | 8 |
9 logger = logging.getLogger(__name__) | 9 logger = logging.getLogger(__name__) |
10 | 10 |
11 | 11 |
177 | 177 |
178 if data_type is str: | 178 if data_type is str: |
179 if len(data) > DebugDataRenderer.MAX_VALUE_LENGTH: | 179 if len(data) > DebugDataRenderer.MAX_VALUE_LENGTH: |
180 data = data[:DebugDataRenderer.MAX_VALUE_LENGTH - 5] | 180 data = data[:DebugDataRenderer.MAX_VALUE_LENGTH - 5] |
181 data += '[...]' | 181 data += '[...]' |
182 data = cgi.escape(data).encode('ascii', 'xmlcharrefreplace') | 182 data = html.escape(data) |
183 self._write('<span style="%s">%s</span>' % (CSS_VALUE, data)) | 183 self._write('<span style="%s">%s</span>' % (CSS_VALUE, data)) |
184 return | 184 return |
185 | 185 |
186 self._renderCollapsableValueStart(path) | 186 self._renderCollapsableValueStart(path) |
187 with IndentScope(self): | 187 with IndentScope(self): |
273 drid = data.__class__.debug_render_invoke_dynamic | 273 drid = data.__class__.debug_render_invoke_dynamic |
274 for ng in drid: | 274 for ng in drid: |
275 name_gen = getattr(data, ng) | 275 name_gen = getattr(data, ng) |
276 invoke_attrs += name_gen() | 276 invoke_attrs += name_gen() |
277 | 277 |
278 redirects = {} | |
279 if hasattr(data.__class__, 'debug_render_redirect'): | |
280 redirects = data.__class__.debug_render_redirect | |
281 | |
278 rendered_count = 0 | 282 rendered_count = 0 |
279 for name in attr_names: | 283 for name in attr_names: |
280 value = None | 284 value = None |
281 render_name = name | 285 render_name = name |
282 should_call = name in invoke_attrs | 286 should_call = name in invoke_attrs |
283 | 287 |
288 if name in redirects: | |
289 name = redirects[name] | |
290 | |
291 query_instance = False | |
284 try: | 292 try: |
285 attr = getattr(data.__class__, name) | 293 attr = getattr(data.__class__, name) |
286 except AttributeError: | 294 except AttributeError: |
287 # This could be an attribute on the instance itself, or some | 295 # This could be an attribute on the instance itself, or some |
288 # dynamic attribute. | 296 # dynamic attribute. |
297 query_instance = True | |
298 | |
299 if query_instance: | |
289 attr = getattr(data, name) | 300 attr = getattr(data, name) |
290 | 301 |
291 if isinstance(attr, collections.Callable): | 302 if isinstance(attr, collections.Callable): |
292 attr_func = getattr(data, name) | 303 attr_func = getattr(data, name) |
293 argcount = attr_func.__code__.co_argcount | 304 argcount = attr_func.__code__.co_argcount |