mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Some source code tweakings; I still don't know why that test fails, but it's a good reminder that we should use the copy method instead of the copy.copy function.
This commit is contained in:
parent
a87d8c9a1f
commit
0dc88e88b9
@ -323,34 +323,40 @@ class ChannelState(object):
|
|||||||
class IrcState(IrcCommandDispatcher):
|
class IrcState(IrcCommandDispatcher):
|
||||||
"""Maintains state of the Irc connection. Should also become smarter.
|
"""Maintains state of the Irc connection. Should also become smarter.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('history', 'nicksToHostmasks', 'channels')
|
|
||||||
__metaclass__ = log.MetaFirewall
|
__metaclass__ = log.MetaFirewall
|
||||||
__firewalled__ = {'addMsg': None}
|
__firewalled__ = {'addMsg': None}
|
||||||
def __init__(self):
|
def __init__(self, history=None, supported=None,
|
||||||
self.supported = utils.InsensitivePreservingDict()
|
nicksToHostmasks=None, channels=None):
|
||||||
self.history=RingBuffer(conf.supybot.protocols.irc.maxHistoryLength())
|
if history is None:
|
||||||
self.reset()
|
history = RingBuffer(conf.supybot.protocols.irc.maxHistoryLength())
|
||||||
|
if supported is None:
|
||||||
|
supported = utils.InsensitivePreservingDict()
|
||||||
|
if nicksToHostmasks is None:
|
||||||
|
nicksToHostmasks = ircutils.IrcDict()
|
||||||
|
if channels is None:
|
||||||
|
channels = ircutils.IrcDict()
|
||||||
|
self.supported = supported
|
||||||
|
self.history = history
|
||||||
|
self.channels = channels
|
||||||
|
self.nicksToHostmasks = nicksToHostmasks
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""Resets the state to normal, unconnected state."""
|
"""Resets the state to normal, unconnected state."""
|
||||||
self.history.reset()
|
self.history.reset()
|
||||||
|
self.channels.clear()
|
||||||
self.supported.clear()
|
self.supported.clear()
|
||||||
|
self.nicksToHostmasks.clear()
|
||||||
self.history.resize(conf.supybot.protocols.irc.maxHistoryLength())
|
self.history.resize(conf.supybot.protocols.irc.maxHistoryLength())
|
||||||
self.channels = ircutils.IrcDict()
|
|
||||||
self.nicksToHostmasks = ircutils.IrcDict()
|
|
||||||
|
|
||||||
def __getstate__(self):
|
|
||||||
return map(utils.curry(getattr, self), self.__slots__)
|
|
||||||
|
|
||||||
def __setstate__(self, t):
|
|
||||||
for (name, value) in zip(self.__slots__, t):
|
|
||||||
setattr(self, name, value)
|
|
||||||
|
|
||||||
|
def __reduce__(self):
|
||||||
|
return (self.__class__, (self.history, self.supported,
|
||||||
|
self.nicksToHostmasks, self.channels))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
ret = True
|
return self.history == other.history and \
|
||||||
for name in self.__slots__:
|
self.channels == other.channels and \
|
||||||
ret = ret and getattr(self, name) == getattr(other, name)
|
self.supported == other.supported and \
|
||||||
return ret
|
self.nicksToHostmasks == other.nicksToHostmasks
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not self == other
|
return not self == other
|
||||||
|
@ -254,7 +254,17 @@ class IrcStateTestCase(SupyTestCase):
|
|||||||
pass
|
pass
|
||||||
self.assertEqual(state, state.copy())
|
self.assertEqual(state, state.copy())
|
||||||
|
|
||||||
|
def testCopyCopiesChannels(self):
|
||||||
state = irclib.IrcState()
|
state = irclib.IrcState()
|
||||||
|
stateCopy = copy.copy(state)
|
||||||
|
state.channels['#foo'] = None
|
||||||
|
self.failIf('#foo' in stateCopy.channels)
|
||||||
|
|
||||||
|
def testCopyCopiesChannels2(self):
|
||||||
|
state = irclib.IrcState()
|
||||||
|
stateCopy = state.copy()
|
||||||
|
state.channels['#foo'] = None
|
||||||
|
self.failIf('#foo' in stateCopy.channels)
|
||||||
|
|
||||||
def testJoin(self):
|
def testJoin(self):
|
||||||
st = irclib.IrcState()
|
st = irclib.IrcState()
|
||||||
|
Loading…
Reference in New Issue
Block a user