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

import sys

from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientCreator
from twisted.protocols import amp
from twisted.python import usage

from diceserver import RollDice, port


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


def roll_die(host, port):
    clientcreator = ClientCreator(reactor, amp.AMP)
    d1 = clientcreator.connectTCP(host, port)
    d1.addCallback(lambda p: p.callRemote(RollDice, sides=6))
    d1.addCallback(lambda result: result['result'])
    def done(result):
        print 'Got roll:', result
        reactor.stop()
    d1.addCallback(done)
    d1.addErrback(failure)
<commit_msg>Make done a top-level function rather than a nested one.<commit_after>#!/usr/bin/env python

import sys

from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientCreator
from twisted.protocols import amp
from twisted.python import usage

from diceserver import RollDice, port


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

def done(result):
    print 'Got roll:', result
    reactor.stop()

def roll_die(host, port):
    clientcreator = ClientCreator(reactor, amp.AMP)
    d1 = clientcreator.connectTCP(host, port)
    d1.addCallback(lambda p: p.callRemote(RollDice, sides=6))
    d1.addCallback(lambda result: result['result'])
    d1.addCallback(done)
    d1.addErrback(failure)

{'fraction_non_alphanumeric': 0.11629315566323441, 'fraction_numerical': 0.0072683222289521504, 'mean_word_length': 3.6666666666666665, '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': '5779831', 'n_tokens_mistral': 521, 'n_tokens_neox': 503, 'n_words': 137}