<commit_before>import traceback
import sys

class SessionHackException(Exception):
    """
    Raised when something goes wrong.
    """

class SessionHack(object):
    """
        The SessionHack middleware is used to catch any exceptions that occur;
        this makes debugging easier. Typically debugging can be painful because
        the trace and error is only shown in the web page.
    """

    def __init__(self, app, render_call):
        self.app = app
        self.render_call = render_call

    def __call__(self, env, start_response):
        error = False
        try:
            ret = self.app(env, start_response)
        except Exception, e:
            print 'Exception in SessionHack:', e.message
            print '-' * 60
            traceback.print_exc(file=sys.stdout)
            print '-' * 60
            ret = self.render_call(env, str(e))
            #raise SessionHackException(e.message)
            error = True
        finally:
            pass

        if error:
            start_response('200 OK', [('Content-Type', 'text/html')])
        return ret
<commit_msg>pyroTorrent: Fix encoding on error page.<commit_after>import traceback
import sys

class SessionHackException(Exception):
    """
    Raised when something goes wrong.
    """

class SessionHack(object):
    """
        The SessionHack middleware is used to catch any exceptions that occur;
        this makes debugging easier. Typically debugging can be painful because
        the trace and error is only shown in the web page.
    """

    def __init__(self, app, render_call):
        self.app = app
        self.render_call = render_call

    def __call__(self, env, start_response):
        error = False
        try:
            ret = self.app(env, start_response)
        except Exception, e:
            print 'Exception in SessionHack:', e.message
            print '-' * 60
            traceback.print_exc(file=sys.stdout)
            print '-' * 60
            ret = self.render_call(env, str(e))
            #raise SessionHackException(e.message)
            error = True
        finally:
            pass

        if error:
            start_response('200 OK', [('Content-Type', 'text/html;charset=utf8')])
        return ret

{'fraction_non_alphanumeric': 0.0875, 'fraction_numerical': 0.006696428571428571, 'mean_word_length': 2.057298772169168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2304088', 'n_tokens_mistral': 620, 'n_tokens_neox': 594, 'n_words': 191}