From ce88b052d0d1a87f1df8fe59588d650a64761615 Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 20 Oct 2003 17:52:09 +0000 Subject: [PATCH] Added @disablesfsnarfer and its test --- plugins/Sourceforge.py | 16 ++++++++++++++++ test/test_Sourceforge.py | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/Sourceforge.py b/plugins/Sourceforge.py index 179e55df2..a2b7040e9 100644 --- a/plugins/Sourceforge.py +++ b/plugins/Sourceforge.py @@ -39,6 +39,7 @@ import urllib2 from itertools import ifilter +import conf import debug import utils import ircutils @@ -94,6 +95,10 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp): _getStatus = lambda self, s: '%s: %s' % (ircutils.bold('Status'), self._status.search(s).group(1)) + def __init__(self): + callbacks.PrivmsgCommandAndRegexp.__init__(self) + self.snarfer = True + def _formatResp(self, num, text): """ Parses the Sourceforge query to return a list of tuples that @@ -112,6 +117,15 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp): matches.append((item[0], utils.htmlToText(item[2]))) return matches + def disablesfsnarfer(self, irc, msg, args): + """takes no argument + + Disables the snarfer that responds to all Sourceforge Tracker links + """ + self.snarfer = False + irc.reply(msg, conf.replySuccess) + disablesfsnarfer=privmsgs.checkCapability(disablesfsnarfer,'admin') + _bugLink = re.compile(r'"([^"]+)">Bugs') def bugs(self, irc, msg, args): """[ []] @@ -230,6 +244,8 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp): _linkType = re.compile(r'(\w+ \w+|\w+): Tracker Detailed View', re.I) def sourceforgeSnarfer(self, irc, msg, match): r"https?://(?:www\.)?sourceforge\.net/tracker/(?:index\.php)?\?func=detail&aid=\d+&group_id=\d+&atid=\d+" + if not self.snarfer: + return url = match.group(0) fd = urllib2.urlopen(url) s = fd.read() diff --git a/test/test_Sourceforge.py b/test/test_Sourceforge.py index b7e1b05a8..71e81c3dc 100644 --- a/test/test_Sourceforge.py +++ b/test/test_Sourceforge.py @@ -96,5 +96,13 @@ class SourceforgeTest(PluginTestCase, PluginDocumentation): self.assertNotError('https://www.sourceforge.net/tracker/index.php?'\ 'func=detail&aid=540223&group_id=235&atid=300235') + def testDisablesfsnarfer(self): + self.assertRegexp('http://sourceforge.net/tracker/index.php?'\ + 'func=detail&aid=540223&group_id=235&atid=300235', + r';.*Status.*: \w+;') + self.assertNotError('disablesfsnarfer') + self.assertNoResponse('http://sourceforge.net/tracker/index.php?'\ + 'func=detail&aid=540223&group_id=235&atid=300235') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: