Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaredly/registrar
A simple library for handling @registration of functions
https://github.com/jaredly/registrar
Last synced: 17 days ago
JSON representation
A simple library for handling @registration of functions
- Host: GitHub
- URL: https://github.com/jaredly/registrar
- Owner: jaredly
- Created: 2010-07-10T22:42:01.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-07-10T22:54:54.000Z (over 14 years ago)
- Last Synced: 2024-10-13T19:10:20.620Z (about 1 month ago)
- Language: Python
- Homepage: http://jaredforsyth.com/projects/registrar
- Size: 87.9 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
I often find myself writing meta decorators::
_reg = {}
def register(name):
def meta(func):
_reg[name] = func
return func
return metaOr some such thing. And that solution is very often enough. But, for the times when you need a bit more control, I've created ``Registrar``. The situation that prompted me to write this was within the confines of a class -- and the functions were being "registered" before they became bound...
Anyway, here's a sample of Registrar in action::
from registrar import NamedRegistrar
class Spam:
def __init__(self):
self.events = self._events.bind(self)# or
self.shop = Shoppe()
for event, value in self._events.bind(self):
self.show.addEventHandler(event, value[0], **value[2])## setup events
_events = NamedRegistrar()@_events('cheese', bubble=False)
def onCheese(self, baz):
pass
@_events('eggs')
def onEggs(self, baz):
return 'no eggs. cheese.'