Make ChannelUserDictionary subclass collections.MutableMapping instead of deprecated UserDict.DictMixin.

This commit is contained in:
Valentin Lorentz 2012-08-04 21:16:00 +02:00
parent 11df697b96
commit 36812798fb

View File

@ -38,8 +38,8 @@ import time
import random import random
import fnmatch import fnmatch
import os.path import os.path
import UserDict
import threading import threading
import collections
import supybot.log as log import supybot.log as log
import supybot.dbi as dbi import supybot.dbi as dbi
@ -230,7 +230,7 @@ class DbiChannelDB(object):
return _getDbAndDispatcher return _getDbAndDispatcher
class ChannelUserDictionary(UserDict.DictMixin): class ChannelUserDictionary(collections.MutableMapping):
IdDict = dict IdDict = dict
def __init__(self): def __init__(self):
self.channels = ircutils.IrcDict() self.channels = ircutils.IrcDict()
@ -246,6 +246,15 @@ class ChannelUserDictionary(UserDict.DictMixin):
def __delitem__(self, (channel, id)): def __delitem__(self, (channel, id)):
del self.channels[channel][id] del self.channels[channel][id]
def __iter__(self):
for channel, ids in self.channels.items():
for id_, value in ids.items():
yield (channel, id_)
raise StopIteration()
def __len__(self):
return sum([len(x) for x in self.channels])
def iteritems(self): def iteritems(self):
for (channel, ids) in self.channels.iteritems(): for (channel, ids) in self.channels.iteritems():
for (id, v) in ids.iteritems(): for (id, v) in ids.iteritems():