mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Fixed handling of callbacks.ArgumentError in PrivmsgCommandAndRegexp.
This commit is contained in:
parent
7815d2c0b6
commit
0b6c2084cf
@ -756,12 +756,16 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
||||
self.res.sort(lambda (r1, m1), (r2, m2): cmp(m1.__name__, m2.__name__))
|
||||
self.addressedRes.sort(lambda (r1, m1), (r2, m2): cmp(m1.__name__,
|
||||
m2.__name__))
|
||||
def callCommand(self, f, irc, msg, *L):
|
||||
|
||||
def callCommand(self, f, irc, msg, *L, **kwargs):
|
||||
try:
|
||||
Privmsg.callCommand(self, f, irc, msg, *L)
|
||||
except Exception, e:
|
||||
irc.error(msg, debug.exnToString(e))
|
||||
debug.recoverableException()
|
||||
if 'catchErrors' in kwargs and kwargs['catchErrors']:
|
||||
irc.error(msg, debug.exnToString(e))
|
||||
debug.recoverableException()
|
||||
else:
|
||||
raise
|
||||
|
||||
def doPrivmsg(self, irc, msg):
|
||||
if ircdb.checkIgnored(msg.prefix, msg.args[0]):
|
||||
@ -775,7 +779,7 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
||||
msg = self.rateLimiter.get()
|
||||
if msg:
|
||||
proxy = IrcObjectProxyRegexp(irc)
|
||||
self.callCommand(method, proxy, msg, m)
|
||||
self.callCommand(method, proxy, msg, m, catchErrors=True)
|
||||
s = addressed(irc.nick, msg)
|
||||
if s:
|
||||
for (r, method) in self.addressedRes:
|
||||
@ -786,7 +790,7 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
||||
msg = self.rateLimiter.get()
|
||||
if msg:
|
||||
proxy = IrcObjectProxyRegexp(irc)
|
||||
self.callCommand(method, proxy, msg, m)
|
||||
self.callCommand(method,proxy,msg,m,catchErrors=True)
|
||||
Privmsg.doPrivmsg(self, irc, msg, rateLimit=(not fed))
|
||||
|
||||
|
||||
|
@ -100,7 +100,6 @@ class TokenizerTestCase(unittest.TestCase):
|
||||
conf.enablePipeSyntax = False
|
||||
|
||||
|
||||
|
||||
class FunctionsTestCase(unittest.TestCase):
|
||||
def testCanonicalName(self):
|
||||
self.assertEqual('foo', callbacks.canonicalName('foo'))
|
||||
@ -154,10 +153,17 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.assertEqual(callbacks.getCommands(['foo', ['bar'], ['baz']]),
|
||||
['foo', 'bar', 'baz'])
|
||||
|
||||
def testTokenize(self):
|
||||
self.assertEqual(callbacks.tokenize(''), [])
|
||||
self.assertEqual(callbacks.tokenize('foo'), ['foo'])
|
||||
self.assertEqual(callbacks.tokenize('foo'), ['foo'])
|
||||
self.assertEqual(callbacks.tokenize('bar [baz]'), ['bar', ['baz']])
|
||||
|
||||
|
||||
class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
plugins = ('Utilities', 'OwnerCommands')
|
||||
conf.allowEval = True
|
||||
timeout = 2
|
||||
def testEmptySquareBrackets(self):
|
||||
self.assertResponse('echo []', '[]')
|
||||
|
||||
@ -195,6 +201,65 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
finally:
|
||||
conf.errorReplyPrivate = originalConfErrorReplyPrivate
|
||||
|
||||
# Now for stuff not based on the plugins.
|
||||
class First(callbacks.Privmsg):
|
||||
def firstcmd(self, irc, msg, args):
|
||||
"""First"""
|
||||
irc.reply(msg, 'foo')
|
||||
|
||||
class Second(callbacks.Privmsg):
|
||||
def secondcmd(self, irc, msg, args):
|
||||
"""Second"""
|
||||
irc.reply(msg, 'bar')
|
||||
|
||||
class FirstRepeat(callbacks.Privmsg):
|
||||
def firstcmd(self, irc, msg, args):
|
||||
"""FirstRepeat"""
|
||||
irc.reply(msg, 'baz')
|
||||
|
||||
class Third(callbacks.Privmsg):
|
||||
def third(self, irc, msg, args):
|
||||
"""Third"""
|
||||
irc.reply(msg, ' '.join(args))
|
||||
|
||||
def testDispatching(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.Second())
|
||||
self.assertResponse('firstcmd', 'foo')
|
||||
self.assertResponse('secondcmd', 'bar')
|
||||
self.assertResponse('first firstcmd', 'foo')
|
||||
self.assertResponse('second secondcmd', 'bar')
|
||||
|
||||
def testAmbiguousError(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.FirstRepeat())
|
||||
self.assertError('firstcmd')
|
||||
self.assertNotRegexp('firstcmd', '(foo.*baz|baz.*foo)')
|
||||
self.assertResponse('first firstcmd', 'foo')
|
||||
self.assertResponse('firstrepeat firstcmd', 'baz')
|
||||
self.assertError('help firstcmd')
|
||||
self.assertRegexp('help first firstcmd', 'First', 0) # no re.I flag.
|
||||
self.assertRegexp('help firstrepeat firstcmd', 'FirstRepeat', 0)
|
||||
self.assertResponse('syntax first firstcmd', 'firstcmd First')
|
||||
self.assertResponse('syntax firstrepeat firstcmd',
|
||||
'firstcmd FirstRepeat')
|
||||
|
||||
def testDefaultCommand(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.Third())
|
||||
self.assertError('first blah')
|
||||
self.assertResponse('third foo bar baz', 'foo bar baz')
|
||||
|
||||
|
||||
class PrivmsgCommandAndRegexpTestCase(PluginTestCase):
|
||||
plugins = ('Utilities',) # Gotta put something.
|
||||
class PCAR(callbacks.PrivmsgCommandAndRegexp):
|
||||
def test(self, irc, msg, args):
|
||||
"<foo>"
|
||||
raise callbacks.ArgumentError
|
||||
def testNoEscapingArgumentError(self):
|
||||
self.irc.addCallback(self.PCAR())
|
||||
self.assertResponse('test', 'test <foo>')
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user