mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Fixed major bugz0rs with IrcSet and IrcDict.
This commit is contained in:
parent
6092ce484a
commit
3f8c149047
@ -182,10 +182,10 @@ class ChannelState(object):
|
||||
__slots__ = ('users', 'ops', 'halfops', 'voices', 'topic')
|
||||
def __init__(self):
|
||||
self.topic = ''
|
||||
self.users = ircutils.IrcSet() # sets.Set()
|
||||
self.ops = ircutils.IrcSet() # sets.Set()
|
||||
self.halfops = ircutils.IrcSet() # sets.Set()
|
||||
self.voices = ircutils.IrcSet() # sets.Set()
|
||||
self.users = ircutils.IrcSet()
|
||||
self.ops = ircutils.IrcSet()
|
||||
self.halfops = ircutils.IrcSet()
|
||||
self.voices = ircutils.IrcSet()
|
||||
|
||||
def addUser(self, user):
|
||||
"Adds a given user to the ChannelState. Power prefixes are handled."
|
||||
|
@ -39,6 +39,7 @@ IRC-case-insensitive fashion), and numerous other things.
|
||||
import fix
|
||||
|
||||
import re
|
||||
import copy
|
||||
import sets
|
||||
import string
|
||||
import fnmatch
|
||||
@ -355,11 +356,19 @@ class IrcDict(dict):
|
||||
def __delitem__(self, s):
|
||||
self.__parent.__delitem__(IrcString(s))
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s)' % (self.__class__.__name__, self.__parent.__repr__())
|
||||
|
||||
def __reduce__(self):
|
||||
return (self.__class__, (dict(self),))
|
||||
|
||||
class IrcSet(sets.Set):
|
||||
"""A sets.Set using IrcStrings instead of regular strings."""
|
||||
def __init__(self):
|
||||
def __init__(self, seq=()):
|
||||
self.__parent = super(IrcSet, self)
|
||||
self.__parent.__init__()
|
||||
for elt in seq:
|
||||
self.add(elt)
|
||||
|
||||
def add(self, s):
|
||||
return self.__parent.add(IrcString(s))
|
||||
@ -372,9 +381,12 @@ class IrcSet(sets.Set):
|
||||
|
||||
def __contains__(self, s):
|
||||
return self.__parent.__contains__(IrcString(s))
|
||||
|
||||
has_key = __contains__
|
||||
|
||||
def __reduce__(self):
|
||||
return (self.__class__, (list(self),))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys, doctest
|
||||
doctest.testmod(sys.modules['__main__'])
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
import copy
|
||||
import random
|
||||
|
||||
import ircmsgs
|
||||
@ -205,6 +206,12 @@ class IrcDictTestCase(unittest.TestCase):
|
||||
d['#fOOBAR[]'] = 'blah'
|
||||
self.assertEqual('blah', d['#foobar{}'])
|
||||
|
||||
def testCopyable(self):
|
||||
d = ircutils.IrcDict()
|
||||
d['foo'] = 'bar'
|
||||
self.failUnless(d == copy.copy(d))
|
||||
self.failUnless(d == copy.deepcopy(d))
|
||||
|
||||
class IrcSetTestCase(unittest.TestCase):
|
||||
def test(self):
|
||||
s = ircutils.IrcSet()
|
||||
@ -217,6 +224,26 @@ class IrcSetTestCase(unittest.TestCase):
|
||||
self.failIf('foo' in s)
|
||||
self.failIf('FOo' in s)
|
||||
|
||||
def testCopy(self):
|
||||
s = ircutils.IrcSet()
|
||||
s.add('foo')
|
||||
s.add('bar')
|
||||
s1 = copy.deepcopy(s)
|
||||
self.failUnless('foo' in s)
|
||||
self.failUnless('FOO' in s)
|
||||
s.discard('alfkj')
|
||||
s.remove('FOo')
|
||||
self.failIf('foo' in s)
|
||||
self.failIf('FOo' in s)
|
||||
self.failUnless('foo' in s1)
|
||||
self.failUnless('FOO' in s1)
|
||||
s1.discard('alfkj')
|
||||
s1.remove('FOo')
|
||||
self.failIf('foo' in s1)
|
||||
self.failIf('FOo' in s1)
|
||||
|
||||
|
||||
|
||||
class IrcStringTestCase(unittest.TestCase):
|
||||
def testEquality(self):
|
||||
self.assertEqual('#foo', ircutils.IrcString('#foo'))
|
||||
|
Loading…
Reference in New Issue
Block a user