<commit_before>from twisted.internet import protocol, reactor, endpoints
from twisted.protocols.basic import Int16StringReceiver


class Echo(Int16StringReceiver):
    def __init__(self, position):
        self.position = position

    def stringReceived(self, data):
        peer = self.transport.getPeer()

        self.updatePosition(data)
        print "[{ip}:{port}] '{msg}'".format(ip=peer.host, port=peer.port,
                                             msg=data)
        self.sendString(data)
        self.sendString('Player position is now {0}'.format(self.position))
        # self.transport.loseConnection()

    def updatePosition(self, data):
        command = data.lower().strip()

        oldX, oldY = self.position
        updateX, updateY = {
            'n':       [    0,     1],
            'north':   [    0,     1],
            's':       [    0,    -1],
            'south':   [    0,    -1],
            'e':       [    1,     0],
            'east':    [    1,     0],
            'west':    [   -1,     0],
            'start9':  [-oldX, -oldY],
        }.get(command, [    0,     0])
        
        self.position[0] += updateX
        self.position[1] += updateY

class EchoFactory(protocol.Factory):
    def __init__(self, *args, **kwargs):
        # TODO: Use a real object with real methods here.
        self.position = [0, 0]

    def buildProtocol(self, addr):
        return Echo(self.position)


def runEchoServer():
    endpoints.serverFromString(reactor, 'tcp:50000').listen(EchoFactory())
    reactor.run()<commit_msg>Added westward motion.<commit_after>from twisted.internet import protocol, reactor, endpoints
from twisted.protocols.basic import Int16StringReceiver


class Echo(Int16StringReceiver):
    def __init__(self, position):
        self.position = position

    def stringReceived(self, data):
        peer = self.transport.getPeer()

        self.updatePosition(data)
        print "[{ip}:{port}] '{msg}'".format(ip=peer.host, port=peer.port,
                                             msg=data)
        self.sendString(data)
        self.sendString('Player position is now {0}'.format(self.position))
        # self.transport.loseConnection()

    def updatePosition(self, data):
        command = data.lower().strip()

        oldX, oldY = self.position
        updateX, updateY = {
            'n':       [    0,     1],
            'north':   [    0,     1],
            'up':      [    0,     1],
            's':       [    0,    -1],
            'south':   [    0,    -1],
            'down':    [    0,    -1],
            'e':       [    1,     0],
            'east':    [    1,     0],
            'right':   [    1,     0],
            'w':       [   -1,     0],
            'west':    [   -1,     0],
            'left':    [   -1,     0],
            'start9':  [-oldX, -oldY],
        }.get(command, [    0,     0])
        
        self.position[0] += updateX
        self.position[1] += updateY

class EchoFactory(protocol.Factory):
    def __init__(self, *args, **kwargs):
        # TODO: Use a real object with real methods here.
        self.position = [0, 0]

    def buildProtocol(self, addr):
        return Echo(self.position)


def runEchoServer():
    endpoints.serverFromString(reactor, 'tcp:50000').listen(EchoFactory())
    reactor.run()
{'fraction_non_alphanumeric': 0.13929001203369434, 'fraction_numerical': 0.021660649819494584, 'mean_word_length': 1.6685393258426966, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '80210', 'n_tokens_mistral': 1028, 'n_tokens_neox': 983, 'n_words': 224}