def not_found_app(self, environ, start_response): mapper = environ.get('paste.urlmap_object') if mapper: matches = [p for p, a in mapper.applications] extra = 'defined apps: %s' % (',\n '.join(map(repr, matches))) else: extra = '' extra += '\nSCRIPT_NAME: %r' % html.escape(environ.get('SCRIPT_NAME')) extra += '\nPATH_INFO: %r' % html.escape(environ.get('PATH_INFO')) extra += '\nHTTP_HOST: %r' % html.escape(environ.get('HTTP_HOST')) app = httpexceptions.HTTPNotFound( environ['PATH_INFO'], comment=html.escape(extra)).wsgi_application return app(environ, start_response)
def html_quote(v): """ Escape HTML characters, plus translate None to '' """ if v is None: return '' return html.escape(str(v), 1)
def format_html(exc_data, include_hidden_frames=False, **ops): if not include_hidden_frames: return HTMLFormatter(**ops).format_collected_data(exc_data) short_er = format_html(exc_data, show_hidden_frames=False, **ops) # @@: This should have a way of seeing if the previous traceback # was actually trimmed at all ops['include_reusable'] = False ops['show_extra_data'] = False long_er = format_html(exc_data, show_hidden_frames=True, **ops) text_er = format_text(exc_data, show_hidden_frames=True, **ops) return """ %s <br> <script type="text/javascript"> show_button('full_traceback', 'full traceback') </script> <div id="full_traceback" class="hidden-data"> %s </div> <br> <script type="text/javascript"> show_button('text_version', 'text version') </script> <div id="text_version" class="hidden-data"> <textarea style="width: 100%%" rows=10 cols=60>%s</textarea> </div> """ % (short_er, long_er, html.escape(text_er))
def html_quote(v, encoding=None): r""" Quote the value (turned to a string) as HTML. This quotes <, >, and quotes: """ encoding = encoding or default_encoding if v is None: return '' elif isinstance(v, six.binary_type): return html.escape(v, 1) elif isinstance(v, six.text_type): if six.PY3: return html.escape(v, 1) else: return html.escape(v.encode(encoding), 1) else: if six.PY3: return html.escape(six.text_type(v), 1) else: return html.escape(six.text_type(v).encode(encoding), 1)
def format_eval_html(exc_data, base_path, counter): short_formatter = EvalHTMLFormatter(base_path=base_path, counter=counter, include_reusable=False) short_er = short_formatter.format_collected_data(exc_data) long_formatter = EvalHTMLFormatter(base_path=base_path, counter=counter, show_hidden_frames=True, show_extra_data=False, include_reusable=False) long_er = long_formatter.format_collected_data(exc_data) text_er = formatter.format_text(exc_data, show_hidden_frames=True) if short_formatter.filter_frames(exc_data.frames) != \ long_formatter.filter_frames(exc_data.frames): # Only display the full traceback when it differs from the # short version full_traceback_html = """ <br> <script type="text/javascript"> show_button('full_traceback', 'full traceback') </script> <div id="full_traceback" class="hidden-data"> %s </div> """ % long_er else: full_traceback_html = '' return """ %s %s <br> <script type="text/javascript"> show_button('text_version', 'text version') </script> <div id="text_version" class="hidden-data"> <textarea style="width: 100%%" rows=10 cols=60>%s</textarea> </div> """ % (short_er, full_traceback_html, html.escape(text_er))
def html_quote(v): if v is None: return '' return html.escape(str(v), 1)
def html_quote(s): return html.escape(str(s), True)