<commit_before>import BaseHTTPServer
import sys
import time
import json
import os
import re
import logging
from mock import patch
from notification_backend.entrypoint import handler


HOST_NAME = sys.argv[1]
PORT_NUMBER = int(sys.argv[2])
logger = logging.getLogger("notification_backend")


class LocalNotificationBackend(BaseHTTPServer.BaseHTTPRequestHandler):

    server_version = "LocalNotificationBackend/0.1"

    def do_OPTIONS(self):
        self.send_response(200)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Headers", "Content-Type")
        self.end_headers()

    def do_GET(self):
        status, result = handle_request({}, self.headers, self.path, "GET")
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Headers", "Content-Type")
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

    def do_POST(self):
        length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(length)
        payload = json.loads(post_data)
        status, result = handle_request(
            payload,
            self.headers,
            self.path,
            "POST"
        )
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Headers", "Content-Type")
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

    def do_PATCH(self):
        length = int(self.headers['Content-Length'])
        patch_data = self.rfile.read(length)
        payload = json.loads(patch_data)
        status, result = handle_request(
            payload,
            self.headers,
            self.path,
            "PATCH"
        )
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Headers", "Content-Type")
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

    def do_DELETE(self):
        status, result = handle_request({}, self.headers, self.path, "DELETE")
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Headers", "Content-Type")
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))
<commit_msg>Add the Allow-Methods and Allow-Headers headers to the local test server<commit_after>import BaseHTTPServer
import sys
import time
import json
import os
import re
import logging
from mock import patch
from notification_backend.entrypoint import handler


HOST_NAME = sys.argv[1]
PORT_NUMBER = int(sys.argv[2])
logger = logging.getLogger("notification_backend")

allowed_headers = [
    "Content-Type",
    "Authorization"
]

allowed_methods = [
    "OPTIONS",
    "GET",
    "POST",
    "PATCH",
    "DELETE"
]


class LocalNotificationBackend(BaseHTTPServer.BaseHTTPRequestHandler):

    server_version = "LocalNotificationBackend/0.1"

    def do_OPTIONS(self):
        self.send_response(200)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Methods", ",".join(allowed_methods))  # NOQA
        self.send_header("Access-Control-Allow-Headers", ",".join(allowed_headers))  # NOQA
        self.end_headers()

    def do_GET(self):
        status, result = handle_request({}, self.headers, self.path, "GET")
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Methods", ",".join(allowed_methods))  # NOQA
        self.send_header("Access-Control-Allow-Headers", ",".join(allowed_headers))  # NOQA
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

    def do_POST(self):
        length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(length)
        payload = json.loads(post_data)
        status, result = handle_request(
            payload,
            self.headers,
            self.path,
            "POST"
        )
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Methods", ",".join(allowed_methods))  # NOQA
        self.send_header("Access-Control-Allow-Headers", ",".join(allowed_headers))  # NOQA
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

    def do_PATCH(self):
        length = int(self.headers['Content-Length'])
        patch_data = self.rfile.read(length)
        payload = json.loads(patch_data)
        status, result = handle_request(
            payload,
            self.headers,
            self.path,
            "PATCH"
        )
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Methods", ",".join(allowed_methods))  # NOQA
        self.send_header("Access-Control-Allow-Headers", ",".join(allowed_headers))  # NOQA
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

    def do_DELETE(self):
        status, result = handle_request({}, self.headers, self.path, "DELETE")
        self.send_response(status)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header("Access-Control-Allow-Methods", ",".join(allowed_methods))  # NOQA
        self.send_header("Access-Control-Allow-Headers", allowed_headers.join(","))  # NOQA
        self.send_header("Content-type", "application/json")
        self.end_headers()
        self.wfile.write(json.dumps(result))

{'fraction_non_alphanumeric': 0.13451443569553806, 'fraction_numerical': 0.0022965879265091863, 'mean_word_length': 2.9386304909560725, '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': '5464985', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1805, 'n_words': 273}