summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sleekxmpp/stanza/error.py55
-rw-r--r--sleekxmpp/stanza/htmlim.py25
-rw-r--r--sleekxmpp/stanza/nick.py16
-rw-r--r--sleekxmpp/stanza/roster.py44
4 files changed, 140 insertions, 0 deletions
diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py
new file mode 100644
index 00000000..4cb7310a
--- /dev/null
+++ b/sleekxmpp/stanza/error.py
@@ -0,0 +1,55 @@
+from .. xmlstream.stanzabase import ElementBase, ET
+
+class Error(ElementBase):
+ namespace = 'jabber:client'
+ name = 'error'
+ plugin_attrib = 'error'
+ conditions = set(('bad-request', 'conflict', 'feature-not-implemented', 'forbidden', 'gone', 'item-not-found', 'jid-malformed', 'not-acceptable', 'not-allowed', 'not-authorized', 'payment-required', 'recipient-unavailable', 'redirect', 'registration-required', 'remote-server-not-found', 'remote-server-timeout', 'service-unavailable', 'subscription-required', 'undefined-condition', 'unexpected-request'))
+ interfaces = set(('condition', 'text', 'type'))
+ types = set(('cancel', 'continue', 'modify', 'auth', 'wait'))
+ sub_interfaces = set(('text',))
+ condition_ns = 'urn:ietf:params:xml:ns:xmpp-stanzas'
+
+ def setup(self, xml=None):
+ if ElementBase.setup(self, xml): #if we had to generate xml
+ self['type'] = 'cancel'
+ self['condition'] = 'feature-not-implemented'
+ if self.parent is not None:
+ self.parent['type'] = 'error'
+
+ def getCondition(self):
+ for child in self.xml.getchildren():
+ if "{%s}" % self.condition_ns in child.tag:
+ return child.tag.split('}', 1)[-1]
+ return ''
+
+ def setCondition(self, value):
+ if value in self.conditions:
+ for child in self.xml.getchildren():
+ if "{%s}" % self.condition_ns in child.tag:
+ self.xml.remove(child)
+ condition = ET.Element("{%s}%s" % (self.condition_ns, value))
+ self.xml.append(condition)
+ return self
+
+ def delCondition(self):
+ return self
+
+ def getText(self):
+ text = ''
+ textxml = self.xml.find("{urn:ietf:params:xml:ns:xmpp-stanzas}text")
+ if textxml is not None:
+ text = textxml.text
+ return text
+
+ def setText(self, value):
+ self.delText()
+ textxml = ET.Element('{urn:ietf:params:xml:ns:xmpp-stanzas}text')
+ textxml.text = value
+ self.xml.append(textxml)
+ return self
+
+ def delText(self):
+ textxml = self.xml.find("{urn:ietf:params:xml:ns:xmpp-stanzas}text")
+ if textxml is not None:
+ self.xml.remove(textxml)
diff --git a/sleekxmpp/stanza/htmlim.py b/sleekxmpp/stanza/htmlim.py
new file mode 100644
index 00000000..dbfb45d6
--- /dev/null
+++ b/sleekxmpp/stanza/htmlim.py
@@ -0,0 +1,25 @@
+from .. xmlstream.stanzabase import ElementBase, ET
+
+class HTMLIM(ElementBase):
+ namespace = 'http://jabber.org/protocol/xhtml-im'
+ name = 'html'
+ plugin_attrib = 'html'
+ interfaces = set(('html'))
+
+ def setHtml(self, html):
+ if issinstance(html, str):
+ html = ET.XML(html)
+ if html.find('{http://www.w3.org/1999/xhtml}body') is None:
+ body = ET.Element('{http://www.w3.org/1999/xhtml}body')
+ body.append(html)
+ else:
+ body = html
+ self.xml.append(html)
+
+ def getHtml(self):
+ html = self.xml.find('{http://www.w3.org/1999/xhtml}body')
+ if html is None: return ''
+ return __str__(html)
+
+ def delHtml(self):
+ return self.__del__()
diff --git a/sleekxmpp/stanza/nick.py b/sleekxmpp/stanza/nick.py
new file mode 100644
index 00000000..438b5a9b
--- /dev/null
+++ b/sleekxmpp/stanza/nick.py
@@ -0,0 +1,16 @@
+from .. xmlstream.stanzabase import ElementBase, ET
+
+class HTMLIM(ElementBase):
+ namespace = 'http://jabber.org/nick/nick'
+ name = 'nick'
+ plugin_attrib = 'nick'
+ interfaces = set(('nick'))
+
+ def setNick(self, nick):
+ self.xml.text = nick
+
+ def getNick(self):
+ return self.xml.text
+
+ def delNick(self):
+ return self.__del__()
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)