event hooks for python
Project description
panglery is a library for writing hooks for events in python.
Here’s a basic example of usage:
import panglery p = panglery.Pangler() @p.subscribe(event='example', needs=['spam']) def example_hook(p, spam): print spam p.trigger(event='example', spam='eggs') # prints 'eggs'
And a little bit more involved:
@p.subscribe(needs=['spam'], returns=['spam']) def modify_spam_hook(p, spam): spam = spam + ' spam' return {'spam': spam} p.trigger(event='example', spam='eggs') # prints 'eggs spam'
Hooks can also add parameters to an event which then trigger other hooks:
p = panglery.Pangler() @p.subscribe(needs=['spam'], returns=['eggs']) def make_eggs_hook(p, spam): eggs = spam + ' eggs' return {'eggs': eggs} @p.subscribe(event='example', needs=['eggs']): def eggs_hook(p, eggs): print eggs p.trigger(event='example', spam='eggs') # prints 'eggs eggs'
PanglerAggregates can be used to aggregate together multiple Panglers across all superclasses:
class ExampleBase(object): p = panglery.PanglerAggregate('hooks') hooks = panglery.Pangler() @hooks.subscribe(event='example') def example_hook_base(self, p): print 'spam' class ExampleDerived(ExampleBase): hooks = panglery.Pangler() @hooks.subscribe(event='example') def example_hook_derived(self, p): print 'eggs' inst = ExampleDerived() inst.p().trigger(event='example') # prints 'spam' and 'eggs' in some order.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
panglery-1.tar.gz
(5.9 kB
view details)
File details
Details for the file panglery-1.tar.gz
.
File metadata
- Download URL: panglery-1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68820c865338a592246e67a09c46336977c7cf579d70d06f754ea7947e7e0db |
|
MD5 | 693ba191372ecacb82e7bfa971e2bfa6 |
|
BLAKE2b-256 | 9b6f62e6c9881d271d8e9201fa16aa374aff6cf5886bcec06e9c5ab3870828c9 |