"""
    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:
    return _global_dispatcher.save_emit(signal, *arguments, **named)

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)



@@ -835,16 +835,42 @@
 urn %5B%5D%0A%0A
+global _global_dispatcher%0A
 _global_
@@ -930,16 +930,145 @@
 l = %7B%7D%0A%0A
+def _display_deprecation_warning():%0A    warnings.warn(%22extern.louie will soon be deprecated in favor of coherence.dispatcher.%22)%0A%0A
 def conn
@@ -1295,83 +1295,37 @@
     
-warnings.warn(%22Seriously! Use the coherence.dispatcher. It IS object based%22
+_display_deprecation_warning(
 )%0A  
@@ -1700,83 +1700,37 @@
     
-warnings.warn(%22Seriously! Use the coherence.dispatcher. It IS object based%22
+_display_deprecation_warning(
 )%0A  
@@ -2063,83 +2063,37 @@
     
-warnings.warn(%22Seriously! Use the coherence.dispatcher. It IS object based%22
+_display_deprecation_warning(
 )%0A  

make the dispatcher a global variable and the deprecation warning more developer friendly