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
Participants of Bertelsmann Technology Scholarship created an awesome list of resources and they want to share it with the world, if you find illegal resources please report to us and we will remove.

Participants of Bertelsmann Technology Scholarship created an awesome list of resources and they want to share it with the world, if you find illegal

Wissem Marzouki 29 Nov 28, 2022
适用于HoshinoBot下的人生重来模拟器插件

LifeRestart for HoshinoBot 原作地址 python版原地址 本项目地址 安装方法 这是一个HoshinoBot的人生重来模拟器插件 这个项目使用的HoshinoBot的消息触发器,如果你了解其他机器人框架的api(比如nonebot)可以只修改消息触发器就将本项目移植到其他

黛笙笙 16 Sep 03, 2022
Convert your Gyrosco.pe travels to GPX files

gyroscope2gpx This little python joint will do you a favor of taking your "Travel" export from Gyroscope (https://gyrosco.pe) and turn it into a bunch

nick g 4 Oct 02, 2022
pyRTOS is a real-time operating system (RTOS), written in Python.

pyRTOS Introduction pyRTOS is a real-time operating system (RTOS), written in Python. The primary goal of pyRTOS is to provide a pure Python RTOS that

Ben Williams 96 Dec 30, 2022
A collection of convenient parsers for Advent of Code problems.

Advent of Code Parsers A collection of convenient Python parsers for Advent of Code problems. Installation pip install aocp Quickstart You can import

Miguel Blanco Marcos 3 Dec 13, 2021
Remove Sheet Protection from .xlsx files. Easily.

🔓 Excel Sheet Unlocker Remove sheet protection from .xlsx files. How to use Run Run the script/packaged executable from the command line. Universal u

Daniel 3 Nov 16, 2022
Easily map device and application controls to a midi controller

pymidicontroller Introduction Easily map device and application controls to a midi controller

Tane Barriball 24 May 16, 2022
GibMacOS - Py2/py3 script that can download macOS components direct from Apple

Py2/py3 script that can download macOS components direct from Apple Can also now build Internet Recovery USB installers from Windows using dd and 7zip

CorpNewt 4.8k Jan 02, 2023
A repository containing useful resources needed to complete the SUSE Scholarship Challenge #UdacitySUSEScholars #poweredbySUSE

SUSE-udacity-cloud-native-scholarship A repository containing useful resources needed to complete the SUSE Scholarship Challenge #UdacitySUSEScholars

Nandini Proothi 11 Dec 02, 2021
Example applications, dashboards, scripts, notebooks, and other utilities built using Polygon.io

Polygon.io Examples Example applications, dashboards, scripts, notebooks, and other utilities built using Polygon.io. Examples Preview Name Type Langu

Tim Paine 4 Jun 01, 2022
Null safe support for Python

Null Safe Python Null safe support for Python. Installation pip install nullsafe Quick Start Dummy Class class Dummy: pass Normal Python code: o =

Paaksing 13 Nov 17, 2022
PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standard Library.

PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standar

Collage Labs 10 Nov 19, 2022
Converts a base copy of Pokemon BDSP's masterdatas into a more readable and editable Pokemon Showdown Format.

Showdown-BDSP-Converter Converts a base copy of Pokemon BDSP's masterdatas into a more readable and editable Pokemon Showdown Format. Download the lat

Alden Mo 2 Jan 02, 2022
Simple calculator with random number button and dark gray theme created with PyQt6

Calculator Application Simple calculator with random number button and dark gray theme created with : PyQt6 Python 3.9.7 you can download the dark gra

Flamingo 2 Mar 07, 2022
Semester long, web application project for CSCI 4370/6370 (Database Management)

Database_Project Prototype ideas for website: Computer Science library (Sells books, products, etc.) Code editor Graph visualizer / creator (can save

Jordan Harman 4 Feb 17, 2022
A community-driven python bot that aims to be as simple as possible to serve humans with their everyday tasks

JARVIS on Messenger Just A Rather Very Intelligent System, now on Messenger! Messenger is now used by 1.2 billion people every month. With the launch

Swapnil Agarwal 1.3k Jan 07, 2023
This module is for finding the execution time of a whole python program

exetime 3.8 This module is for finding the execution time of a whole program How to install $ pip install exetime Contents: General Information Instru

Saikat Das 4 Oct 18, 2021
LibreMind is a free meditation app made in under 24 hours. It has various meditation, breathwork, and visualization exercises.

libreMind Meditation exercises What is it? LibreMind is a free meditation app made in under 24 hours. It has various meditation, breathwork, and visua

1 May 24, 2022
A small Blender addon for changing an object's local orientation while in edit mode

A small Blender addon for changing an object's local orientation while in edit mode.

Jonathan Lampel 50 Jan 06, 2023
Rename and categorize your DMOJ solutions

DMOJ Downloader What is this for? DMOJ lets you download the code for all your solutions, however the files are just named as numbers

Evan Wild 1 Dec 04, 2022