<commit_before># -*- coding: utf-8 -*-

from flask import request, Response
from flask import json
from flask.views import MethodView

class Resource(MethodView):

    vendors = []
    method_decorators = []

    def dispatch_request(self, *args, **kw):
        method = getattr(self, request.method.lower(), None)
        # if the request method is HEAD and we don't have a handler for it
        # retry with GET
        if method is None and request.method == 'HEAD':
            method = getattr(self, 'get', None)

        if method is None:
            raise NotImplementedError(request.method)

        for decorator in self.method_decorators:
            method = decorator(method)

        response = method(*args, **kw)

        if isinstance(response, Response):
            return response

        data, code, headers = self.parse_response(response)
        presenter = next((v for v in self.vendors
            if v.mediatype==request.access_mediatype), None)

        if not presenter:
            return response

        return presenter.as_representation(method, data, code, headers)

    def _parse_response(self, value):
        if not isinstance(value, tuple):
            code = 200
            if value == '':
                code = 204
            return json.dumps(value), code, {}

        try:
            data, code, headers = value
        except ValueError:
            pass

        try:
            data, code = value
            headers = {}
        except ValueError:<commit_msg>Fix typo.<commit_after># -*- coding: utf-8 -*-

from flask import request, Response
from flask import json
from flask.views import MethodView

class Resource(MethodView):

    vendors = []
    method_decorators = []

    def dispatch_request(self, *args, **kw):
        method = getattr(self, request.method.lower(), None)
        # if the request method is HEAD and we don't have a handler for it
        # retry with GET
        if method is None and request.method == 'HEAD':
            method = getattr(self, 'get', None)

        if method is None:
            raise NotImplementedError(request.method)

        for decorator in self.method_decorators:
            method = decorator(method)

        response = method(*args, **kw)

        if isinstance(response, Response):
            return response

        data, code, headers = self._parse_response(response)
        presenter = next((v for v in self.vendors
            if v.mediatype==request.access_mediatype), None)

        if not presenter:
            return response

        return presenter.as_representation(method, data, code, headers)

    def _parse_response(self, value):
        if not isinstance(value, tuple):
            code = 200
            if value == '':
                code = 204
            return json.dumps(value), code, {}

        try:
            data, code, headers = value
        except ValueError:
            pass

        try:
            data, code = value
            headers = {}
        except ValueError:
{'fraction_non_alphanumeric': 0.08898445253059874, 'fraction_numerical': 0.004631161098246774, 'mean_word_length': 1.9676153091265947, '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': '7277289', 'n_tokens_mistral': 811, 'n_tokens_neox': 768, 'n_words': 260}