mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +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:
|
else:
|
||||||
def p(s):
|
def p(s):
|
||||||
return True
|
return True
|
||||||
users = [u.name for u in ircdb.users.users[1:] if u is not None]
|
users = [u.name for u in ircdb.users if p(u.name)]
|
||||||
users = filter(p, users)
|
|
||||||
if users:
|
if users:
|
||||||
utils.sortBy(str.lower, users)
|
utils.sortBy(str.lower, users)
|
||||||
irc.reply(msg, utils.commaAndify(users))
|
irc.reply(msg, utils.commaAndify(users))
|
||||||
|
@ -458,8 +458,13 @@ class UsersDB(object):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
x = ifilter(None, self.users)
|
||||||
|
x.next() # Skip the bot user.
|
||||||
|
return x
|
||||||
|
|
||||||
def numUsers(self):
|
def numUsers(self):
|
||||||
return ilen(ifilter(None, self.users))-1 # -1 is for the bot user.
|
return ilen(self)
|
||||||
|
|
||||||
def setUser(self, id, user):
|
def setUser(self, id, user):
|
||||||
"""Sets a user (given its id) to the IrcUser given it."""
|
"""Sets a user (given its id) to the IrcUser given it."""
|
||||||
|
@ -311,7 +311,7 @@ class UsersDBTestCase(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
self.users = ircdb.UsersDB(self.filename)
|
self.users = ircdb.UsersDB(self.filename)
|
||||||
|
|
||||||
def testNumUsers(self):
|
def testIterAndNumUsers(self):
|
||||||
self.assertEqual(self.users.numUsers(), 0)
|
self.assertEqual(self.users.numUsers(), 0)
|
||||||
(id, u) = self.users.newUser()
|
(id, u) = self.users.newUser()
|
||||||
hostmask = 'foo!bar@baz'
|
hostmask = 'foo!bar@baz'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user