<commit_before>import asyncio
import json

import logging
from nats.aio.client import Msg


def to_json(entity):
    return json.dumps(entity).encode('utf-8')


def wrap_exception(e):
    return to_json({'error': '%s: %s' % (e.__class__, str(e))})


# SUBSCRIBERS
async def client_echo_sub(msg: Msg, nats_server):
    # All instances of program will answering to this message
    await nats_server.nc.publish(msg.reply, nats_server.id)


async def get_info_sub(msg: Msg, nats_server):
    # Only one instance will send a answer
    try:
        await nats_server.nc.publish(msg.reply, to_json({'msg': 'Hello'}))
    except Exception as e:
        await nats_server.nc.publish(msg.reply, wrap_exception(e))

# MAIN CODE
def start():
    log = logging.getLogger(__name__)

    log.info("starting...")
    loop = asyncio.get_event_loop()
    nats_server = NatsHelper(loop, log)
    #
    nats_server.connect(username='admin', password='<PASSWORD>', host='localhost', port='4221')
    nats_server.subscribe("test.echo", cb=client_echo_sub)
    nats_server.subscribe("test.info", cb=get_info_sub, one_of=True)
    log.info("started")
    nats_server.start()
<commit_msg>Fix demo (package import)<commit_after>import asyncio
import json

import logging
from nats.aio.client import Msg

from nats_helper import NatsHelper


def to_json(entity):
    return json.dumps(entity).encode('utf-8')


def wrap_exception(e):
    return to_json({'error': '%s: %s' % (e.__class__, str(e))})


# SUBSCRIBERS
async def client_echo_sub(msg: Msg, nats_server):
    # All instances of program will answering to this message
    await nats_server.nc.publish(msg.reply, nats_server.id)


async def get_info_sub(msg: Msg, nats_server):
    # Only one instance will send a answer
    try:
        await nats_server.nc.publish(msg.reply, to_json({'msg': 'Hello'}))
    except Exception as e:
        await nats_server.nc.publish(msg.reply, wrap_exception(e))


# MAIN CODE
def start():
    log = logging.getLogger(__name__)

    log.info("starting...")
    loop = asyncio.get_event_loop()
    nats_server = NatsHelper(loop, log)
    #
    nats_server.connect(username='admin', password='<PASSWORD>', host='localhost', port='4221')
    nats_server.subscribe("test.echo", cb=client_echo_sub)
    nats_server.subscribe("test.info", cb=get_info_sub, one_of=True)
    log.info("started")
    nats_server.start()


if __name__ == '__main__':
    start()

{'fraction_non_alphanumeric': 0.1318181818181818, 'fraction_numerical': 0.004132231404958678, 'mean_word_length': 4.251626898047722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3695388', 'n_tokens_mistral': 851, 'n_tokens_neox': 835, 'n_words': 185}