<commit_before>import json
import http.cookies

from .status_codes import HTTP_STATUS_CODES


class Response(object):
    STATUS_CODE = HTTP_STATUS_CODES[200]
    CONTENT_TYPE = 'text/html'

    def __init__(self, content):
        self.content = content
        self.headers = {}
        self.cookies = http.cookies.BaseCookie()

    def set_header(self, key, value):
        self.headers[key] = value

    def set_cookie(self, key, value):
        self.cookies[key] = value

    def bake(self, start_response):
        body = bytes(self.content, 'utf8')
        self.headers['content-length'] = str(len(body))
        headers = self.headers.items()
        cookies = [('set-cookie', v.OutputString())
                   for _, v in self.cookies.items()]
        if len(self.cookies):
            headers = list(headers) + cookies
        start_response(self.STATUS_CODE, headers)
        return [body]


class CustomResponse(Response):
    def __init__(self, status, content_type, body):
        self.status = status
        self.content_type = content_type
        self.body = body
        self.headers = {}
        self.cookies = http.cookies.BaseCookie()

    def bake(self, start_response):
        self.headers['content-length'] = str(len(self.body))
        self.headers['content-type'] = self.content_type
        headers = self.headers.items()
        cookies = [('set-cookie', v.OutputString())
                   for _, v in self.cookies.items()]
        if len(self.cookies):
            headers = list(headers) + cookies
        start_response(self.status, headers)
        return [self.body]


class JSONResponse(object):
    CONTENT_TYPE = 'application/javascript'

    def __init__(self, obj):
        super(JSONResponse, self).__init__(json.dumps(obj))


class Redirect(object):
    STATUS_CODE = HTTP_STATUS_CODES[303]

    def __init__(self, location):
        self.location = location
        self.headers = {}

    def bake(self, start_response):
        self.headers['location'] = self.location
        headers = self.headers.items()
        start_response(self.STATUS_CODE, headers)<commit_msg>Inheriting Response class for JSONResponse class.<commit_after>import json
import http.cookies

from .status_codes import HTTP_STATUS_CODES


class Response(object):
    STATUS_CODE = HTTP_STATUS_CODES[200]
    CONTENT_TYPE = 'text/html'

    def __init__(self, content):
        self.content = content
        self.headers = {}
        self.cookies = http.cookies.BaseCookie()

    def set_header(self, key, value):
        self.headers[key] = value

    def set_cookie(self, key, value):
        self.cookies[key] = value

    def bake(self, start_response):
        body = bytes(self.content, 'utf8')
        self.headers['content-length'] = str(len(body))
        headers = self.headers.items()
        cookies = [('set-cookie', v.OutputString())
                   for _, v in self.cookies.items()]
        if len(self.cookies):
            headers = list(headers) + cookies
        start_response(self.STATUS_CODE, headers)
        return [body]


class CustomResponse(Response):
    def __init__(self, status, content_type, body):
        self.status = status
        self.content_type = content_type
        self.body = body
        self.headers = {}
        self.cookies = http.cookies.BaseCookie()

    def bake(self, start_response):
        self.headers['content-length'] = str(len(self.body))
        self.headers['content-type'] = self.content_type
        headers = self.headers.items()
        cookies = [('set-cookie', v.OutputString())
                   for _, v in self.cookies.items()]
        if len(self.cookies):
            headers = list(headers) + cookies
        start_response(self.status, headers)
        return [self.body]


class JSONResponse(Response):
    CONTENT_TYPE = 'application/javascript'

    def __init__(self, obj):
        super(JSONResponse, self).__init__(json.dumps(obj))


class Redirect(object):
    STATUS_CODE = HTTP_STATUS_CODES[303]

    def __init__(self, location):
        self.location = location
        self.headers = {}

    def bake(self, start_response):
        self.headers['location'] = self.location
        headers = self.headers.items()
        start_response(self.STATUS_CODE, headers)
{'fraction_non_alphanumeric': 0.11675245671502106, 'fraction_numerical': 0.003275620028076743, 'mean_word_length': 2.619813717188823, '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': '66536', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1237, 'n_words': 262}