1
'''This module manages events and evet handlers'''
4
def register_handler(self, handler):
5
'''Register an event handler'''
6
if isinstance(handler, Handler):
7
event_handlers.append(handler)
9
raise Exception('Object must be a subclass of libs.events.Handler')
11
def unregister_handler(self, handler):
12
'''Unregister an event handler'''
13
event_handlers.remove(handler)
15
class Handler(object):
16
'''Base handler class. Provides default methods to handle events. This must
17
be used by all modules and is done to ensure compatibility.'''
18
def got_message(self, message):
19
'''Called when a message is recieved'''
22
def got_connect(self, connection):
23
'''Called when we get or establish a connection'''
26
class Logger(Handler):
27
'''Print events as they happen. TODO: Write to a log file'''
28
def got_message(self, message):
29
self._output('Got a message')
31
def got_connect(self, connection):
32
self._output('Got a connection')
34
def _output(self, message):
35
print('[*] %s' % message)