<commit_before><commit_msg>moved parsing out into parser<commit_after>import logging

from protocol import *


class Parser(object):

    def __init__(self, connection):
        self.connection = connection

    def parse_message(self, message):        
        service = get_service(message)

        if service not in requests.keys():
            logging.info('No such request!')

        conn = self.connection

        request_name = requests[service]

        if request_name == 'ping':
            conn.write_message(create_pong())
            return
        elif request_name == 'roomlist':
            conn.write_message(create_roomlist(conn.possible_rooms))
            return

        data = get_data(message)

        if request_name == 'join':
            conn.join_room(data['user'])
        elif request_name == 'userlist':
            room = conn.get_room(data['room'])

            if room is None:
                conn.write_message('No such room as {room}'.format(room=data['room']))
            else:
                conn.write_message(create_userlist(room.user_names))

        elif request_name == 'send':
            room = conn.get_room(data['room'])

            if room is not None:
                room.send_message(create_message(data['username'], data['message']))
{'fraction_non_alphanumeric': 0.10681114551083591, 'fraction_numerical': 0.0, 'mean_word_length': 2.208436724565757, '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': '3169374', 'n_tokens_mistral': 352, 'n_tokens_neox': 335, 'n_words': 77}