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

from optparse import OptionParser

from circuits.node import Node, remote, protocol
from circuits import Component, Debugger, Event


__version__ = "0.0.1"

USAGE = "%prog [options]"
VERSION = "%prog v" + __version__


class increment(Event):
    def __init__(self, value):
        Event.__init__(self, value)


def parse_options():
    parser = OptionParser(usage=USAGE, version=VERSION)

    parser.add_option(
        "-i", "--ip",
        action="store", type="string",
        default="127.0.0.1:8000", dest="bind",
        help="Bind to address:[port]"
    )

    parser.add_option(
        "-d", "--debug",
        action="store_true",
        default=False, dest="debug",
        help="Enable debug mode"
    )

    opts, args = parser.parse_args()

    return opts, args


class NodeClient(Component):
    def init(self, args, opts):
        if opts.debug:
            Debugger().register(self)

        if ":" in opts.bind:
            address, port = opts.bind.split(":")
            port = int(port)
        else:
            address, port = opts.bind, 8000

        node = Node().register(self)
        node.add('peer_name', address, port)

    def ready(self, client):
        i = 0
        while True:
            print(i)
            i = (yield self.call(remote(increment(i), 'peer_name'))).value


def main():
    opts, args = parse_options()

    # Configure and "run" the System.
    NodeClient(args, opts).run()


if __name__ == "__main__":
    main()<commit_msg>Node example: use "connected_to" handler<commit_after>#!/usr/bin/env python

from optparse import OptionParser

from circuits.node import Node, remote, protocol
from circuits import Component, Debugger, Event


__version__ = "0.0.1"

USAGE = "%prog [options]"
VERSION = "%prog v" + __version__


class increment(Event):
    def __init__(self, value):
        Event.__init__(self, value)


def parse_options():
    parser = OptionParser(usage=USAGE, version=VERSION)

    parser.add_option(
        "-i", "--ip",
        action="store", type="string",
        default="127.0.0.1:8000", dest="bind",
        help="Bind to address:[port]"
    )

    parser.add_option(
        "-d", "--debug",
        action="store_true",
        default=False, dest="debug",
        help="Enable debug mode"
    )

    opts, args = parser.parse_args()

    return opts, args


class NodeClient(Component):
    def init(self, args, opts):
        if opts.debug:
            Debugger().register(self)

        if ":" in opts.bind:
            address, port = opts.bind.split(":")
            port = int(port)
        else:
            address, port = opts.bind, 8000

        node = Node().register(self)
        node.add('peer_name', address, port)

    def connected_to(self, *args, **kwargs):
        i = 0
        while True:
            print(i)
            i = (yield self.call(remote(increment(i), 'peer_name'))).value


def main():
    opts, args = parse_options()

    # Configure and "run" the System.
    NodeClient(args, opts).run()


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.14100486223662884, 'fraction_numerical': 0.011669367909238249, 'mean_word_length': 2.43652561247216, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3497329', 'n_tokens_mistral': 998, 'n_tokens_neox': 933, 'n_words': 242}