From 156084c225b8b23bff8270f14bf1ff653075d15c Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 17 Feb 2005 22:39:44 +0000 Subject: [PATCH] Fixed some bugs introduced with the latest refactoring of callCommand, etc. --- plugins/Config/plugin.py | 4 ++-- plugins/Ctcp/plugin.py | 4 ++-- plugins/Google/plugin.py | 4 ++-- plugins/ShrinkUrl/plugin.py | 4 ++-- src/callbacks.py | 23 ++++++++++++++++------- src/commands.py | 6 +++--- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/plugins/Config/plugin.py b/plugins/Config/plugin.py index e36698f94..46fb7481a 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -100,9 +100,9 @@ def getConfigVar(irc, msg, args, state): addConverter('configVar', getConfigVar) class Config(callbacks.Plugin): - def callCommand(self, method, irc, msg, *args, **kwargs): + def callCommand(self, command, irc, msg, *args, **kwargs): try: - super(Config, self).callCommand(method, irc, msg, *args, **kwargs) + super(Config, self).callCommand(command, irc, msg, *args, **kwargs) except registry.InvalidRegistryValue, e: irc.error(str(e)) diff --git a/plugins/Ctcp/plugin.py b/plugins/Ctcp/plugin.py index a165bb08e..6cbc5a3e3 100644 --- a/plugins/Ctcp/plugin.py +++ b/plugins/Ctcp/plugin.py @@ -47,7 +47,7 @@ class Ctcp(callbacks.PluginRegexp): self.ignores = ircutils.IrcDict() self.floods = ircutils.FloodQueue(60) - def callCommand(self, method, irc, msg, *args, **kwargs): + def callCommand(self, command, irc, msg, *args, **kwargs): if conf.supybot.abuse.flood.ctcp(): now = time.time() for (ignore, expiration) in self.ignores.items(): @@ -65,7 +65,7 @@ class Ctcp(callbacks.PluginRegexp): ignoreMask = '*!%s@%s' % (msg.user, msg.host) self.ignores[ignoreMask] = now + expires return - self.__parent.callCommand(method, irc, msg, *args, **kwargs) + self.__parent.callCommand(command, irc, msg, *args, **kwargs) def _reply(self, irc, msg, s): s = '\x01%s\x01' % s diff --git a/plugins/Google/plugin.py b/plugins/Google/plugin.py index 41fad1423..5073bdb16 100644 --- a/plugins/Google/plugin.py +++ b/plugins/Google/plugin.py @@ -108,9 +108,9 @@ class Google(callbacks.PluginRegexp): self.__parent.__init__(irc) google.setLicense(self.registryValue('licenseKey')) - def callCommand(self, method, irc, msg, *args, **kwargs): + def callCommand(self, command, irc, msg, *args, **kwargs): try: - self.__parent.callCommand(method, irc, msg, *args, **kwargs) + self.__parent.callCommand(command, irc, msg, *args, **kwargs) except xml.sax.SAXReaderNotAvailable, e: irc.error('No XML parser available.') diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index a5d6b9858..3e73d263c 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -76,9 +76,9 @@ class ShrinkUrl(callbacks.PluginRegexp): def die(self): self.db.close() - def callCommand(self, method, irc, msg, *args, **kwargs): + def callCommand(self, command, irc, msg, *args, **kwargs): try: - self.__parent.callCommand(method, irc, msg, *args, **kwargs) + self.__parent.callCommand(command, irc, msg, *args, **kwargs) except utils.web.Error, e: irc.error(str(e)) diff --git a/src/callbacks.py b/src/callbacks.py index fd876a294..bf9978902 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -884,12 +884,12 @@ class CommandThread(world.SupyThread): """ def __init__(self, target=None, args=(), kwargs={}): self.command = args[0] - self.__parent = super(CommandThread, self) - self.method = self.cb.getCommandMethod(self.command) + self.cb = target.im_self threadName = 'Thread #%s (for %s.%s)' % (world.threadsSpawned, - target.im_self.name(), + self.cb.name(), self.command) - log.debug('Spawning thread %s' % threadName) + log.debug('Spawning thread %s (args: %r)', threadName, args) + self.__parent = super(CommandThread, self) self.__parent.__init__(target=target, name=threadName, args=args, kwargs=kwargs) self.setDaemon(True) @@ -1016,15 +1016,24 @@ class Commands(object): commands.sort() return commands - def callCommand(self, method, irc, msg, *args, **kwargs): + def callCommand(self, command, irc, msg, *args, **kwargs): + method = self.getCommandMethod(command) method(irc, msg, *args, **kwargs) def _callCommand(self, command, irc, msg, *args, **kwargs): - method = self.getCommandMethod(command) + if command is None: + assert self.callingCommand, \ + 'Received command=None without self.callingCommand.' + command = self.callingCommand self.log.info('%s called by %s.', command, msg.prefix) try: - self.callCommand(method, irc, msg, *args, **kwargs) + try: + self.callingCommand = command + self.callCommand(command, irc, msg, *args, **kwargs) + finally: + self.callingCommand = None except (getopt.GetoptError, ArgumentError): + method = self.getCommandMethod(command) irc.reply(formatArgumentError(method, name=command)) except (SyntaxError, Error), e: self.log.debug('Error return: %s', utils.exnToString(e)) diff --git a/src/commands.py b/src/commands.py index 018d240f8..0b0fbdfe5 100644 --- a/src/commands.py +++ b/src/commands.py @@ -59,9 +59,9 @@ def thread(f): """Makes sure a command spawns a thread when called.""" def newf(self, irc, msg, args, *L, **kwargs): if world.isMainThread(): - t = callbacks.CommandThread(target=irc._callCommand, - args=(f.func_name, self), - kwargs=kwargs) + targetArgs = (self.callingCommand, irc, msg, args) + tuple(L) + t = callbacks.CommandThread(target=self._callCommand, + args=targetArgs, kwargs=kwargs) t.start() else: f(self, irc, msg, args, *L, **kwargs)