Updated calc.

This commit is contained in:
Jeremy Fincher 2004-08-20 04:08:00 +00:00
parent 06afd9ff3d
commit d86ebf4e7f
2 changed files with 18 additions and 1 deletions

View File

@ -408,6 +408,9 @@ class Google(callbacks.PrivmsgCommandAndRegexp):
googleGroups = privmsgs.urlSnarfer(googleGroups)
_calcRe = re.compile(r'<td nowrap><font size=\+1><b>(.*?)</b>', re.I)
_calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I)
_calcFontRe = re.compile(r'<font size=-2>(.*?)</font>')
_calcTimesRe = re.compile(r'&times;')
def calc(self, irc, msg, args):
"""<expression>
@ -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.')

View File

@ -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', '<sup>')
self.assertNotRegexp('google calc '
'the speed of light '
'in microns / fortnight', '&times;')
def testNoNoLicenseKeyError(self):
conf.supybot.plugins.Google.groupsSnarfer.setValue(True)
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah'))