Fixed urlSnarfer bugz0r.

This commit is contained in:
Jeremy Fincher 2004-02-09 02:52:41 +00:00
parent da209e5a36
commit ea2f4a55ca
2 changed files with 26 additions and 4 deletions

View File

@ -164,13 +164,10 @@ def channel(f):
def urlSnarfer(f):
"""Protects the snarfer from loops and whatnot."""
f = _threadedWrapMethod(f)
q = structures.smallqueue()
def newf(self, irc, msg, match, *L):
now = time.time()
cutoff = now - conf.supybot.snarfThrottle()
q = getattr(self, '_snarfedUrls', None)
if q is None:
q = structures.smallqueue()
self._snarfedUrls = q
while q and q[0][2] < cutoff:
q.dequeue()
url = match.group(0)

View File

@ -62,6 +62,31 @@ class FunctionsTest(unittest.TestCase):
self.assertEqual(privmsgs.getArgs(args, required=0, optional=1),
' '.join(args))
class UrlSnarferTestCase(PluginTestCase):
plugins = ()
class URL1(callbacks.PrivmsgCommandAndRegexp):
regexps = ['F', 'G']
def __init__(self):
self.FCalled = False
self.GCalled = False
callbacks.PrivmsgCommandAndRegexp.__init__(self)
def F(self, irc, msg, match):
r"."
self.FCalled = True
F = privmsgs.urlSnarfer(F)
def G(self, irc, msg, match):
r"."
self.GCalled = True
G = privmsgs.urlSnarfer(G)
def test(self):
cb = self.URL1()
self.irc.addCallback(cb)
self.assertNoResponse('foo', 1)
self.failUnless(cb.FCalled and cb.GCalled)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: