<commit_before>HTTP_200_OK = '200 OK'

HTTP_404_NOT_FOUND = '404 Not Found'
HTTP_405_METHOD_NOT_ALLOWED = '405 Method Not Allowed'

HTTP_500_INTERNAL_SERVER_ERROR = '500 Internal Server Error'
HTTP_501_NOT_IMPLEMENTED = '501 Not Implemented'


class HttpError(Exception):

    default_headers = ()

    def __init__(self, status=HTTP_500_INTERNAL_SERVER_ERROR,
                 data=None, headers=None):
        self.status = status
        self._headers = headers or ()
        self._data = data
        self._prepared_data = None

    def __len__(self):
        return 1

    def __iter__(self):
        yield self.data

    @property
    def headers(self):
        headers_sent = set()
        for header, value in self._headers:
            header, value = str(header).title(), str(value)
            headers_sent.add(header)
            yield header, value
        for header, value in self.default_headers:
            header = header.title()
            if header not in headers_sent:
                yield header, value

    @property
    def data(self):
        if self._prepared_data is None:
            self._prepared_data = self.prepare_data(self._data)
        return self._prepared_data

    def prepare_data(self, data):
        return data and str(data) or ''<commit_msg>HttpError optimization<commit_after>HTTP_200_OK = '200 OK'

HTTP_404_NOT_FOUND = '404 Not Found'
HTTP_405_METHOD_NOT_ALLOWED = '405 Method Not Allowed'

HTTP_500_INTERNAL_SERVER_ERROR = '500 Internal Server Error'
HTTP_501_NOT_IMPLEMENTED = '501 Not Implemented'


class HttpError(Exception):

    default_headers = ()

    def __init__(self, status=HTTP_500_INTERNAL_SERVER_ERROR,
                 data=None, headers=None):
        self.status = status
        self._headers = headers or ()
        self.data = data

    def __len__(self):
        return 1

    def __iter__(self):
        yield self.data and str(self.data) or ''

    @property
    def headers(self):
        headers_sent = set()
        for header, value in self._headers:
            header, value = str(header).title(), str(value)
            headers_sent.add(header)
            yield header, value
        for header, value in self.default_headers:
            header = header.title()
            if header not in headers_sent:
                yield header, value

{'fraction_non_alphanumeric': 0.08168529664660361, 'fraction_numerical': 0.029234737747205503, 'mean_word_length': 2.4525222551928785, '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': '2082271', 'n_tokens_mistral': 726, 'n_tokens_neox': 661, 'n_words': 179}