summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza/roster.py
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2009-12-15 04:37:10 +0000
committerNathan Fritz <fritzy@netflint.net>2009-12-15 04:37:10 +0000
commit6897a0b57c299cff9e32fde4dcb4209e70fb4bcb (patch)
treecbe75272586755074840dd37d5b848a0c38de0b6 /sleekxmpp/stanza/roster.py
parentca044a4934bc6373988a1b442da3673b70357317 (diff)
downloadslixmpp-6897a0b57c299cff9e32fde4dcb4209e70fb4bcb.tar.gz
slixmpp-6897a0b57c299cff9e32fde4dcb4209e70fb4bcb.tar.bz2
slixmpp-6897a0b57c299cff9e32fde4dcb4209e70fb4bcb.tar.xz
slixmpp-6897a0b57c299cff9e32fde4dcb4209e70fb4bcb.zip
* added error, htmlim, roster, and nick stanza plugins
Diffstat (limited to 'sleekxmpp/stanza/roster.py')
-rw-r--r--sleekxmpp/stanza/roster.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py
new file mode 100644
index 00000000..cb1c1c6f
--- /dev/null
+++ b/sleekxmpp/stanza/roster.py
@@ -0,0 +1,44 @@
+from .. xmlstream.stanzabase import ElementBase, ET, JID
+
+class Roster(ElementBase):
+ namespace = 'jabber:iq:roster'
+ name = 'query'
+ plugin_attrib = 'roster'
+ interfaces = set(('items',))
+
+ def setItems(self, items):
+ self.delItems()
+ for jid in items:
+ ijid = str(jid)
+ item = ET.Element('{jabber:iq:roster}item', {'jid': ijid})
+ if 'subscription' in items[jid]:
+ item.attrib['subscription'] = items[jid]['subscription']
+ if 'name' in items[jid]:
+ item.attrib['name'] = items[jid]['name']
+ if 'groups' in items[jid]:
+ for group in items[jid]['groups']:
+ groupxml = ET.Element('{jabber:iq:roster}group')
+ groupxml.text = group
+ item.append(groupxml)
+ self.xml.append(item)
+ return self
+
+ def getItems(self):
+ items = {}
+ itemsxml = self.xml.findall('{jabber:iq:roster}item')
+ if itemsxml is not None:
+ item = {}
+ for itemxml in itemsxml:
+ item['name'] = itemxml.get('name', '')
+ item['subscription'] = itemxml.get('subscription', '')
+ item['groups'] = []
+ groupsxml = itemxml.findall('{jabber:iq:roster}group')
+ if groupsxml is not None:
+ for groupxml in groupsxml:
+ item['groups'].append(groupxml.text)
+ items[JID(itemxml.get('jid'))] = item
+ return items
+
+ def delItems(self):
+ for child in self.xml.getchildren():
+ self.xml.remove(child)