<commit_before>import sys
import logging
import socketserver
import struct
import threading
import hashlib
from messageparser import MessageParser
import messages
from lobby import *
from game import *
from helpers import *


class TCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass


class RequestHandler(socketserver.BaseRequestHandler):

    def setup(self):
        self.__client = ClientHandler(self.request)

    def handle(self):
        self.__client.handle()

    def finish(self):
        self.__client.finish()


class ClientHandler:

    def __init__(self, sock):
        self.__socket = sock
        self.__message_parser = MessageParser()
        self.__lobby_model = LobbyModel()
        # name of the game
        self.__game = None
        # player number (1 or 2)
        self.__player = None
        # player id lol
        self.__id = self.__get_own_player_id()
        # add client as player
        self.__lobby_model.add_player(self.__id)

        # register callbacks
        # TODO consistently rename on_update into on_update_lobby
        self.__lobby_model.register_callback(LobbyEvent.on_update, self.on_update_lobby)
        self.__lobby_model.register_callback(LobbyEvent.on_game_deleted, self.on_game_deleted)
        self.__lobby_model.register_callback(LobbyEvent.on_chat, self.on_chat)

    def handle(self):
        logging.info("Client {} connected.".format(self.__socket.getpeername()))
        while True:
            # receive 2 bytes size header
            size = self.__socket.recv(2)
            if not size:
                logging.debug("Did not receive 2 bytes header.")
                break
            size = struct.unpack('>H', size)[0]
            logging.debug("Size: " + str(size))

            # receive message body<commit_msg>[server] whatever<commit_after>import sys
import logging
import socketserver
import struct
import threading
import hashlib
from messageparser import MessageParser
import messages
from lobby import *
from game import *
from helpers import *


class TCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass


class RequestHandler(socketserver.BaseRequestHandler):

    def setup(self):
        self.__client = ClientHandler(self.request)

    def handle(self):
        self.__client.handle()

    def finish(self):
        self.__client.finish()


class ClientHandler:

    def __init__(self, sock):
        self.__socket = sock
        self.__message_parser = MessageParser()
        self.__lobby_model = LobbyModel()
        # name of the game
        self.__game = None
        # player number (1 or 2)
        self.__player = None
        # player id lol
        self.__id = self.__get_own_player_id()
        # add client as player
        self.__lobby_model.add_player(self.__id)

        # register callbacks
        self.__lobby_model.register_callback(LobbyEvent.on_update, self.on_update_lobby)
        self.__lobby_model.register_callback(LobbyEvent.on_game_deleted, self.on_game_deleted)
        self.__lobby_model.register_callback(LobbyEvent.on_chat, self.on_chat)

    def handle(self):
        logging.info("Client {} connected.".format(self.__socket.getpeername()))
        while True:
            # receive 2 bytes size header
            size = self.__socket.recv(2)
            if not size:
                logging.debug("Did not receive 2 bytes header.")
                break
            size = struct.unpack('>H', size)[0]
            logging.debug("Size: " + str(size))

            # receive message body
{'fraction_non_alphanumeric': 0.08370913190529876, 'fraction_numerical': 0.0033821871476888386, 'mean_word_length': 2.632548618219038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1407808', 'n_tokens_mistral': 987, 'n_tokens_neox': 968, 'n_words': 238}