def unregister(self, variables): """Unregister all willie callables in variables, and their bindings. When unloading a module, this ensures that the unloaded modules will not get called and that the objects can be garbage collected. Objects that have not been registered are ignored. Args: variables -- A list of callable objects from a willie module. """ def remove_func(func, commands): """Remove all traces of func from commands.""" for func_list in commands.itervalues(): if func in func_list: func_list.remove(func) hostmask = "%s!%s@%s" % (self.nick, self.user, socket.gethostname()) willie = self.WillieWrapper(self, irc.Origin(self, hostmask, [])) for obj in variables.itervalues(): if obj in self.callables: self.callables.remove(obj) for commands in self.commands.itervalues(): remove_func(obj, commands) if obj in self.shutdown_methods: try: obj(willie) except Exception as e: stderr("Error calling shutdown method for module %s:%s" % (obj.__module__, e)) self.shutdown_methods.remove(obj)
def test_privmsg(self): source = "[email protected]" args = ['PRIVMSG', '#phenny'] origin = irc.Origin(self.bot, source, args) self.assertEqual(origin.nick, 'Foobar') self.assertEqual(origin.user, 'foo') self.assertEqual(origin.host, 'bar.example.com') self.assertEqual(origin.sender, '#phenny')
def message(jenni, hostmask, room, msg): origin = irc.Origin( jenni, hostmask, [ "PRIVMSG", room, msg, ] ) jenni.dispatch(origin, [ msg, 'PRIVMSG', ])
def _shutdown(self): stderr('Calling shutdown for %d modules.' % (len(self.shutdown_methods), )) hostmask = "%s!%s@%s" % (self.nick, self.user, socket.gethostname()) willie = self.WillieWrapper(self, irc.Origin(self, hostmask, [])) for shutdown_method in self.shutdown_methods: try: stderr("calling %s.%s" % ( shutdown_method.__module__, shutdown_method.__name__, )) shutdown_method(willie) except Exception as e: stderr("Error calling shutdown method for module %s:%s" % (shutdown_method.__module__, e))
def test_server(self): source = "foobar.example.com" origin = irc.Origin(self.bot, source, []) self.assertEqual(origin.host, '')