Fix the bugs in #1032945, Observer.list exceptions and exceptions when adding

an observer after a plugin reload.
This commit is contained in:
James Vega 2004-09-22 22:06:27 +00:00
parent ff86d2cccd
commit ed61675016
3 changed files with 23 additions and 11 deletions

View File

@ -56,11 +56,15 @@ def configure(advanced):
class Probability(registry.Float): class Probability(registry.Float):
"""Value must be a floating point number in the range (0, 1].""" """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): def setValue(self, v):
if not 0 < v <= 1: if not 0 < v <= 1:
self.error() self.error()
else: else:
super(Probability, self).setValue(v) self.__parent.setValue(v)
class Observers(registry.SpaceSeparatedListOfStrings): class Observers(registry.SpaceSeparatedListOfStrings):
List = callbacks.CanonicalNameSet List = callbacks.CanonicalNameSet
@ -103,9 +107,13 @@ class Observer(callbacks.Privmsg):
def _isValidObserverName(self, name): def _isValidObserverName(self, name):
return name != 'active' and registry.isValidRegistryName(name) return name != 'active' and registry.isValidRegistryName(name)
def __init__(self):
self.__parent = super(Observer, self)
self.__parent.__init__()
def callCommand(self, *args, **kwargs): def callCommand(self, *args, **kwargs):
self.commandCalled = True self.commandCalled = True
super(Observer, self).callCommand(*args, **kwargs) self.__parent.callCommand(*args, **kwargs)
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
if self.commandCalled: if self.commandCalled:
@ -152,7 +160,7 @@ class Observer(callbacks.Privmsg):
# We don't sort because order matters. # We don't sort because order matters.
else: else:
observers = self.registryValue('observers') observers = self.registryValue('observers')
utils.sortBy(str.lower, observers) observers = utils.sorted(observers, key=str.lower)
if observers: if observers:
irc.reply(utils.commaAndify(observers)) irc.reply(utils.commaAndify(observers))
else: else:

View File

@ -427,7 +427,7 @@ def sortBy(f, L):
def sorted(iterable, cmp=None, key=None, reversed=False): def sorted(iterable, cmp=None, key=None, reversed=False):
L = list(iterable) L = list(iterable)
if key is not None: 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) sortBy(key, L)
else: else:
L.sort(cmp) L.sort(cmp)

View File

@ -51,6 +51,10 @@ class ObserverTestCase(ChannelPluginTestCase):
self.assertResponse('testing, 1 2 3' , '1') self.assertResponse('testing, 1 2 3' , '1')
self.assertNotError('observer disable digits') 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: