diff --git a/src/privmsgs.py b/src/privmsgs.py index 39c6d425f..b5d365e08 100644 --- a/src/privmsgs.py +++ b/src/privmsgs.py @@ -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) diff --git a/test/test_privmsgs.py b/test/test_privmsgs.py index 70ad1576a..d52004b59 100644 --- a/test/test_privmsgs.py +++ b/test/test_privmsgs.py @@ -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: