Package: blinker_herald
Blinker HeraldThe Blinker Herald includes helpers to easily emit signals using the excelentblinkerlibrary.Decorate a function or method with@blinker_herald.emit()andpreandpostsignals will be automatically emitted to
all connected handlers.Free software: ISC licenseDocumentation:https://blinker_herald.readthedocs.org.FeaturesAll the features provided byblinker+an easy decorator@emit()to magically emit signals when your functions are called and before it returns a result.Asignalsnamespace proxy to discover the signals in your projectCustomizable for your needsUsageLet’s say you have a class and wants to emit a signal for a specific method:from blinker_herald import emit

class SomeClass(object):

    @emit()
    def do_something(self, arg1):
        # here is were magically the 'pre' signal will be sent
        return 'something done'
        # here is were magically the 'post' signal will be sentusing@emitdecorator makes blinker_herald to emit a signal for that method
and now you can connect handlers to capture that signalsYou can capturepresignal to manipulate the object:SomeClass.do_something.pre.connect
def handle_pre(sender, signal_emitter, **kwargs):
    signal_emitter.foo = 'bar'
    signal_emitter.do_another_thing()And you can also capture thepostsignal to log the results:SomeClass.do_something.post.connect
def handle_post(sender, signal_emitter, result, **kwargs):
    logger.info("The method {0} returned {1}".format(sender, result))You can also use the namespace proxyblinker_herald.signalsto connect
handlers to signals, the signal name is the prefixpreorpostfollowed by_and the method name:from blinker_herald import signals

@signals.pre_do_something.connect
def handle_pre(sender, signal_emitter, **kwargs):
    ...If you have a lot of subclasses emitting signals with the same name and you
need to capture only specific signals, you can specify that you want to listen
to only one type of sender:from blinker_herald import emit, signals, SENDER_CLASS
class BaseModel(object):
    ...
    @emit(sender=SENDER_CLASS)
    def create(self, **kwargs):
        new_instance = my_project.new(self, **kwargs)
        return new_instance

class One(BaseModel):
    pass

class Two(BaseModel):
    passNoteBy default the sender is always the instance but you can useSENDER_CLASSto force the sender to be theclassanother options areSENDER_CLASS_NAME,SENDER_MODULE,SENDER_NAMEand you can also pass a string, an object
or a lambda receiving thesenderinstance e.g:@emit(sender=lambda self: self.get_sender())UsingSENDER_CLASSyou can now connect to specific signal:from blinker_herald import signals

@signals.post_create.connect_via(One)
def handle_post_only_for_one(sender, signal_emitter, result, **kwargs):
    # sender is the class One (cls)
    # signal the instance of the class One (self)
    # result is the return of the method createThe above will handle thecreatemethod signal for the classOnebut not for the classTwoYou can also be more specific about the signal you want to connect using the__double underscore to provide method name:from blinker_herald import signals

@signals.module_name__ClassName__post_method_name.connect
def handle_post(sender, signal_emitter, result, **kwargs):
    ...The above will connect to thepostsignal emitted bymodule_name.ClassName.method_nameNoteYou don’t have to use the pattern above if your project do not have a lot of
method name collisions, using only the method name will be just fine for most cases.CreditsThis software was first created by SatelliteQE team to provide signals to
Robottelo and NailgunHistory0.1.0 (2016-05-28)First release on PyPI.