Fix the Google Groups snarfer bug and added appropriate tests

This commit is contained in:
James Vega 2003-11-20 19:53:15 +00:00
parent 8854363785
commit 8b9f5a607f
2 changed files with 11 additions and 2 deletions

View File

@ -289,7 +289,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
_ggThread = re.compile(r'<br>Subject: ([^<]+)<br>') _ggThread = re.compile(r'<br>Subject: ([^<]+)<br>')
_ggPlainThread = re.compile(r'Subject: (.*)') _ggPlainThread = re.compile(r'Subject: (.*)')
_ggGroup = re.compile(r'Newsgroups: <a[^>]+>([^<]+)</a>') _ggGroup = re.compile(r'Newsgroups: (?:<a[^>]+>)?([^<]+)(?:</a>)?')
_ggPlainGroup = re.compile(r'Newsgroups: (.*)') _ggPlainGroup = re.compile(r'Newsgroups: (.*)')
def googleGroups(self, irc, msg, match): def googleGroups(self, irc, msg, match):
r"http://groups.google.com/[^\s]+" r"http://groups.google.com/[^\s]+"
@ -311,7 +311,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
fd = urllib2.urlopen(request) fd = urllib2.urlopen(request)
text = fd.read() text = fd.read()
fd.close() fd.close()
if '&output=gplain' not in match.group(0): elif '&output=gplain' not in match.group(0):
mThread = self._ggThread.search(text) mThread = self._ggThread.search(text)
mGroup = self._ggGroup.search(text) mGroup = self._ggGroup.search(text)
else: else:

View File

@ -46,6 +46,15 @@ class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation):
self.assertRegexp('http://groups.google.com/groups?selm=ExDm.' self.assertRegexp('http://groups.google.com/groups?selm=ExDm.'
'8bj.23%40gated-at.bofh.it&oe=UTF-8&output=gplain', '8bj.23%40gated-at.bofh.it&oe=UTF-8&output=gplain',
r'linux\.kernel.*NFS client freezes') r'linux\.kernel.*NFS client freezes')
self.assertRegexp('http://groups.google.com/groups?'
'q=kernel+hot-pants&hl=en&lr=&ie=UTF-8&oe=UTF-8&'
'selm=1.5.4.32.19970313170853.00674d60%40'
'adan.kingston.net&rnum=1',
r'Madrid Bluegrass Ramble')
self.assertRegexp('http://groups.google.com/groups?'
'selm=1.5.4.32.19970313170853.00674d60%40adan.'
'kingston.net&oe=UTF-8&output=gplain',
r'Madrid Bluegrass Ramble')
def testConfig(self): def testConfig(self):
self.assertNotError('google config groups-snarfer off') self.assertNotError('google config groups-snarfer off')