<commit_before>"""
Wrapper module for the louie implementation
"""

import warnings
from coherence.dispatcher import Dispatcher

class Any(object): pass
class All(object): pass
class Anonymous(object): pass

# fake the API 
class Dummy(object): pass
signal = Dummy()
sender = Dummy()

#senders
sender.Anonymous = Anonymous
sender.Any = Any

#signals
signal.All = All

# a slightly less raise-y-ish implementation as louie was not so picky, too
class GlobalDispatcher(Dispatcher):

    def connect(self, signal, callback, *args, **kw):
        if not signal in self.receivers:
            # ugly hack
            self.receivers[signal] = []
        return Dispatcher.connect(self, signal, callback, *args, **kw)

    def _get_receivers(self, signal):
        try:
            return self.receivers[signal]
        except KeyError:
            return []

_global_dispatcher = GlobalDispatcher()
_global_receivers_pool = {}

def connect(receiver, signal=All, sender=Any, weak=True):
    callback = receiver
    if signal in (Any, All):
        raise NotImplemented("This is not allowed. Signal HAS to be something")
    if sender not in (Any, All):
        warnings.warn("Seriously! Use the coherence.dispatcher. It IS object based")
    receiver = _global_dispatcher.connect(signal, callback)
    _global_receivers_pool[(callback, signal)] = receiver
    return receiver

def disconnect(receiver, signal=All, sender=Any, weak=True):
    callback = receiver
    if signal in (Any, All):
        raise NotImplemented("This is not allowed. Signal HAS to be something")
    if sender not in (Any, All):
        warnings.warn("Seriously! Use the coherence.dispatcher. It IS object based")
    receiver = _global_receivers_pool.pop((callback, signal))
    return _global_dispatcher.disconnect(receiver)

def send(signal=All, sender=Anonymous, *arguments, **named):
    if signal in (Any, All):
        raise NotImplemented("This is not allowed. Signal HAS to be something")
    if sender not in (Anonymous, None):
        warnings.warn("Seriously! Use the coherence.dispatcher. It IS object based")
    # the first value of the callback shall always be the signal:
    results, errors = _global_dispatcher.emit(signal, *arguments, **named)
    if errors:
        warnings.warn('Erros while processing %s: %r' % (signal, errors)

def send_minimal(signal=All, sender=Anonymous, *arguments, **named):
    return send(signal, sender, *arguments, **named)

def send_exact(signal=All, sender=Anonymous, *arguments, **named):
    return send(signal, sender, *arguments, **named)

def send_robust(signal=All, sender=Anonymous, *arguments, **named):
    return send(signal, sender, *arguments, **named)

<commit_msg>small syntax fix in the louie wrapper<commit_after>"""
Wrapper module for the louie implementation
"""

import warnings
from coherence.dispatcher import Dispatcher

class Any(object): pass
class All(object): pass
class Anonymous(object): pass

# fake the API 
class Dummy(object): pass
signal = Dummy()
sender = Dummy()

#senders
sender.Anonymous = Anonymous
sender.Any = Any

#signals
signal.All = All

# a slightly less raise-y-ish implementation as louie was not so picky, too
class GlobalDispatcher(Dispatcher):

    def connect(self, signal, callback, *args, **kw):
        if not signal in self.receivers:
            # ugly hack
            self.receivers[signal] = []
        return Dispatcher.connect(self, signal, callback, *args, **kw)

    def _get_receivers(self, signal):
        try:
            return self.receivers[signal]
        except KeyError:
            return []

_global_dispatcher = GlobalDispatcher()
_global_receivers_pool = {}

def connect(receiver, signal=All, sender=Any, weak=True):
    callback = receiver
    if signal in (Any, All):
        raise NotImplemented("This is not allowed. Signal HAS to be something")
    if sender not in (Any, All):
        warnings.warn("Seriously! Use the coherence.dispatcher. It IS object based")
    receiver = _global_dispatcher.connect(signal, callback)
    _global_receivers_pool[(callback, signal)] = receiver
    return receiver

def disconnect(receiver, signal=All, sender=Any, weak=True):
    callback = receiver
    if signal in (Any, All):
        raise NotImplemented("This is not allowed. Signal HAS to be something")
    if sender not in (Any, All):
        warnings.warn("Seriously! Use the coherence.dispatcher. It IS object based")
    receiver = _global_receivers_pool.pop((callback, signal))
    return _global_dispatcher.disconnect(receiver)

def send(signal=All, sender=Anonymous, *arguments, **named):
    if signal in (Any, All):
        raise NotImplemented("This is not allowed. Signal HAS to be something")
    if sender not in (Anonymous, None):
        warnings.warn("Seriously! Use the coherence.dispatcher. It IS object based")
    # the first value of the callback shall always be the signal:
    results, errors = _global_dispatcher.emit(signal, *arguments, **named)
    if errors:
        warnings.warn('Erros while processing %s: %r' % (signal, errors))

def send_minimal(signal=All, sender=Anonymous, *arguments, **named):
    return send(signal, sender, *arguments, **named)

def send_exact(signal=All, sender=Anonymous, *arguments, **named):
    return send(signal, sender, *arguments, **named)

def send_robust(signal=All, sender=Anonymous, *arguments, **named):
    return send(signal, sender, *arguments, **named)


{'fraction_non_alphanumeric': 0.10566107320671216, 'fraction_numerical': 0.0, 'mean_word_length': 3.9264305177111716, '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': '5184277', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1538, 'n_words': 526}