class Event object def __init__ self self _handlers def __call__ self

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Event(object):
def __init__(self):
self._handlers = []
def __call__(self, *args, **kwargs):
for h in self.handlers:
h(*args, **kwargs)
def __iadd__(self, handler):
if not callable(handler):
raise TypeError('Handler is not callable')
self._handlers.append(handler)
def __isub__(self, handler):
self._handlers.remove(handler)