<commit_before>#!/usr/bin/env python

import random

from twisted.protocols import amp

port = 1234

_rand = random.Random()


class RollDice(amp.Command):
    arguments = [('sides', amp.Integer())]
    response = [('result', amp.Integer())]


class Dice(amp.AMP):
    def roll(self, sides=6):
        """Return a random integer from 1 to sides"""
        result = _rand.randint(1, sides)
        return {'result': result}
    RollDice.responder(roll)


def main():
    from twisted.internet import reactor
    from twisted.internet.protocol import Factory
    pf = Factory()
    pf.protocol = Dice
    reactor.listenTCP(port, pf)
    reactor.run()

if __name__ == '__main__':
    main()
<commit_msg>Add command-line option to set port.<commit_after>#!/usr/bin/env python

import random

from twisted.protocols import amp
from twisted.internet import reactor
from twisted.internet.protocol import Factory
from twisted.python import usage

port = 1234

_rand = random.Random()

class Options(usage.Options):
    optParameters = [
        ["port", "p", port, "server port"],
    ]

class RollDice(amp.Command):
    arguments = [('sides', amp.Integer())]
    response = [('result', amp.Integer())]


class Dice(amp.AMP):
    def roll(self, sides=6):
        """Return a random integer from 1 to sides"""
        result = _rand.randint(1, sides)
        return {'result': result}
    RollDice.responder(roll)


def main():
    options = Options()
    try:
        options.parseOptions()
    except usage.UsageError, err:
        print "%s: %s" % (sys.argv[0], err)
        print "%s: Try --help for usage details" % sys.argv[0]
        sys.exit(1)
    port = int(options["port"])

    pf = Factory()
    pf.protocol = Dice
    reactor.listenTCP(port, pf)
    reactor.run()

if __name__ == '__main__':
    main()

{'fraction_non_alphanumeric': 0.13827433628318583, 'fraction_numerical': 0.009402654867256638, 'mean_word_length': 3.0560538116591927, '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': '2073531', 'n_tokens_mistral': 605, 'n_tokens_neox': 576, 'n_words': 162}