diff options
author | Lance Stout <lancestout@gmail.com> | 2011-08-18 00:07:37 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-08-18 00:07:37 -0700 |
commit | 3fc20e10f5ae009273cd2d751628b0dfc05f9e8d (patch) | |
tree | a433fd3c59c9a15c1088d5cf5e8118ff27f59edc /sleekxmpp | |
parent | 004eabf80959ebcaeddf2e15065bd4f50ad10974 (diff) | |
download | slixmpp-3fc20e10f5ae009273cd2d751628b0dfc05f9e8d.tar.gz slixmpp-3fc20e10f5ae009273cd2d751628b0dfc05f9e8d.tar.bz2 slixmpp-3fc20e10f5ae009273cd2d751628b0dfc05f9e8d.tar.xz slixmpp-3fc20e10f5ae009273cd2d751628b0dfc05f9e8d.zip |
Add some convenience methods to rosters.
Can now use len(self.client_roster) to get the number of JIDs in
the roster, and self.client_roster.groups() to get a dict of
groups and the JIDs in those groups.
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/roster/single.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sleekxmpp/roster/single.py b/sleekxmpp/roster/single.py index 411c5d98..c2a73d34 100644 --- a/sleekxmpp/roster/single.py +++ b/sleekxmpp/roster/single.py @@ -75,6 +75,10 @@ class RosterNode(object): self.add(key, save=True) return self._jids[key] + def __len__(self): + """Return the number of JIDs referenced by the roster.""" + return len(self._jids) + def keys(self): """Return a list of all subscribed JIDs.""" return self._jids.keys() @@ -83,6 +87,16 @@ class RosterNode(object): """Returns whether the roster has a JID.""" return jid in self._jids + def groups(self): + """Return a dictionary mapping group names to JIDs.""" + result = {} + for jid in self._jids: + for group in self._jids[jid]['groups']: + if group not in result: + result[group] = [] + result[group].append(jid) + return result + def __iter__(self): """Iterate over the roster items.""" return self._jids.__iter__() |