From 2acf59d7817a4f6d090ea20514d8469eb2aaf459 Mon Sep 17 00:00:00 2001 From: James Vega Date: Sat, 11 Oct 2003 20:52:35 +0000 Subject: [PATCH] Added a urlsnarfer and the appropriate tests --- plugins/Sourceforge.py | 23 +++++++++++++++++++++-- test/test_Sourceforge.py | 8 ++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/plugins/Sourceforge.py b/plugins/Sourceforge.py index f9e8c66de..c276e9976 100644 --- a/plugins/Sourceforge.py +++ b/plugins/Sourceforge.py @@ -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 """) -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'(\d+)'\ '([^<]+)', 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+) - ([^<]+)', 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: diff --git a/test/test_Sourceforge.py b/test/test_Sourceforge.py index df1811a6e..41b9e5f7f 100644 --- a/test/test_Sourceforge.py +++ b/test/test_Sourceforge.py @@ -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: