<commit_before>from __future__ import print_function
from collections import defaultdict

import json

from twisted.internet import reactor, protocol, threads, defer
from twisted.protocols.basic import LineReceiver

from nethud.controller import Controller


class TelnetConnection(LineReceiver):
    def __init__(self, users):
        self.users = users
        self.uname = ''
        self.auth = False
        self.data_buffer = ''
        self.input_handlers = {'display': self.display,
                               'display_objects': self.objects}

        # Container for all the cool things on the level
        self.details = []

    # Twistedy methods!
    def connectionLost(self, reason):
        Controller.disconnect_user(self.uname)
        if self.uname in self.users:
            del self.users[self.uname]
        self.uname = ''
        print(reason)

    def lineReceived(self, line):
        msg_split = line.split()
        if msg_split[0] == 'AUTH':
            if len(msg_split) != 2:
                self.sendLine("ERR 406 Invalid Parameters.")
                return
            self.handle_auth(msg_split[1])
        elif msg_split[0] == 'QUIT':
            self.transport.loseConnection()
        else:
            self.sendLine("ERR 452 Invalid Command")

    # Bookkeeping methods
    def handle_auth(self, uname):
        self.users[uname] = self
        self.uname = uname
        Controller.connect_user(uname, self.handle_data)
        self.auth = True

    def handle_data(self, json_data):
        if self.data_buffer:
            data = self.data_buffer + data
            self.data_buffer = ''
        try:
            data = json.loads(json_data)
        except ValueError:
            # We probably just didn't get all of it
            self.data_buffer = json_data
            return

        for ret_key in data:
            if ret_key in self.input_handlers:
                self.input_handlers[ret_key](data[ret_key])

    # Methods  to actually do something about the Nethack data
    def display(self, display_data):
        """
        This interprets `display` objects and tries to pass that information
        on to the user.
        """

        status_line = ''
        messages = []
        inventory = []
        pois = defaultdict(list)<commit_msg>found a typo: data -> json_data<commit_after>from __future__ import print_function
from collections import defaultdict

import json

from twisted.internet import reactor, protocol, threads, defer
from twisted.protocols.basic import LineReceiver

from nethud.controller import Controller


class TelnetConnection(LineReceiver):
    def __init__(self, users):
        self.users = users
        self.uname = ''
        self.auth = False
        self.data_buffer = ''
        self.input_handlers = {'display': self.display,
                               'display_objects': self.objects}

       # Container for all the cool things on the level
        self.details = []

    # Twistedy methods!
    def connectionLost(self, reason):
        Controller.disconnect_user(self.uname)
        if self.uname in self.users:
            del self.users[self.uname]
        self.uname = ''
        print(reason)

    def lineReceived(self, line):
        msg_split = line.split()
        if msg_split[0] == 'AUTH':
            if len(msg_split) != 2:
                self.sendLine("ERR 406 Invalid Parameters.")
                return
            self.handle_auth(msg_split[1])
        elif msg_split[0] == 'QUIT':
            self.transport.loseConnection()
        else:
            self.sendLine("ERR 452 Invalid Command")

    # Bookkeeping methods
    def handle_auth(self, uname):
        self.users[uname] = self
        self.uname = uname
        Controller.connect_user(uname, self.handle_data)
        self.auth = True

    def handle_data(self, json_data):
        if self.data_buffer:
            data = self.data_buffer + json_data
            self.data_buffer = ''
        try:
            data = json.loads(json_data)
        except ValueError:
            # We probably just didn't get all of it
            self.data_buffer = json_data
            return

        for ret_key in data:
            if ret_key in self.input_handlers:
                self.input_handlers[ret_key](data[ret_key])

    # Methods  to actually do something about the Nethack data
    def display(self, display_data):
        """
        This interprets `display` objects and tries to pass that information
        on to the user.
        """

        status_line = ''
        messages = []
        inventory = []
        pois = defaultdict(list)
{'fraction_non_alphanumeric': 0.08488120950323974, 'fraction_numerical': 0.004319654427645789, 'mean_word_length': 2.0110533159947983, 'pattern_counts': {'":': 0, '<': 3, '<?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': '199960', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1254, 'n_words': 341}