<commit_before>from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
import ssl
import stoppable_thread
import threading
import time
import uuid


class HandlerMaison(BaseHTTPRequestHandler):
    logger = logging.getLogger("HandlerMaison")
    #server stuff

    def do_GET(self):
        return self.do_POST()

    def do_POST(self):
        try:
            print(self.path)
            print(WebHookServer.Path)
            if self.path == WebHookServer.Path:
                self.logger.info("Recieve post")
                print ("THE POST")
                jsonListString = []
                #for line in self.rfile:
                #    jsonListString.append(str(line, 'utf-8'))
                #    print ("line:"+str(line, 'utf-8'))
                print ("THE END")
                #jsonObject = json.loads(''.join(jsonListString))
                #print(jsonObject)
                self.ok()
            else:
                self.error_access()
        except:
            self.logger.exception("Handler error", exc_info=True)
            self.error()

    def error_access(self):
        self.send_response(403)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(bytes("Access denied", "utf-8"))

    def error(self):
        self.send_response(500)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(bytes("Server error", "utf-8"))

    def ok(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(bytes("Ok", "utf-8"))


class WebHookServer(stoppable_thread.StoppableThread):
    Bot = None
    Path = None

    def __init__(self, bot, public, private, port=8443):
        super(WebHookServer, self).__init__()
        self.logger = logging.getLogger(type(self).__name__)
        WebHookServer.Bot = bot
        self.__public_path = public
        self.__private_path = private
        self.__port = port
        self.key = None
        self.url = None
        self.httpd = None
        
    def run(self):
        try:
            self.logger.info("Starting getting public ip")
            #response = json.loads(requests.get("https://api.ipify.org/?format=json").text)
            #ip = response["ip"]
            ip = "fa18swiss.no-ip.biz"
            self.logger.warning("Ip : %s", ip)
            self.key = str(uuid.uuid4())
            self.logger.warning("Key : '%s'", self.key)
            WebHookServer.Path = "/%s/" % self.key
            self.url = "https://%s:%d%s" % (ip, self.__port, self.Path)
            self.logger.warning("Url : '%s'", self.url)
            self.logger.info("Init server on port %d", self.__port)
            server_address = ('', self.__port)
            self.httpd = HTTPServer(server_address, HandlerMaison)

            try:
                ssl_version = ssl.PROTOCOL_TLSv1_2
            except:
                self.logger.warning("Can't use TLS 1.2, use TLS 1 instead")
                ssl_version = ssl.PROTOCOL_TLSv1

            # SSL
            self.httpd.socket = ssl.wrap_socket(self.httpd.socket,
                                            server_side=True,
                                            certfile=self.__public_path,
                                            keyfile=self.__private_path,
                                            ssl_version=ssl_version)

            self.logger.info("Bot starting")
            self.Bot.start()
            self.logger.info("Bot started")
            thread = WebHookSetter(self.Bot, self.url, self.__public_path)
            thread.start()
            self.httpd.serve_forever()
        except:
            self.logger.exception("Server fail", exc_info=True)
        self.logger.info("Stoppring bot")
        self.Bot.setWebhook("")
        self.Bot.stop()
        self.logger.info("Stopped bot")

    def stop(self):
        super(WebHookServer, self).stop()<commit_msg>remove bot starting<commit_after>from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
import ssl
import stoppable_thread
import threading
import time
import uuid


class HandlerMaison(BaseHTTPRequestHandler):
    logger = logging.getLogger("HandlerMaison")
    #server stuff

    def do_GET(self):
        return self.do_POST()

    def do_POST(self):
        try:
            print(self.path)
            print(WebHookServer.Path)
            if self.path == WebHookServer.Path:
                self.logger.info("Recieve post")
                print ("THE POST")
                jsonListString = []
                #for line in self.rfile:
                #    jsonListString.append(str(line, 'utf-8'))
                #    print ("line:"+str(line, 'utf-8'))
                print ("THE END")
                #jsonObject = json.loads(''.join(jsonListString))
                #print(jsonObject)
                self.ok()
            else:
                self.error_access()
        except:
            self.logger.exception("Handler error", exc_info=True)
            self.error()

    def error_access(self):
        self.send_response(403)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(bytes("Access denied", "utf-8"))

    def error(self):
        self.send_response(500)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(bytes("Server error", "utf-8"))

    def ok(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        self.wfile.write(bytes("Ok", "utf-8"))


class WebHookServer(stoppable_thread.StoppableThread):
    Bot = None
    Path = None

    def __init__(self, bot, public, private, port=8443):
        super(WebHookServer, self).__init__()
        self.logger = logging.getLogger(type(self).__name__)
        WebHookServer.Bot = bot
        self.__public_path = public
        self.__private_path = private
        self.__port = port
        self.key = None
        self.url = None
        self.httpd = None
        
    def run(self):
        try:
            self.logger.info("Starting getting public ip")
            #response = json.loads(requests.get("https://api.ipify.org/?format=json").text)
            #ip = response["ip"]
            ip = "fa18swiss.no-ip.biz"
            self.logger.warning("Ip : %s", ip)
            self.key = str(<KEY>())
            self.logger.warning("Key : '%s'", self.key)
            WebHookServer.Path = "/%s/" % self.key
            self.url = "https://%s:%d%s" % (ip, self.__port, self.Path)
            self.logger.warning("Url : '%s'", self.url)
            self.logger.info("Init server on port %d", self.__port)
            server_address = ('', self.__port)
            self.httpd = HTTPServer(server_address, HandlerMaison)

            try:
                ssl_version = ssl.PROTOCOL_TLSv1_2
            except:
                self.logger.warning("Can't use TLS 1.2, use TLS 1 instead")
                ssl_version = ssl.PROTOCOL_TLSv1

            # SSL
            self.httpd.socket = ssl.wrap_socket(self.httpd.socket,
                                            server_side=True,
                                            certfile=self.__public_path,
                                            keyfile=self.__private_path,
                                            ssl_version=ssl_version)

            thread = WebHookSetter(self.Bot, self.url, self.__public_path)
            thread.start()
            self.httpd.serve_forever()
        except:
            self.logger.exception("Server fail", exc_info=True)
        self.logger.info("Stoppring bot")
        self.Bot.setWebhook("")
        self.Bot.stop()
        self.logger.info("Stopped bot")

    def stop(self):
        super(WebHookServer, self).stop()
{'fraction_non_alphanumeric': 0.11936339522546419, 'fraction_numerical': 0.006694454970317039, 'mean_word_length': 1.7598466364586964, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2420659', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2226, 'n_words': 414}