mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 02:24:12 +01:00
Changed the implementation of IrcMsgQueue a bit.
This commit is contained in:
parent
3a7202bfbe
commit
46225641bd
@ -161,17 +161,15 @@ class IrcMsgQueue(object):
|
||||
self.highpriority = smallqueue()
|
||||
self.normal = smallqueue()
|
||||
self.lowpriority = smallqueue()
|
||||
self.msgs = set()
|
||||
|
||||
def enqueue(self, msg):
|
||||
"""Enqueues a given message."""
|
||||
if msg in self.msgs and \
|
||||
if msg in self and \
|
||||
conf.supybot.protocols.irc.refuseToQueueDuplicateMessages():
|
||||
s = str(msg).strip()
|
||||
log.info('Not adding message %q to queue, already added.', s)
|
||||
return False
|
||||
else:
|
||||
self.msgs.add(msg)
|
||||
if msg.command in _high:
|
||||
self.highpriority.enqueue(msg)
|
||||
elif msg.command in _low:
|
||||
@ -189,19 +187,18 @@ class IrcMsgQueue(object):
|
||||
msg = self.normal.dequeue()
|
||||
elif self.lowpriority:
|
||||
msg = self.lowpriority.dequeue()
|
||||
if msg:
|
||||
try:
|
||||
self.msgs.remove(msg)
|
||||
except KeyError:
|
||||
s = 'Odd, dequeuing a message that\'s not in self.msgs.'
|
||||
log.warning(s)
|
||||
return msg
|
||||
|
||||
def __contains__(self, msg):
|
||||
return msg in self.normal or \
|
||||
msg in self.lowpriority or \
|
||||
msg in self.highpriority
|
||||
|
||||
def __nonzero__(self):
|
||||
return bool(self.highpriority or self.normal or self.lowpriority)
|
||||
|
||||
def __len__(self):
|
||||
return sum(imap(len,[self.highpriority,self.lowpriority,self.normal]))
|
||||
return len(self.highpriority)+len(self.lowpriority)+len(self.normal)
|
||||
|
||||
def __repr__(self):
|
||||
name = self.__class__.__name__
|
||||
|
@ -76,6 +76,19 @@ class IrcMsgQueueTestCase(SupyTestCase):
|
||||
q.dequeue()
|
||||
self.assertEqual(len(q), 0)
|
||||
|
||||
def testContains(self):
|
||||
q = irclib.IrcMsgQueue()
|
||||
q.enqueue(self.msg)
|
||||
q.enqueue(self.msg)
|
||||
q.enqueue(self.msg)
|
||||
self.failUnless(self.msg in q)
|
||||
q.dequeue()
|
||||
self.failUnless(self.msg in q)
|
||||
q.dequeue()
|
||||
self.failUnless(self.msg in q)
|
||||
q.dequeue()
|
||||
self.failIf(self.msg in q)
|
||||
|
||||
def testRepr(self):
|
||||
q = irclib.IrcMsgQueue()
|
||||
self.assertEqual(repr(q), 'IrcMsgQueue([])')
|
||||
|
Loading…
Reference in New Issue
Block a user