mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Better error handling for calc/icalc.
This commit is contained in:
parent
2f55345012
commit
a247e2f008
@ -117,8 +117,18 @@ class Math(callbacks.Privmsg):
|
|||||||
is that large values such as 10**24 might not be exact.
|
is that large values such as 10**24 might not be exact.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
text = privmsgs.getArgs(args)
|
||||||
|
if text != text.translate(string.ascii, '_[]'):
|
||||||
|
irc.error(msg, 'There\'s really no reason why you should have '
|
||||||
|
'underscores or brackets in your mathematical '
|
||||||
|
'expression. Please remove them.')
|
||||||
|
return
|
||||||
|
# This removes spaces, too, but we'll leave the removal of _[] for
|
||||||
|
# safety's sake.
|
||||||
text = text.translate(string.ascii, '_[] \t')
|
text = text.translate(string.ascii, '_[] \t')
|
||||||
text = text.replace('lambda', '')
|
if 'lambda' in text:
|
||||||
|
irc.error(msg, 'You can\'t use lambda in this command.')
|
||||||
|
return
|
||||||
|
text = text.replace('lambda', '') # Let's leave it in for safety.
|
||||||
def handleMatch(m):
|
def handleMatch(m):
|
||||||
s = m.group(1)
|
s = m.group(1)
|
||||||
if s.startswith('0x'):
|
if s.startswith('0x'):
|
||||||
@ -157,7 +167,17 @@ class Math(callbacks.Privmsg):
|
|||||||
the 'trusted' capability to use.
|
the 'trusted' capability to use.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
text = privmsgs.getArgs(args)
|
||||||
|
if text != text.translate(string.ascii, '_[]'):
|
||||||
|
irc.error(msg, 'There\'s really no reason why you should have '
|
||||||
|
'underscores or brackets in your mathematical '
|
||||||
|
'expression. Please remove them.')
|
||||||
|
return
|
||||||
|
# This removes spaces, too, but we'll leave the removal of _[] for
|
||||||
|
# safety's sake.
|
||||||
text = text.translate(string.ascii, '_[] \t')
|
text = text.translate(string.ascii, '_[] \t')
|
||||||
|
if 'lambda' in text:
|
||||||
|
irc.error(msg, 'You can\'t use lambda in this command.')
|
||||||
|
return
|
||||||
text = text.replace('lambda', '')
|
text = text.replace('lambda', '')
|
||||||
try:
|
try:
|
||||||
self.log.info('evaluating %r from %s' % (text, msg.prefix))
|
self.log.info('evaluating %r from %s' % (text, msg.prefix))
|
||||||
|
@ -46,6 +46,7 @@ class MathTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
|
|
||||||
def testICalc(self):
|
def testICalc(self):
|
||||||
self.assertResponse('icalc 1^1', '0')
|
self.assertResponse('icalc 1^1', '0')
|
||||||
|
self.assertResponse('icalc 10**24', '1' + '0'*24)
|
||||||
|
|
||||||
def testCalcNoNameError(self):
|
def testCalcNoNameError(self):
|
||||||
self.assertNotRegexp('calc foobar(x)', 'NameError')
|
self.assertNotRegexp('calc foobar(x)', 'NameError')
|
||||||
|
Loading…
Reference in New Issue
Block a user