<commit_before># Module:   errors
# Date:     11th February 2009
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""Errors

This module implements a set of standard HTTP Errors.
"""

from cgi import escape as _escape
from urlparse import urljoin as _urljoin

from circuits import Event

import utils
from constants import DEFAULT_ERROR_MESSAGE, RESPONSES, SERVER_VERSION


class HTTPError(Event):

    def __init__(self, request, response, status, message=None, error=None):
        super(HTTPError, self).__init__(request, response,
                status, message=message, error=error)

        response.close = True

        self.request = request
        self.response = response
        self.status = status

        short, long = RESPONSES.get(status, ("???", "???",))
        self.message = message = message or short

        self.error = error

        response.status = "%s %s" % (status, short)

        response.body = DEFAULT_ERROR_MESSAGE % {
            "status": "%s %s" % (status, short),
            "message": _escape(message),
            "traceback": error or "",
            "version": SERVER_VERSION}<commit_msg>web.errors: Set additional attributes etype, evalue and traceback for HTTPError object and pass a formatted traceback as "traceback" for the default error template.<commit_after># Module:   errors
# Date:     11th February 2009
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""Errors

This module implements a set of standard HTTP Errors.
"""

from traceback import format_tb
from cgi import escape as _escape
from urlparse import urljoin as _urljoin

from circuits import Event

import utils
from constants import DEFAULT_ERROR_MESSAGE, RESPONSES, SERVER_VERSION


class HTTPError(Event):

    def __init__(self, request, response, status, message=None, error=None):
        super(HTTPError, self).__init__(request, response,
                status, message=message, error=error)

        response.close = True

        self.request = request
        self.response = response
        self.status = status

        short, long = RESPONSES.get(status, ("???", "???",))
        self.message = message = message or short

        self.error = error
        self.etype, self.evalue, self.traceback = self.error

        response.status = "%s %s" % (status, short)

        response.body = DEFAULT_ERROR_MESSAGE % {
            "status": "%s %s" % (status, short),
            "message": _escape(message),
            "traceback": "".join(format_tb(self.traceback)),
            "version": SERVER_VERSION}
{'fraction_non_alphanumeric': 0.10183378852906749, 'fraction_numerical': 0.0046820132657042525, 'mean_word_length': 2.9446153846153846, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, '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': '4785749', 'n_tokens_mistral': 734, 'n_tokens_neox': 700, 'n_words': 232}