mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +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.highpriority = smallqueue()
|
||||||
self.normal = smallqueue()
|
self.normal = smallqueue()
|
||||||
self.lowpriority = smallqueue()
|
self.lowpriority = smallqueue()
|
||||||
self.msgs = set()
|
|
||||||
|
|
||||||
def enqueue(self, msg):
|
def enqueue(self, msg):
|
||||||
"""Enqueues a given message."""
|
"""Enqueues a given message."""
|
||||||
if msg in self.msgs and \
|
if msg in self and \
|
||||||
conf.supybot.protocols.irc.refuseToQueueDuplicateMessages():
|
conf.supybot.protocols.irc.refuseToQueueDuplicateMessages():
|
||||||
s = str(msg).strip()
|
s = str(msg).strip()
|
||||||
log.info('Not adding message %q to queue, already added.', s)
|
log.info('Not adding message %q to queue, already added.', s)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.msgs.add(msg)
|
|
||||||
if msg.command in _high:
|
if msg.command in _high:
|
||||||
self.highpriority.enqueue(msg)
|
self.highpriority.enqueue(msg)
|
||||||
elif msg.command in _low:
|
elif msg.command in _low:
|
||||||
@ -189,19 +187,18 @@ class IrcMsgQueue(object):
|
|||||||
msg = self.normal.dequeue()
|
msg = self.normal.dequeue()
|
||||||
elif self.lowpriority:
|
elif self.lowpriority:
|
||||||
msg = self.lowpriority.dequeue()
|
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
|
return msg
|
||||||
|
|
||||||
|
def __contains__(self, msg):
|
||||||
|
return msg in self.normal or \
|
||||||
|
msg in self.lowpriority or \
|
||||||
|
msg in self.highpriority
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return bool(self.highpriority or self.normal or self.lowpriority)
|
return bool(self.highpriority or self.normal or self.lowpriority)
|
||||||
|
|
||||||
def __len__(self):
|
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):
|
def __repr__(self):
|
||||||
name = self.__class__.__name__
|
name = self.__class__.__name__
|
||||||
|
@ -76,6 +76,19 @@ class IrcMsgQueueTestCase(SupyTestCase):
|
|||||||
q.dequeue()
|
q.dequeue()
|
||||||
self.assertEqual(len(q), 0)
|
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):
|
def testRepr(self):
|
||||||
q = irclib.IrcMsgQueue()
|
q = irclib.IrcMsgQueue()
|
||||||
self.assertEqual(repr(q), 'IrcMsgQueue([])')
|
self.assertEqual(repr(q), 'IrcMsgQueue([])')
|
||||||
|
Loading…
Reference in New Issue
Block a user