The Blinker Herald includes helpers to easily emit signals using the excellent blinker library.

Overview

Blinker Herald

The Herald

https://travis-ci.org/SatelliteQE/blinker_herald.svg?branch=master Documentation Status Coverage

The Blinker Herald includes helpers to easily emit signals using the excelent blinker library.

Decorate a function or method with @blinker_herald.emit() and pre and post signals will be automatically emitted to all connected handlers.

Features

  • All the features provided by blinker
  • + an easy decorator @emit() to magically emit signals when your functions are called and before it returns a result.
  • A signals namespace proxy to discover the signals in your project
  • Customizable for your needs

Usage

Let'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 sent

using @emit decorator makes blinker_herald to emit a signal for that method and now you can connect handlers to capture that signals

You can capture pre signal 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 the post signal 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))

Note

Post-signals are only called if there were no exceptions raised during the processing of their related function.

You can also use the namespace proxy blinker_herald.signals to connect handlers to signals, the signal name is the prefix pre or post followed 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):
    pass

Note

By default the sender is always the instance but you can use SENDER_CLASS to force the sender to be the class another options are SENDER_CLASS_NAME, SENDER_MODULE, SENDER_NAME and you can also pass a string, an object or a lambda receiving the sender instance e.g: @emit(sender=lambda self: self.get_sender())

Using SENDER_CLASS you 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 create

The above will handle the create method signal for the class One but not for the class Two

You 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 the post signal emitted by module_name.ClassName.method_name

Note

You 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.

Credits

This software was first created by SatelliteQE team to provide signals to Robottelo and Nailgun

Owner
SatelliteQE
Projects related to the automation of Red Hat Satellite 6
SatelliteQE
🛠️ Plugin to integrate Chuy with Poetry

Archived This is bundled with Chuy since v1.3.0. Poetry Chuy Plugin This plugin integrates Chuy with Poetry. Note: This only works in Poetry 1.2.0 or

Eliaz Bobadilla 4 Sep 24, 2021
Repository for DNN training, theory to practice, part of the Large Scale Machine Learning class at Mines Paritech

DNN Training, from theory to practice This repository is complementary to the deep learning training lesson given to les Mines ParisTech on the 11th o

Alexandre Défossez 6 Nov 14, 2022
An easy FASTA object handler, reader, writer and translator for small to medium size projects without dependencies.

miniFASTA An easy FASTA object handler, reader, writer and translator for small to medium size projects without dependencies. Installation Using pip /

Jules Kreuer 3 Jun 30, 2022
プレヤフHackUチーム「キャット・タン」が作成したアプリ「illustection」

cat_tongue_illustection プレヤフHackUチーム「キャット・タン」が作成した, プライバシー保護アプリ「illustection」です! デモ動画 https://youtu.be/z3I7LuB_i58 機能 アップロードされた画像をいい感じのイラストやの素材に置き換える(

4 Jul 03, 2021
A Python utility belt containing simple tools, a stdlib like feel, and extra batteries. Hashing, Caching, Timing, Progress, and more made easy!

Ubelt is a small library of robust, tested, documented, and simple functions that extend the Python standard library. It has a flat API that all behav

Jon Crall 638 Dec 13, 2022
Tesla App Update Differences Extractor

Tesla App Update Differences Extractor Python program that finds the differences between two versions of the Tesla App. When Tesla updates the app a l

Adrian 5 Apr 11, 2022
🎅🏻 Helping santa understand ✨ python ✨

☃️ Advent of code 2021 ☃️ Helping santa understand ✨ python ✨

Fluffy 2 Dec 25, 2021
Python framework to build apps with the GASP metaphor

Gaspium Python framework to build apps with the GASP metaphor This project is part of the Pyrustic Open Ecosystem. Installation | Documentation | Late

5 Jan 01, 2023
Python tools for working with Orbit Ephemeris Messages (OEMs).

Python Orbit Ephemeris Message tools Python tools for working with Orbit Ephemeris Messages (OEMs). Development Status Installation The oem package is

Brad Sease 4 Apr 06, 2022
2 Way Sync Between Notion Database and Google Calendar

Notion-and-Google-Calendar-2-Way-Sync 2 Way Sync Between a Notion Database and Google Calendar WARNING: This repo will be undergoing a good bit of cha

248 Dec 26, 2022
An Airdrop alternative for cross-platform users only for desktop with Python

PyDrop An Airdrop alternative for cross-platform users only for desktop with Python, -version 1.0 with less effort, just as a practice. ##############

Bernardo Olisan 6 Mar 25, 2022
Supply Chain will be a SAAS platfom to provide e-logistic facilites with most optimal

Shipp It Welcome To Supply Chain App [ Shipp It ] In "Shipp It" we are creating a full solution[web+app] for a entire supply chain from receiving orde

SAIKAT_CLAW 25 Dec 26, 2022
Simple Denial of Service Program yang di bikin menggunakan bahasa pemograman Python,

Peringatan Tujuan kami share code Indo-DoS hanya untuk bertujuan edukasi / pembelajaran! Dilarang memperjual belikan source ini / memperjual-belikan s

SonLyte 8 Nov 07, 2021
For Tok-k passages that have passed through the Bi-Encoder Retrival, ReRank is performed using CrossEncoder.

Cross-Encoder-with-Bi-Encoder For Tok-k passages that have passed through the Bi-Encoder Retrival, ReRank is performed using CrossEncoder. Data Data u

7 Feb 09, 2022
This is an implementation of PEP 557, Data Classes.

This is an implementation of PEP 557, Data Classes. It is a backport for Python 3.6. Because dataclasses will be included in Python 3.7, any discussio

Eric V. Smith 561 Dec 06, 2022
Osintgram by Datalux but i fixed some errors i found and made it look cleaner

OSINTgram-V2 OSINTgram-V2 is made from Osintgram which is made by Datalux originally but i took the script and fixed some errors i found and made the

2 Feb 02, 2022
A web application which you can search, buy or sell shares with current prices which provided by IEX.

CS50 - Stock Exchange A web application which you can search, buy or sell shares with current prices which provided by IEX. Table of Contents Setup St

1 May 28, 2022
Projeto para ajudar no aprendizado da linguagem Pyhon

Economize Este projeto tem o intuito de criar desáfios para a codificação em Python, fazendo com que haja um maior entendimento da linguagem em seu to

Lucas Cunha Rodrigues 1 Dec 16, 2021
Some Python scripts that fx(hash) users might find useful.

fx_hash_utils Some Python scripts that fx(hash) users might find useful. get_images This script downloads all the static images of the tokens generate

30 Oct 05, 2022
A not exist cat image generator python package

A not exist cat image generator python package

Fayas Noushad 2 Dec 03, 2021