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, cgi.escape(text_er))
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, cgi.escape(text_er))
def handle_exception(exc_info, error_stream, html=True, debug_mode=False, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=False, error_email_from='errors@localhost', smtp_server='localhost', smtp_username=None, smtp_password=None, smtp_use_tls=False, error_subject_prefix='', error_message=None, simple_html_error=False, environ=None ): """ For exception handling outside of a web context Use like:: import sys from paste.exceptions.errormiddleware import handle_exception try: do stuff except: handle_exception( sys.exc_info(), sys.stderr, html=False, ...other config...) If you want to report, but not fully catch the exception, call ``raise`` after ``handle_exception``, which (when given no argument) will reraise the exception. """ reported = False exc_data = collector.collect_exception(*exc_info) extra_data = '' if error_email: rep = reporter.EmailReporter( to_addresses=error_email, from_address=error_email_from, smtp_server=smtp_server, smtp_username=smtp_username, smtp_password=smtp_password, smtp_use_tls=smtp_use_tls, subject_prefix=error_subject_prefix) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if error_log: rep = reporter.LogReporter( filename=error_log) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if show_exceptions_in_wsgi_errors: rep = reporter.FileReporter( file=error_stream) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True else: error_stream.write('Error - %s: %s\n' % ( exc_data.exception_type, exc_data.exception_value)) if html: if debug_mode and simple_html_error: return_error = formatter.format_html( exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False) reported = True elif debug_mode and not simple_html_error: error_html = formatter.format_html( exc_data, include_hidden_frames=True, include_reusable=False) head_html = formatter.error_css + formatter.hide_display_js return_error = error_template( head_html, error_html, extra_data) extra_data = '' reported = True else: msg = error_message or ''' An error occurred. ''' extra = "<p><b>The error has been logged to our team.</b>" if 'sentry_event_id' in environ: extra += " If you want to contact us about this error, please reference the following<br><br>" extra += "<b><large>GURU MEDITATION: #" + environ['sentry_event_id'] + "</large></b>" extra += "</p>" return_error = error_template('', msg, extra) else: return_error = None if not reported and error_stream: err_report = formatter.format_text(exc_data, show_hidden_frames=True) err_report += '\n' + '-'*60 + '\n' error_stream.write(err_report) if extra_data: error_stream.write(extra_data) return return_error
def format_text(self, exc_data, **kw): return formatter.format_text(exc_data, **kw)
def handle_exception(exc_info, error_stream, html=True, debug_mode=False, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=False, error_email_from='errors@localhost', smtp_server='localhost', error_subject_prefix='', error_message=None, simple_html_error=False, ): """ For exception handling outside of a web context Use like:: import sys import paste import paste.error_middleware try: do stuff except: paste.error_middleware.exception_handler( sys.exc_info(), paste.CONFIG, sys.stderr, html=False) If you want to report, but not fully catch the exception, call ``raise`` after ``exception_handler``, which (when given no argument) will reraise the exception. """ reported = False exc_data = collector.collect_exception(*exc_info) extra_data = '' if error_email: rep = reporter.EmailReporter( to_addresses=error_email, from_address=error_email_from, smtp_server=smtp_server, subject_prefix=error_subject_prefix) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if error_log: rep = reporter.LogReporter( filename=error_log) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if show_exceptions_in_wsgi_errors: rep = reporter.FileReporter( file=error_stream) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True else: error_stream.write('Error - %s: %s\n' % ( exc_data.exception_type, exc_data.exception_value)) if html: if debug_mode and simple_html_error: return_error = formatter.format_html( exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False) reported = True elif debug_mode and not simple_html_error: error_html = formatter.format_html( exc_data, include_hidden_frames=True, include_reusable=False) head_html = formatter.error_css + formatter.hide_display_js return_error = error_template( head_html, error_html, extra_data) extra_data = '' reported = True else: msg = error_message or ''' An error occurred. See the error logs for more information. (Turn debug on to display exception reports here) ''' return_error = error_template('', msg, '') else: return_error = None if not reported and error_stream: err_report = formatter.format_text(exc_data, show_hidden_frames=True) err_report += '\n' + '-'*60 + '\n' error_stream.write(err_report) if extra_data: error_stream.write(extra_data) return return_error
def handle_exception(exc_info, error_stream, html=True, debug_mode=False, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=False, error_email_from='errors@localhost', smtp_server='localhost', smtp_username=None, smtp_password=None, smtp_use_tls=False, error_subject_prefix='', error_message=None, simple_html_error=False, environ=None): """ For exception handling outside of a web context Use like:: import sys from paste.exceptions.errormiddleware import handle_exception try: do stuff except Exception: handle_exception( sys.exc_info(), sys.stderr, html=False, ...other config...) If you want to report, but not fully catch the exception, call ``raise`` after ``handle_exception``, which (when given no argument) will reraise the exception. """ reported = False exc_data = collector.collect_exception(*exc_info) extra_data = '' if error_email: rep = reporter.EmailReporter(to_addresses=error_email, from_address=error_email_from, smtp_server=smtp_server, smtp_username=smtp_username, smtp_password=smtp_password, smtp_use_tls=smtp_use_tls, subject_prefix=error_subject_prefix) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if error_log: rep = reporter.LogReporter(filename=error_log) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if show_exceptions_in_wsgi_errors: rep = reporter.FileReporter(file=error_stream) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True else: error_stream.write('Error - {}: {}\n'.format(exc_data.exception_type, exc_data.exception_value)) if html: if debug_mode and simple_html_error: return_error = formatter.format_html(exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False) reported = True elif debug_mode and not simple_html_error: error_html = formatter.format_html(exc_data, include_hidden_frames=True, include_reusable=False) head_html = formatter.error_css + formatter.hide_display_js return_error = error_template(head_html, error_html, extra_data) extra_data = '' reported = True else: msg = error_message or ''' An error occurred. ''' extra = "<p><b>The error has been logged to our team.</b>" if 'sentry_event_id' in environ: extra += " If you want to contact us about this error, please reference the following<br><br>" extra += "<b><large>GURU MEDITATION: #" + environ[ 'sentry_event_id'] + "</large></b>" extra += "</p>" return_error = error_template('', msg, extra) else: return_error = None if not reported and error_stream: err_report = formatter.format_text(exc_data, show_hidden_frames=True) err_report += '\n' + '-' * 60 + '\n' error_stream.write(err_report) if extra_data: error_stream.write(extra_data) return return_error
def handle_exception( exc_info, error_stream, html=True, debug_mode=False, error_email=None, error_log=None, show_exceptions_in_wsgi_errors=False, error_email_from='errors@localhost', smtp_server='localhost', smtp_username=None, smtp_password=None, smtp_use_tls=False, error_subject_prefix='', error_message=None, simple_html_error=False, ): """ For exception handling outside of a web context Use like:: import sys from paste.exceptions.errormiddleware import handle_exception try: do stuff except: handle_exception( sys.exc_info(), sys.stderr, html=False, ...other config...) If you want to report, but not fully catch the exception, call ``raise`` after ``handle_exception``, which (when given no argument) will reraise the exception. """ reported = False exc_data = collector.collect_exception(*exc_info) extra_data = '' if error_email: rep = reporter.EmailReporter(to_addresses=error_email, from_address=error_email_from, smtp_server=smtp_server, smtp_username=smtp_username, smtp_password=smtp_password, smtp_use_tls=smtp_use_tls, subject_prefix=error_subject_prefix) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if error_log: rep = reporter.LogReporter(filename=error_log) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True if show_exceptions_in_wsgi_errors: rep = reporter.FileReporter(file=error_stream) rep_err = send_report(rep, exc_data, html=html) if rep_err: extra_data += rep_err else: reported = True else: line = ('Error - %s: %s\n' % (exc_data.exception_type, exc_data.exception_value)) error_stream.write(line) if html: if debug_mode and simple_html_error: return_error = formatter.format_html(exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False) reported = True elif debug_mode and not simple_html_error: error_html = formatter.format_html(exc_data, include_hidden_frames=True, include_reusable=False) head_html = formatter.error_css + formatter.hide_display_js return_error = error_template(head_html, error_html, extra_data) extra_data = '' reported = True else: msg = error_message or ''' An error occurred. See the error logs for more information. (Turn debug on to display exception reports here) ''' return_error = error_template('', msg, '') else: return_error = None if not reported and error_stream: err_report = formatter.format_text(exc_data, show_hidden_frames=True) err_report += '\n' + '-' * 60 + '\n' error_stream.write(err_report) if extra_data: error_stream.write(extra_data) return return_error