mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added __iter__ to UsersDB for a cleaner interface.
This commit is contained in:
parent
e34d9deecd
commit
b39e1237fc
@ -73,8 +73,7 @@ class User(callbacks.Privmsg):
|
||||
else:
|
||||
def p(s):
|
||||
return True
|
||||
users = [u.name for u in ircdb.users.users[1:] if u is not None]
|
||||
users = filter(p, users)
|
||||
users = [u.name for u in ircdb.users if p(u.name)]
|
||||
if users:
|
||||
utils.sortBy(str.lower, users)
|
||||
irc.reply(msg, utils.commaAndify(users))
|
||||
|
@ -458,8 +458,13 @@ class UsersDB(object):
|
||||
except KeyError:
|
||||
return False
|
||||
|
||||
def __iter__(self):
|
||||
x = ifilter(None, self.users)
|
||||
x.next() # Skip the bot user.
|
||||
return x
|
||||
|
||||
def numUsers(self):
|
||||
return ilen(ifilter(None, self.users))-1 # -1 is for the bot user.
|
||||
return ilen(self)
|
||||
|
||||
def setUser(self, id, user):
|
||||
"""Sets a user (given its id) to the IrcUser given it."""
|
||||
|
@ -311,7 +311,7 @@ class UsersDBTestCase(unittest.TestCase):
|
||||
pass
|
||||
self.users = ircdb.UsersDB(self.filename)
|
||||
|
||||
def testNumUsers(self):
|
||||
def testIterAndNumUsers(self):
|
||||
self.assertEqual(self.users.numUsers(), 0)
|
||||
(id, u) = self.users.newUser()
|
||||
hostmask = 'foo!bar@baz'
|
||||
|
Loading…
Reference in New Issue
Block a user