Irc.callbacks is always mutated, never replaced, helping the Relay module out.

This commit is contained in:
Jeremy Fincher 2003-03-27 11:29:42 +00:00
parent 37b9342178
commit 714de6bfae

View File

@ -245,10 +245,10 @@ class Irc(object):
self.prefix = '' self.prefix = ''
self.user = user or nick # Default to nick if user isn't provided. self.user = user or nick # Default to nick if user isn't provided.
self.ident = ident or nick # Ditto. self.ident = ident or nick # Ditto.
self.callbacks = [] if callbacks is None:
if callbacks is not None: self.callbacks = []
for callback in callbacks: else:
self.addCallback(callback) self.callbacks = callbacks
self._nickmods = copy.copy(conf.nickmods) self._nickmods = copy.copy(conf.nickmods)
self.state = IrcState() self.state = IrcState()
self.queue = IrcMsgQueue() self.queue = IrcMsgQueue()
@ -274,11 +274,15 @@ class Irc(object):
def removeCallback(self, name): def removeCallback(self, name):
ret = [] ret = []
toRemove = []
for (i, cb) in enumerate(self.callbacks): for (i, cb) in enumerate(self.callbacks):
if cb.name() == name: if cb.name() == name:
ret.append(self.callbacks[i]) toRemove.append(i)
self.callbacks[i] = None if toRemove:
self.callbacks = [cb for cb in self.callbacks if cb is not None] for i in reviter(range(len(self.callbacks))):
if toRemove[-1] == i:
toRemove.pop()
ret.append(self.callbacks.pop(i))
return ret return ret
def queueMsg(self, msg): def queueMsg(self, msg):