Added a urlsnarfer and the appropriate tests

This commit is contained in:
James Vega 2003-10-11 20:52:35 +00:00
parent c202848677
commit 2acf59d781
2 changed files with 29 additions and 2 deletions

View File

@ -34,6 +34,7 @@ Accesses Sourceforge.net for various things
"""
import re
import sets
import urllib2
from itertools import ifilter
@ -67,13 +68,13 @@ in 0.71, Bug #820961: dock icon doesn't show up with..., Bug #820879: Cannot con
< supybot> jamessan|work: Improve CLI interface <http://sourceforge.net/tracker/index.php?func=detail&aid=720757&group_id=75946&atid=545548>
""")
class Sourceforge(callbacks.Privmsg):
class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
"""
Module for Sourceforge stuff. Currently contains commands to query a
project's most recent bugs and rfes.
"""
threaded = True
regexps = sets.Set(['sourceforgeSnarfer'])
_infoRe = re.compile(r'<td nowrap>(\d+)</td><td><a href="([^"]+)">'\
'([^<]+)</a>', re.I)
@ -212,6 +213,24 @@ class Sourceforge(callbacks.Privmsg):
except Exception, e:
irc.error(msg, debug.exnToString(e))
_sfTitle = re.compile(r'Detail:(\d+) - ([^<]+)</title>', re.I)
_linkType = re.compile(r'(\w+ \w+|\w+): Tracker Detailed View', re.I)
def sourceforgeSnarfer(self, irc, msg, match):
r"http://(?:www\.)?sourceforge.net/tracker/index.php\?func=detail&aid=\d+&group_id=\d+&atid=\d+"
url = match.group(0)
fd = urllib2.urlopen(url)
s = fd.read()
fd.close()
try:
(num, desc) = self._sfTitle.search(s).groups()
linktype = self._linkType.search(s).group(1)[:-1]
irc.reply(msg, '%s #%s: %s' % (linktype, num, desc))
except AttributeError, e:
irc.queueMsg(callbacks.reply(msg,
'That doesn\'t appear to be a proper Sourceforge bug/rfe.'))
except Exception, e:
irc.error(msg, debug.exnToString(e))
Class = Sourceforge
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -51,5 +51,13 @@ class SourceforgeTest(PluginTestCase, PluginDocumentation):
n = re.search('#(\d+)', m.args[1]).group(1)
self.assertNotError('rfes gaim %s' % n)
def testSnarfer(self):
self.assertResponse('http://sourceforge.net/tracker/index.php?'\
'func=detail&aid=589953&group_id=58965&atid=489447',
'Bug #589953: Logger doesn\'t log QUITs.')
self.assertResponse('http://sourceforge.net/tracker/index.php?'\
'func=detail&aid=712761&group_id=58965&atid=489450',
'Feature Request #712761: PyPI searching and announcements')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: