mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Fixed urlSnarfer bugz0r.
This commit is contained in:
parent
da209e5a36
commit
ea2f4a55ca
@ -164,13 +164,10 @@ def channel(f):
|
|||||||
def urlSnarfer(f):
|
def urlSnarfer(f):
|
||||||
"""Protects the snarfer from loops and whatnot."""
|
"""Protects the snarfer from loops and whatnot."""
|
||||||
f = _threadedWrapMethod(f)
|
f = _threadedWrapMethod(f)
|
||||||
|
q = structures.smallqueue()
|
||||||
def newf(self, irc, msg, match, *L):
|
def newf(self, irc, msg, match, *L):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
cutoff = now - conf.supybot.snarfThrottle()
|
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:
|
while q and q[0][2] < cutoff:
|
||||||
q.dequeue()
|
q.dequeue()
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
|
@ -62,6 +62,31 @@ class FunctionsTest(unittest.TestCase):
|
|||||||
self.assertEqual(privmsgs.getArgs(args, required=0, optional=1),
|
self.assertEqual(privmsgs.getArgs(args, required=0, optional=1),
|
||||||
' '.join(args))
|
' '.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:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user