<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    pyfire.zmq_forwarder

    This Class holds a forwarder implementation for ZMQs PUB/SUB messages as
    the included forwarder device does not work as espected.

:copyright: 2011 by the pyfire Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

import random
import zmq
from zmq.eventloop import ioloop, zmqstream

import pyfire.configuration as config
from pyfire.logger import Logger

log = Logger(__name__)


class ZMQForwarder(object):
    """ZMQ Forwarder class"""

    def __init__(self, event_loop = None):

        # use provided event_loop if provided
        self.own_loop = False
        if event_loop is None:
            self.loop = ioloop.IOLoop.instance()
            self.own_loop = True
        else:
            self.loop = event_loop

        self.ctx = zmq.Context()

        # Init command channel
        comm_sock = self.ctx.socket(zmq.REP)
        comm_sock.bind(config.get('ipc', 'forwarder_command_channel'))
        self.command_channel = zmqstream.ZMQStream(comm_sock, self.loop)
        self.command_channel.on_recv(self.register_peer)

        self.output_url = 'tcp://127.0.0.1:%i' % ( random.randint(15000,15500) )
        self.output = self.ctx.socket(zmq.PUB)
        self.output.bind(self.output_url)

    def start(self):
        """Starts the IOloop"""

        if self.own_loop:
            self.loop.start()

    def handle_stanza(self, msg):
        """Callback handler used for forwarding received stanzas"""

        for line in msg:<commit_msg>removed running in contect of a provided event_loop again, as it makes no sence<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    pyfire.zmq_forwarder

    This Class holds a forwarder implementation for ZMQs PUB/SUB messages as
    the included forwarder device does not work as espected.

:copyright: 2011 by the pyfire Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

import random
import zmq
from zmq.eventloop import ioloop, zmqstream

import pyfire.configuration as config
from pyfire.logger import Logger

log = Logger(__name__)


class ZMQForwarder(object):
    """ZMQ Forwarder class"""

    def __init__(self):
        self.loop = ioloop.IOLoop.instance()
        self.ctx = zmq.Context()

        # Init command channel
        comm_sock = self.ctx.socket(zmq.REP)
        comm_sock.bind(config.get('ipc', 'forwarder_command_channel'))
        self.command_channel = zmqstream.ZMQStream(comm_sock, self.loop)
        self.command_channel.on_recv(self.register_peer)

        self.output_url = 'tcp://127.0.0.1:%i' % ( random.randint(15000,15500) )
        self.output = self.ctx.socket(zmq.PUB)
        self.output.bind(self.output_url)

    def start(self):
        """Starts the IOloop"""

        if self.own_loop:
            self.loop.start()

    def handle_stanza(self, msg):
        """Callback handler used for forwarding received stanzas"""

        for line in msg:
{'fraction_non_alphanumeric': 0.10363036303630363, 'fraction_numerical': 0.013861386138613862, 'mean_word_length': 2.856234096692112, 'pattern_counts': {'":': 0, '<': 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': '479425', 'n_tokens_mistral': 986, 'n_tokens_neox': 928, 'n_words': 254}