Added @disablesfsnarfer and its test

This commit is contained in:
James Vega 2003-10-20 17:52:09 +00:00
parent f6088d57d8
commit ce88b052d0
2 changed files with 24 additions and 0 deletions

View File

@ -39,6 +39,7 @@ import urllib2
from itertools import ifilter from itertools import ifilter
import conf
import debug import debug
import utils import utils
import ircutils import ircutils
@ -94,6 +95,10 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
_getStatus = lambda self, s: '%s: %s' % (ircutils.bold('Status'), _getStatus = lambda self, s: '%s: %s' % (ircutils.bold('Status'),
self._status.search(s).group(1)) self._status.search(s).group(1))
def __init__(self):
callbacks.PrivmsgCommandAndRegexp.__init__(self)
self.snarfer = True
def _formatResp(self, num, text): def _formatResp(self, num, text):
""" """
Parses the Sourceforge query to return a list of tuples that 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]))) matches.append((item[0], utils.htmlToText(item[2])))
return matches 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') _bugLink = re.compile(r'"([^"]+)">Bugs')
def bugs(self, irc, msg, args): def bugs(self, irc, msg, args):
"""[<project> [<num>]] """[<project> [<num>]]
@ -230,6 +244,8 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
_linkType = re.compile(r'(\w+ \w+|\w+): Tracker Detailed View', re.I) _linkType = re.compile(r'(\w+ \w+|\w+): Tracker Detailed View', re.I)
def sourceforgeSnarfer(self, irc, msg, match): def sourceforgeSnarfer(self, irc, msg, match):
r"https?://(?:www\.)?sourceforge\.net/tracker/(?:index\.php)?\?func=detail&aid=\d+&group_id=\d+&atid=\d+" 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) url = match.group(0)
fd = urllib2.urlopen(url) fd = urllib2.urlopen(url)
s = fd.read() s = fd.read()

View File

@ -96,5 +96,13 @@ class SourceforgeTest(PluginTestCase, PluginDocumentation):
self.assertNotError('https://www.sourceforge.net/tracker/index.php?'\ self.assertNotError('https://www.sourceforge.net/tracker/index.php?'\
'func=detail&aid=540223&group_id=235&atid=300235') '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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: