Fix for a few exceptions escaping, bug #826177 in partciular.

This commit is contained in:
Jeremy Fincher 2003-10-19 14:47:29 +00:00
parent 37b796ac74
commit 487ac95d80
2 changed files with 13 additions and 1 deletions

View File

@ -152,6 +152,8 @@ class Math(callbacks.Privmsg):
irc.error(msg, 'Go get scanez, this is a *real* math problem!')
except TypeError:
irc.error(msg, 'Something in there wasn\'t a valid number.')
except NameError, e:
irc.error(msg, '%s is not a defined function.' % str(e).split()[1])
except Exception, e:
irc.error(msg, debug.exnToString(e))
@ -194,7 +196,11 @@ class Math(callbacks.Privmsg):
arg2 = stack.pop()
arg1 = stack.pop()
s = '%s%s%s' % (arg1, arg, arg2)
stack.append(eval(s, self._mathEnv, self._mathEnv))
try:
stack.append(eval(s, self._mathEnv, self._mathEnv))
except SyntaxError:
irc.error(msg, '%r is not a defined function.' % arg)
return
if len(stack) == 1:
irc.reply(msg, str(self._complexToString(complex(stack[0]))))
else:

View File

@ -47,6 +47,9 @@ class MathTestCase(PluginTestCase, PluginDocumentation):
## self.assertNotError('calc log(8,2)')
## self.assertNotError('calc log(8,2)')
def testCalcNoNameError(self):
self.assertNotRegexp('calc foobar(x)', 'NameError')
def testRpn(self):
self.assertResponse('rpn 5 2 +', '7')
self.assertResponse('rpn 1 2 3 +', 'Stack: [1, 5]')
@ -54,6 +57,9 @@ class MathTestCase(PluginTestCase, PluginDocumentation):
self.assertResponse('rpn 2 3 4 + -', str(2-7))
self.assertNotError('rpn 2 degrees')
def testRpmNoSyntaxError(self):
self.assertNotRegexp('rpn 2 3 foobar', 'SyntaxError')
def testConvert(self):
self.assertResponse('convert 1 m to cm', '100.0 cm')
self.assertResponse('convert 1 M to cm', '100.0 cm')