<commit_before>from django.contrib import messages
from django.core.serializers.json import DjangoJSONEncoder
from django.http import JsonResponse, HttpResponse
from django.shortcuts import redirect, render_to_response

import logging
import json
import re

logger = logging.getLogger("logger")


class ErrorResponse(Exception):
    def __init__(self, message, data=None, status=401, err=None,
                 redirect_back=None):
        super(Exception, self).__init__(self, message)
        self.data = {"error": message}
        if data:
            self.data.update(data)
        self.status = status
        self.exception = err
        self.redirect_back = redirect_back


def make_response(template=None, error_template="error.djhtml",
                  shared_context=None):
    """
    View decorator

    Tailor the response to the requested data type, as specified
    in the Accept header. Expects the wrapped view to return a
    dict. If the request wants JSON, renders the dict as JSON data.
    """
    def constructor_fn(view):
        def wrapped_view(req, *args, **kwargs):
            use_template = template
            status = 200
            redirect = False
            try:
                data = view(req, *args, **kwargs)
                if shared_context:
                    data.update(shared_context)
            except ErrorResponse as err:
                data = err.data
                use_template = error_template
                status = err.status
                redirect_back = err.redirect_back<commit_msg>Bug fix: wrong variable name<commit_after>from django.contrib import messages
from django.core.serializers.json import DjangoJSONEncoder
from django.http import JsonResponse, HttpResponse
from django.shortcuts import redirect, render_to_response

import logging
import json
import re

logger = logging.getLogger("logger")


class ErrorResponse(Exception):
    def __init__(self, message, data=None, status=401, err=None,
                 redirect_back=None):
        super(Exception, self).__init__(self, message)
        self.data = {"error": message}
        if data:
            self.data.update(data)
        self.status = status
        self.exception = err
        self.redirect_back = redirect_back


def make_response(template=None, error_template="error.djhtml",
                  shared_context=None):
    """
    View decorator

    Tailor the response to the requested data type, as specified
    in the Accept header. Expects the wrapped view to return a
    dict. If the request wants JSON, renders the dict as JSON data.
    """
    def constructor_fn(view):
        def wrapped_view(req, *args, **kwargs):
            use_template = template
            status = 200
            redirect_back = False
            try:
                data = view(req, *args, **kwargs)
                if shared_context:
                    data.update(shared_context)
            except ErrorResponse as err:
                data = err.data
                use_template = error_template
                status = err.status
                redirect_back = err.redirect_back
{'fraction_non_alphanumeric': 0.07335041639974375, 'fraction_numerical': 0.003843689942344651, 'mean_word_length': 2.270157068062827, 'pattern_counts': {'":': 2, '<': 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': '6505860', 'n_tokens_mistral': 813, 'n_tokens_neox': 771, 'n_words': 245}