<commit_before>"""
Forward notification

This is a simple forwarder bridge

Config Example:
[regrowl.bridge.forward]
host = 127.0.0.1
pass = <PASSWORD>
"""

from __future__ import absolute_import

import logging

from gntp.notifier import GrowlNotifier
from regrowl.regrowler import ReGrowler
from regrowl.config import DEFAULTS

logger = logging.getLogger(__name__)

# Ignore debug logging from lower level growl library
logging.getLogger('gntp.notifier').setLevel(logging.INFO)

__all__ = ['ForwardNotifier']


class ForwardNotifier(ReGrowler):
    valid = ['REGISTER', 'NOTIFY']

    def forward(self, messagetype, packet):
        self.password = self.get('pass')
        self.passwordHash = self.get('passwordHash', DEFAULTS['passwordHash'])
        self.host = self.get('host')
        self.port = self.getint('port', DEFAULTS['port'])

        packet.set_password(self.password, self.passwordHash)

        logger.info('Forwarding %s to %s:%s', messagetype, self.host, self.port)

        self.growler = GrowlNotifier(
            hostname=self.host,
            port=self.port,
        )._send(messagetype, packet)

    def register(self, packet):
        self.forward('REGISTER', packet)

    def notify(self, packet):
        self.forward('NOTIFY', packet)<commit_msg>Update regrowl.bridge.forward to use similar list rules as regrowl.bridge.push<commit_after>"""
Forward notification

This is a simple forwarder bridge

Config Example:
[regrowl.bridge.forward]
label = host,password
other = host:port,password
"""

from __future__ import absolute_import

import logging

from gntp.notifier import GrowlNotifier
from regrowl.regrowler import ReGrowler
from regrowl.config import DEFAULTS

logger = logging.getLogger(__name__)

# Ignore debug logging from lower level growl library
logging.getLogger('gntp.notifier').setLevel(logging.INFO)

__all__ = ['ForwardNotifier']


class ForwardNotifier(ReGrowler):
    valid = ['REGISTER', 'NOTIFY']

    def forward(self, packet):
        messagetype = packet.info['messagetype']
        for label, settings in self.config.items(__name__):
            dest, password = settings.split(',')
            try:
                host, port = dest.split(':')
            except ValueError:
                host, port = dest, DEFAULTS['port']

            passwordHash = self.get('passwordHash', DEFAULTS['passwordHash'])

            packet.set_password(password, passwordHash)

            logger.info('Forwarding %s to %s:%s', messagetype, host, port)

            GrowlNotifier(
                hostname=host,
                port=port,
            )._send(messagetype, packet)

    def register(self, packet):
        self.forward(packet)

    def notify(self, packet):
        self.forward(packet)
{'fraction_non_alphanumeric': 0.10961398397669338, 'fraction_numerical': 0.0021849963583394027, 'mean_word_length': 3.285491419656786, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '631417', 'n_tokens_mistral': 831, 'n_tokens_neox': 803, 'n_words': 198}