<commit_before>"""
The minimum needed to take a response and render a response
- url mapper utility
- wsgiwrapper
"""
from werkzeug.wrappers import Response
import json


def add_ressource_uri(response, obj):
    obj["ressource_uri"] = "/{0}/{1}/".format(
        response.ressource_name,
        obj[response.model.pk_field.name])
    return obj


class JsonResponse(object):
    """
    Just like a classic Response but render json everytime
    """
    def __init__(self, model, ressource_name,
                 formaters=["add_ressource_uri"], **options):
        self.model = model
        self.ressource_name = ressource_name
        self.formaters = formaters
        if options:
            self.make_options(**options)

    def __call__(self, *args, **kwargs):

        meta = None

        if "meta" in kwargs:
            meta = kwargs.pop("meta")

        if "objs" in kwargs:
            objs = self.format(kwargs.pop('objs'))
            if meta:
                response = {"meta": meta,
                            "object_list": objs}
            else:
                response = objs
            return Response(json.dumps(response),
                            mimetype="application/json",
                            **kwargs)
        else:
            response = ""
            if args:
                response = json.dumps(*args)
            return Response(response,
                            mimetype="application/json",
                            **kwargs)

    def make_options(self, **options):
        pass

    def format(self, objs):

        if isinstance(objs, list):
            for elem in objs:
                for formater in self.formaters:
                    if hasattr(formater, '__call__'):
                        elem = formater(self, elem)
                    else:
                        elem = globals()[formater](self, elem)

        if isinstance(objs, dict):
            for formater in self.formaters:
                if hasattr(formater, '__call__'):
                    objs = formater(self, objs)
                else:
                    objs = globals()[formater](self, objs)

        return objs<commit_msg>removed unused options for the view<commit_after>"""
The minimum needed to take a response and render a response
- url mapper utility
- wsgiwrapper
"""
from werkzeug.wrappers import Response
import json


def add_ressource_uri(response, obj):
    obj["ressource_uri"] = "/{0}/{1}/".format(
        response.ressource_name,
        obj[response.model.pk_field.name])
    return obj


class JsonResponse(object):
    """
    Just like a classic Response but render json everytime
    """
    def __init__(self, model, ressource_name,
                 formaters=["add_ressource_uri"], **options):
        self.model = model
        self.ressource_name = ressource_name
        self.formaters = formaters

    def __call__(self, *args, **kwargs):

        meta = None

        if "meta" in kwargs:
            meta = kwargs.pop("meta")

        if "objs" in kwargs:
            objs = self.format(kwargs.pop('objs'))
            if meta:
                response = {"meta": meta,
                            "object_list": objs}
            else:
                response = objs
            return Response(json.dumps(response),
                            mimetype="application/json",
                            **kwargs)
        else:
            response = ""
            if args:
                response = json.dumps(*args)
            return Response(response,
                            mimetype="application/json",
                            **kwargs)

    def format(self, objs):

        if isinstance(objs, list):
            for elem in objs:
                for formater in self.formaters:
                    if hasattr(formater, '__call__'):
                        elem = formater(self, elem)
                    else:
                        elem = globals()[formater](self, elem)

        if isinstance(objs, dict):
            for formater in self.formaters:
                if hasattr(formater, '__call__'):
                    objs = formater(self, objs)
                else:
                    objs = globals()[formater](self, objs)

        return objs
{'fraction_non_alphanumeric': 0.09707822808671066, 'fraction_numerical': 0.000942507068803016, 'mean_word_length': 1.507383343177791, 'pattern_counts': {'":': 4, '<': 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': '4794483', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1098, 'n_words': 289}