1class Event(object):
2 pass
3
4class Observable(object):
5 def __init__(self):
6 self.callbacks = []
7 def subscribe(self, callback):
8 self.callbacks.append(callback)
9 def fire(self, **attrs):
10 e = Event()
11 e.source = self
12 for k, v in attrs.iteritems():
13 setattr(e, k, v)
14 for fn in self.callbacks:
15 fn(e)