diff --git a/plugins/Fun.py b/plugins/Fun.py
index e95fd65fc..d669858d9 100644
--- a/plugins/Fun.py
+++ b/plugins/Fun.py
@@ -119,14 +119,6 @@ class Fun(callbacks.Privmsg):
except ValueError:
irc.error('That number doesn\'t map to an 8-bit character.')
- def base(self, irc, msg, args):
- """
-
- Converts from base the number
- """
- (base, number) = privmsgs.getArgs(args, required=2)
- irc.reply(str(long(number, int(base))))
-
def encode(self, irc, msg, args):
"""
diff --git a/plugins/Math.py b/plugins/Math.py
index 9259a5e20..1984a02c1 100644
--- a/plugins/Math.py
+++ b/plugins/Math.py
@@ -69,6 +69,24 @@ class Math(callbacks.Privmsg):
# Then we delete all square brackets, underscores, and whitespace, so no
# one can do list comprehensions or call __...__ functions.
###
+ def base(self, irc, msg, args):
+ """
+
+ Converts from base the number
+ """
+ (base, number) = privmsgs.getArgs(args, required=2)
+ try:
+ base = int(base)
+ if not (2 <= base <= 36):
+ raise ValueError
+ except ValueError:
+ irc.error(' must be a number between 2 and 36.')
+ return
+ try:
+ irc.reply(str(long(number, int(base))))
+ except ValueError:
+ irc.error('Invalid for base %s: %s' % (base, number))
+
_mathEnv = {'__builtins__': types.ModuleType('__builtins__'), 'i': 1j}
_mathEnv.update(math.__dict__)
_mathEnv.update(cmath.__dict__)
diff --git a/test/test_Math.py b/test/test_Math.py
index a4be517ad..c472e28c5 100644
--- a/test/test_Math.py
+++ b/test/test_Math.py
@@ -33,6 +33,9 @@ from testsupport import *
class MathTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Math',)
+ def testBase(self):
+ self.assertNotRegexp('base 56 asdflkj', 'ValueError')
+
def testCalc(self):
self.assertResponse('calc 5*0.06', str(5*0.06))
self.assertResponse('calc 2.0-7.0', str(2-7))