From ed61675016332078de25192d113c530c50556a57 Mon Sep 17 00:00:00 2001 From: James Vega Date: Wed, 22 Sep 2004 22:06:27 +0000 Subject: [PATCH] Fix the bugs in #1032945, Observer.list exceptions and exceptions when adding an observer after a plugin reload. --- plugins/Observer.py | 28 ++++++++++++++++++---------- src/utils.py | 2 +- test/test_Observer.py | 4 ++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/plugins/Observer.py b/plugins/Observer.py index ec0c25ca0..53014036f 100644 --- a/plugins/Observer.py +++ b/plugins/Observer.py @@ -56,11 +56,15 @@ def configure(advanced): class Probability(registry.Float): """Value must be a floating point number in the range (0, 1].""" + def __init__(self, *args, **kwargs): + self.__parent = super(Probability, self) + self.__parent.__init__(*args, **kwargs) + def setValue(self, v): if not 0 < v <= 1: self.error() else: - super(Probability, self).setValue(v) + self.__parent.setValue(v) class Observers(registry.SpaceSeparatedListOfStrings): List = callbacks.CanonicalNameSet @@ -77,7 +81,7 @@ conf.registerGlobalValue(conf.supybot.plugins.Observer, 'observers', conf.registerChannelValue(conf.supybot.plugins.Observer.observers, 'active', ActiveObservers([], """Determines what observers are active on a channel.""")) - + def registerObserver(name, regexpString='', commandString='', probability=1.0): @@ -102,11 +106,15 @@ class Observer(callbacks.Privmsg): commandCalled = False def _isValidObserverName(self, name): return name != 'active' and registry.isValidRegistryName(name) - + + def __init__(self): + self.__parent = super(Observer, self) + self.__parent.__init__() + def callCommand(self, *args, **kwargs): self.commandCalled = True - super(Observer, self).callCommand(*args, **kwargs) - + self.__parent.callCommand(*args, **kwargs) + def doPrivmsg(self, irc, msg): if self.commandCalled: self.commandCalled = False @@ -134,7 +142,7 @@ class Observer(callbacks.Privmsg): command = command.replace('$%s' % i, group) tokens = callbacks.tokenize(command, channel=channel) Owner.processTokens(irc, msg, tokens) - + def list(self, irc, msg, args): """[] @@ -152,7 +160,7 @@ class Observer(callbacks.Privmsg): # We don't sort because order matters. else: observers = self.registryValue('observers') - utils.sortBy(str.lower, observers) + observers = utils.sorted(observers, key=str.lower) if observers: irc.reply(utils.commaAndify(observers)) else: @@ -184,7 +192,7 @@ class Observer(callbacks.Privmsg): except (KeyError, ValueError): irc.error('The observer %s was not active on %s.' % (name,channel)) disable = privmsgs.checkChannelCapability(disable, 'op') - + def info(self, irc, msg, args): """ @@ -200,7 +208,7 @@ class Observer(callbacks.Privmsg): irc.reply('%s matches the regular expression %s and ' 'runs the command %s with a probability of %s' % (name, regexp, command, probability)) - + def add(self, irc, msg, args): """ [] @@ -232,7 +240,7 @@ class Observer(callbacks.Privmsg): """ pass - + Class = Observer diff --git a/src/utils.py b/src/utils.py index 8fae97d7a..57b741fcb 100755 --- a/src/utils.py +++ b/src/utils.py @@ -427,7 +427,7 @@ def sortBy(f, L): def sorted(iterable, cmp=None, key=None, reversed=False): L = list(iterable) if key is not None: - assert cmp is not None, 'Can\'t use both cmp and key.' + assert cmp is None, 'Can\'t use both cmp and key.' sortBy(key, L) else: L.sort(cmp) diff --git a/test/test_Observer.py b/test/test_Observer.py index 306089c00..94e7cad07 100644 --- a/test/test_Observer.py +++ b/test/test_Observer.py @@ -51,6 +51,10 @@ class ObserverTestCase(ChannelPluginTestCase): self.assertResponse('testing, 1 2 3' , '1') self.assertNotError('observer disable digits') + def testList(self): + self.assertNotError('add foo m/foo/i echo I saw foo.') + self.assertRegexp('observer list', 'foo') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: