diff --git a/plugins/Google.py b/plugins/Google.py index 134cdbb44..41187e222 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -408,6 +408,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp): googleGroups = privmsgs.urlSnarfer(googleGroups) _calcRe = re.compile(r'(.*?)', re.I) + _calcSupRe = re.compile(r'(.*?)', re.I) + _calcFontRe = re.compile(r'(.*?)') + _calcTimesRe = re.compile(r'×') def calc(self, irc, msg, args): """ @@ -420,7 +423,11 @@ class Google(callbacks.PrivmsgCommandAndRegexp): html = webutils.getUrl(url) match = self._calcRe.search(html) if match is not None: - irc.reply(match.group(1)) + s = match.group(1) + s = self._calcSupRe.sub(r'^(\1)', s) + s = self._calcFontRe.sub(r' , ', s) + s = self._calcTimesRe.sub(r' * ', s) + irc.reply(s) else: irc.reply('Google\'s calculator didn\'t come up with anything.') diff --git a/test/test_Google.py b/test/test_Google.py index 00179e6f6..ee722e682 100644 --- a/test/test_Google.py +++ b/test/test_Google.py @@ -34,6 +34,16 @@ from testsupport import * class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation): plugins = ('Google',) if network: + def testCalc(self): + self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t') + self.assertNotRegexp('google calc ' + 'the speed of light ' + 'in microns / fortnight', '') + self.assertNotRegexp('google calc ' + 'the speed of light ' + 'in microns / fortnight', '×') + + def testNoNoLicenseKeyError(self): conf.supybot.plugins.Google.groupsSnarfer.setValue(True) self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))