def render_summary(self, include_title=True): """Render the traceback for the interactive console.""" title = '' description = '' frames = [] classes = ['traceback'] if not self.frames: classes.append('noframe-traceback') if include_title: if self.is_syntax_error: title = text_('Syntax Error') else: title = text_('Traceback <em>(most recent call last)</em>:') for frame in self.frames: frames.append(text_('<li%s>%s') % ( frame.info and text_(' title="%s"') % escape(frame.info) or text_(''), frame.render() )) if self.is_syntax_error: description_wrapper = text_('<pre class=syntaxerror>%s</pre>') else: description_wrapper = text_('<blockquote>%s</blockquote>') return SUMMARY_HTML % { 'classes': text_(' '.join(classes)), 'title': title and text_('<h3>%s</h3>' % title) or text_(''), 'frames': text_('\n'.join(frames)), 'description': description_wrapper % escape(self.exception) }
def render_summary(self, include_title=True): """Render the traceback for the interactive console.""" title = '' description = '' frames = [] classes = ['traceback'] if not self.frames: classes.append('noframe-traceback') if include_title: if self.is_syntax_error: title = text_('Syntax Error') else: title = text_('Traceback <em>(most recent call last)</em>:') for frame in self.frames: frames.append( text_('<li%s>%s') % (frame.info and text_(' title="%s"') % escape(frame.info) or text_(''), frame.render())) if self.is_syntax_error: description_wrapper = text_('<pre class=syntaxerror>%s</pre>') else: description_wrapper = text_('<blockquote>%s</blockquote>') return SUMMARY_HTML % { 'classes': text_(' '.join(classes)), 'title': title and text_('<h3>%s</h3>' % title) or text_(''), 'frames': text_('\n'.join(frames)), 'description': description_wrapper % escape(self.exception) }
def render(self): """Render a single frame in a traceback.""" return FRAME_HTML % { 'id': self.id, 'filename': escape(self.filename), 'lineno': self.lineno, 'function_name': escape(self.function_name), 'current_line': escape(self.current_line.strip()) }
def render_object_dump(self, items, title, repr=None): html_items = [] for key, value in items: html_items.append('<tr><th>%s<td><pre class=repr>%s</pre>' % (escape(key), value)) if not html_items: html_items.append('<tr><td><em>Nothing</em>') return OBJECT_DUMP_HTML % { 'title': escape(title), 'repr': repr and '<pre class=repr>%s</pre>' % repr or '', 'items': '\n'.join(html_items) }
def render_full(self, evalex=False, secret=None): """Render the Full HTML page with the traceback info.""" exc = escape(self.exception) return PAGE_HTML % { 'evalex': evalex and 'true' or 'false', 'console': 'false', 'title': exc, 'exception': exc, 'exception_type': escape(self.exception_type), 'summary': self.render_summary(include_title=False), 'plaintext': self.plaintext, 'plaintext_cs': re.sub('-{2,}', '-', self.plaintext), 'traceback_id': self.id, 'secret': secret }
def fallback_repr(self): try: info = ''.join(format_exception_only(*sys.exc_info()[:2])) except Exception: # pragma: no cover info = '?' return text_('<span class="brokenrepr"><broken repr (%s)>' '</span>' % escape(text_(info, 'utf-8', 'ignore').strip()))
def fallback_repr(self): try: info = ''.join(format_exception_only(*sys.exc_info()[:2])) except Exception: # pragma: no cover info = '?' return text_( '<span class="brokenrepr"><broken repr (%s)>' '</span>' % escape(text_(info, 'utf-8', 'ignore').strip()) )
def py3_text_repr(self, obj, limit=70): buf = ['<span class="string">'] escaped = escape(obj) a = repr(escaped[:limit]) b = repr(escaped[limit:]) if b != "''": buf.extend((a[:-1], '<span class="extended">', b[1:], '</span>')) else: buf.append(a) buf.append('</span>') return _add_subclass_info(text_(''.join(buf)), obj, text_type)
def py2_string_repr(self, obj, limit=70): buf = ['<span class="string">'] escaped = escape(obj) a = repr(escaped[:limit]) b = repr(escaped[limit:]) if isinstance(obj, text_type): buf.append('u') a = a[1:] b = b[1:] if b != "''": buf.extend((a[:-1], '<span class="extended">', b[1:], '</span>')) else: buf.append(a) buf.append('</span>') return _add_subclass_info(text_('').join(buf), obj, (str, unicode))
def write(self, x): self._write(escape(x))
def object_repr(self, obj): return text_('<span class="object">%s</span>' % escape(text_(repr(obj), 'utf-8', 'replace')))
def render(self): return SOURCE_LINE_HTML % { 'classes': text_(' ').join(self.classes), 'lineno': self.lineno, 'code': escape(self.code) }
def writelines(self, x): self._write(escape(''.join(x)))