<commit_before>import six
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseForbidden
from django.http.response import HttpResponseRedirectBase, HttpResponse, HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import redirect
from django.views import View


class ExceptionResponse(Exception):
    """
    Generic exception for signalling that instead of default error handling
    we should use attached response
    """

    def __init__(self, response):
        self.response = response


class Http403(PermissionDenied, ExceptionResponse):
    """
    A convenience wrapper around :py:class:~django.core.exceptions.PermissionDenied`
    """

    def __init__(self, response):
        if response is None:
            response = HttpResponseForbidden()
        elif not isinstance(response, HttpResponse):
            response = HttpResponseForbidden(response)
        super(Http403, self).__init__(response)


class Http302(ExceptionResponse):
    """Wraps a redirect shortcut call into the ResponseException"""

    def __init__(self, to, *args, **kwargs):
        if isinstance(to, HttpResponseRedirectBase):
            response = to
        else:
            response = redirect(to, *args, **kwargs)
        super(Http302, self).__init__(response)


class Http400(ExceptionResponse):
    def __init__(self, response):
        if isinstance(response, six.string_types):
            response = HttpResponseBadRequest(response)
        super(ExceptionResponse, self).__init__(response)


class Http401(ExceptionResponse):
    def __init__(self, response):
        if isinstance(response, six.string_types):
            response = HttpResponseNotFound(response)
        super(ExceptionResponse, self).__init__(response)


class ExceptionResponseView(View):
    def dispatch(self, request, *args, **kwargs):
        try:
            return super(ExceptionResponseView, self).dispatch(request, *args, **kwargs)
        except ExceptionResponse as ex:
            return ex.response
<commit_msg>+Http401<commit_after>import six
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseForbidden
from django.http.response import HttpResponseRedirectBase, HttpResponse, HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import redirect
from django.views import View


class ExceptionResponse(Exception):
    """
    Generic exception for signalling that instead of default error handling
    we should use attached response
    """

    def __init__(self, response):
        self.response = response


class Http403(PermissionDenied, ExceptionResponse):
    """
    A convenience wrapper around :py:class:~django.core.exceptions.PermissionDenied`
    """

    def __init__(self, response):
        if response is None:
            response = HttpResponseForbidden()
        elif not isinstance(response, HttpResponse):
            response = HttpResponseForbidden(response)
        super(Http403, self).__init__(response)


class Http302(ExceptionResponse):
    """Wraps a redirect shortcut call into the ResponseException"""

    def __init__(self, to, *args, **kwargs):
        if isinstance(to, HttpResponseRedirectBase):
            response = to
        else:
            response = redirect(to, *args, **kwargs)
        super(Http302, self).__init__(response)


class Http400(ExceptionResponse):
    def __init__(self, response):
        if isinstance(response, six.string_types):
            response = HttpResponseBadRequest(response)
        super(Http400, self).__init__(response)


class Http401(ExceptionResponse):
    def __init__(self, response):
        if isinstance(response, six.string_types):
            response = HttpResponseNotFound(response)
        super(Http401, self).__init__(response)


class ExceptionResponseView(View):
    def dispatch(self, request, *args, **kwargs):
        try:
            return super(ExceptionResponseView, self).dispatch(request, *args, **kwargs)
        except ExceptionResponse as ex:
            return ex.response

{'fraction_non_alphanumeric': 0.08515337423312884, 'fraction_numerical': 0.011042944785276074, 'mean_word_length': 3.5952649379932358, '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': '6256333', 'n_tokens_mistral': 1039, 'n_tokens_neox': 990, 'n_words': 284}