<commit_before>import tornado.websocket
from app import url, Route
from logging import getLogger

log = getLogger('apparatus')

@url(r'/(caller|callee)?')
class Index(Route):
    def get(self, type):
        return self.render('index.html')


@url(r'/ws')
class WebSocket(Route, tornado.websocket.WebSocketHandler):
    caller = None
    callee = None

    def open(self):
        log.info('Websocket opened')

    def on_message(self, message):
        if message == 'caller':
            self.caller = self
        elif message == 'callee':
            self.callee = self
        elif message == 'status':
            self.write_message('ECHO!Status: caller: %r callee: %r' % (
                self.caller, self.callee))

    def on_close(self):
        log.info('Websocket closed')

<commit_msg>Working on lan<commit_after>import tornado.websocket
from app import url, Route
from logging import getLogger

log = getLogger('apparatus')

@url(r'/(caller|callee)?')
class Index(Route):
    def get(self, type):
        return self.render('index.html')


@url(r'/ws')
class WebSocket(Route, tornado.websocket.WebSocketHandler):
    caller = None
    callee = None

    def open(self):
        log.info('Websocket opened')

    def on_message(self, message):
        log.debug('Websocket %s' % message)
        if '|' in message:
            pipe = message.index('|')
            cmd, data = message[:pipe], message[pipe + 1:]
        else:
            cmd, data = message, ''

        if cmd == 'IAM':
            if data == 'caller':
                WebSocket.caller = self
            elif  data == 'callee':
                WebSocket.callee = self
            if WebSocket.callee and WebSocket.caller:
                WebSocket.caller.write_message('GO')

        elif cmd == 'STATUS':
            self.write_message('ECHO|Status: caller: %r callee: %r' % (
                WebSocket.caller, WebSocket.callee))
        else:
            if WebSocket.caller == self:
                log.info('Caller -> Callee : %s' % message)
                WebSocket.callee and WebSocket.callee.write_message(message)
            if WebSocket.callee == self:
                log.info('Callee <- Callee : %s' % message)
                WebSocket.caller and WebSocket.caller.write_message(message)

    def on_close(self):
        log.info('Websocket closed')
        if self == WebSocket.caller:
            WebSocket.caller = None
        if self == WebSocket.callee:
            WebSocket.callee = None


{'fraction_non_alphanumeric': 0.1223916532905297, 'fraction_numerical': 0.0004012841091492777, 'mean_word_length': 2.17984693877551, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '859610', 'n_tokens_mistral': 770, 'n_tokens_neox': 738, 'n_words': 178}