<commit_before>#coding:utf8
from twisted.protocols.basic import LineReceiver
import json
import syncplay
from functools import wraps
import time
from syncplay.messages import getMessage

class JSONCommandProtocol(LineReceiver): 
    def handleMessages(self, messages):
        for message in messages.iteritems():
            command = message[0]
            if command == "Hello":
                self.handleHello(message[1])
            elif command == "Set":
                self.handleSet(message[1])
            elif command == "List":
                self.handleList(message[1])
            elif command == "State":
                self.handleState(message[1])
            elif command == "Error":
                self.handleError(message[1])
            else:
                self.dropWithError(getMessage("en", "unknown-command-server-error").format(message[1])) #TODO: log, not drop

    def printReceived(self, line): #TODO: remove
        #print ">>i", line
        pass
        
    def printSent(self, line):
        #print "o<<", line
        pass

    def lineReceived(self, line):
        line = line.strip()
        if not line:
            return
        self.printReceived(line)
        try:
            messages = json.loads(line)
        except:
            if ("GET / HTTP/1." in line):
                self.handleHttpRequest(line)
                self.drop()
            else:
                self.dropWithError(getMessage("en", "not-json-server-error").format(line))
            return
        self.handleMessages(messages) 
    
    def sendMessage(self, dict_):
        line = json.dumps(dict_)
        self.printSent(line)    
        self.sendLine(line)

    def drop(self):
        self.transport.loseConnection()

    def dropWithError(self, error):
        raise NotImplementedError()

class SyncClientProtocol(JSONCommandProtocol):
    def __init__(self, client):
        self._client = client
        self.clientIgnoringOnTheFly = 0
        self.serverIgnoringOnTheFly = 0
        self.logged = False
        
    def connectionMade(self):
        self._client.initProtocol(self)
        self.sendHello()

    def connectionLost(self, reason):
        self._client.destroyProtocol()
        
    def dropWithError(self, error):
        self._client.ui.showErrorMessage(error)<commit_msg>Remmoved prints from protocol classes<commit_after>#coding:utf8
from twisted.protocols.basic import LineReceiver
import json
import syncplay
from functools import wraps
import time
from syncplay.messages import getMessage

class JSONCommandProtocol(LineReceiver): 
    def handleMessages(self, messages):
        for message in messages.iteritems():
            command = message[0]
            if command == "Hello":
                self.handleHello(message[1])
            elif command == "Set":
                self.handleSet(message[1])
            elif command == "List":
                self.handleList(message[1])
            elif command == "State":
                self.handleState(message[1])
            elif command == "Error":
                self.handleError(message[1])
            else:
                self.dropWithError(getMessage("en", "unknown-command-server-error").format(message[1])) #TODO: log, not drop

    def lineReceived(self, line):
        line = line.strip()
        if not line:
            return
        try:
            messages = json.loads(line)
        except:
            if ("GET / HTTP/1." in line):
                self.handleHttpRequest(line)
                self.drop()
            else:
                self.dropWithError(getMessage("en", "not-json-server-error").format(line))
            return
        self.handleMessages(messages) 
    
    def sendMessage(self, dict_):
        line = json.dumps(dict_)
        self.sendLine(line)

    def drop(self):
        self.transport.loseConnection()

    def dropWithError(self, error):
        raise NotImplementedError()

class SyncClientProtocol(JSONCommandProtocol):
    def __init__(self, client):
        self._client = client
        self.clientIgnoringOnTheFly = 0
        self.serverIgnoringOnTheFly = 0
        self.logged = False
        
    def connectionMade(self):
        self._client.initProtocol(self)
        self.sendHello()

    def connectionLost(self, reason):
        self._client.destroyProtocol()
        
    def dropWithError(self, error):
        self._client.ui.showErrorMessage(error)
{'fraction_non_alphanumeric': 0.1007226738934056, 'fraction_numerical': 0.004968383017163505, 'mean_word_length': 2.0608154803040772, 'pattern_counts': {'":': 10, '<': 5, '<?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': '2059888', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1163, 'n_words': 263}