summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2009-12-17 01:54:22 +0000
committerNathan Fritz <fritzy@netflint.net>2009-12-17 01:54:22 +0000
commit07018c0afa7485b06424bf6787d242e7ee523d34 (patch)
tree5de2ae3309eb439b96d4dc5ce62abf00597f75f3 /sleekxmpp/stanza
parent6897a0b57c299cff9e32fde4dcb4209e70fb4bcb (diff)
downloadslixmpp-07018c0afa7485b06424bf6787d242e7ee523d34.tar.gz
slixmpp-07018c0afa7485b06424bf6787d242e7ee523d34.tar.bz2
slixmpp-07018c0afa7485b06424bf6787d242e7ee523d34.tar.xz
slixmpp-07018c0afa7485b06424bf6787d242e7ee523d34.zip
* fixed many stanza bugs
* added stanza unhandled (unhandled iqs now reply with feature-not-implemented) * added stanza exceptions (stanzas may now reply with exceptions when their handler raises an exception)
Diffstat (limited to 'sleekxmpp/stanza')
-rw-r--r--sleekxmpp/stanza/htmlim.py2
-rw-r--r--sleekxmpp/stanza/iq.py39
-rw-r--r--sleekxmpp/stanza/message.py9
-rw-r--r--sleekxmpp/stanza/nick.py4
-rw-r--r--sleekxmpp/stanza/presence.py16
-rw-r--r--sleekxmpp/stanza/roster.py2
6 files changed, 65 insertions, 7 deletions
diff --git a/sleekxmpp/stanza/htmlim.py b/sleekxmpp/stanza/htmlim.py
index dbfb45d6..24b68592 100644
--- a/sleekxmpp/stanza/htmlim.py
+++ b/sleekxmpp/stanza/htmlim.py
@@ -5,6 +5,8 @@ class HTMLIM(ElementBase):
name = 'html'
plugin_attrib = 'html'
interfaces = set(('html'))
+ plugin_attrib_map = set()
+ plugin_xml_map = set()
def setHtml(self, html):
if issinstance(html, str):
diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py
index 68a429e0..3961ead6 100644
--- a/sleekxmpp/stanza/iq.py
+++ b/sleekxmpp/stanza/iq.py
@@ -5,7 +5,7 @@ from .. xmlstream.handler.waiter import Waiter
from .. xmlstream.matcher.id import MatcherId
class Iq(StanzaBase):
- interfaces = set(('type', 'to', 'from', 'id', 'body', 'subject'))
+ interfaces = set(('type', 'to', 'from', 'id','query'))
types = set(('get', 'result', 'set', 'error'))
name = 'iq'
namespace = 'jabber:client'
@@ -13,7 +13,19 @@ class Iq(StanzaBase):
def __init__(self, *args, **kwargs):
StanzaBase.__init__(self, *args, **kwargs)
if self['id'] == '':
- self['id'] = self.stream.getId()
+ self['id'] = self.stream.getNewId()
+
+ def exception(self, text):
+ self.reply()
+ self['error']['condition'] = 'undefined-condition'
+ self['error']['text'] = text
+ self.send()
+
+ def unhandled(self):
+ self.reply()
+ self['error']['condition'] = 'feature-not-implemented'
+ self['error']['text'] = 'No handlers registered for this request.'
+ self.send()
def result(self):
self['type'] = 'result'
@@ -36,6 +48,29 @@ class Iq(StanzaBase):
self.clear()
StanzaBase.setPayload(self, value)
+ def setQuery(self, value):
+ query = self.xml.find("{%s}query" % value)
+ if query is None:
+ self.clear()
+ query = ET.Element("{%s}query" % value)
+ self.xml.append(query)
+ return self
+
+ def getQuery(self):
+ for child in self.getchildren():
+ if child.tag.endswith('query'):
+ ns =child.tag.split('}')[0]
+ if '{' in ns:
+ ns = ns[1:]
+ return ns
+ return ''
+
+ def delQuery(self):
+ for child in self.getchildren():
+ if child.tag.endswith('query'):
+ self.xml.remove(child)
+ return self
+
def unhandled(self):
pass
# returned unhandled error
diff --git a/sleekxmpp/stanza/message.py b/sleekxmpp/stanza/message.py
index 999f7924..d75421c8 100644
--- a/sleekxmpp/stanza/message.py
+++ b/sleekxmpp/stanza/message.py
@@ -4,7 +4,7 @@ from . error import Error
class Message(StanzaBase):
interfaces = set(('type', 'to', 'from', 'id', 'body', 'subject'))
- types = set((None, 'normal', 'chat', 'headline', 'error'))
+ types = set((None, 'normal', 'chat', 'headline', 'error', 'groupchat'))
sub_interfaces = set(('body', 'subject'))
name = 'message'
namespace = 'jabber:client'
@@ -22,9 +22,16 @@ class Message(StanzaBase):
def reply(self, body=None):
StanzaBase.reply(self)
+ del self['id']
if body is not None:
self['body'] = body
return self
+ def exception(self, text):
+ self.reply()
+ self['error']['condition'] = 'undefined-condition'
+ self['error']['text'] = text
+ self.send()
+
Message.plugin_attrib_map['error'] = Error
Message.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error
diff --git a/sleekxmpp/stanza/nick.py b/sleekxmpp/stanza/nick.py
index 438b5a9b..83f7a07b 100644
--- a/sleekxmpp/stanza/nick.py
+++ b/sleekxmpp/stanza/nick.py
@@ -1,10 +1,12 @@
from .. xmlstream.stanzabase import ElementBase, ET
-class HTMLIM(ElementBase):
+class Nick(ElementBase):
namespace = 'http://jabber.org/nick/nick'
name = 'nick'
plugin_attrib = 'nick'
interfaces = set(('nick'))
+ plugin_attrib_map = set()
+ plugin_xml_map = set()
def setNick(self, nick):
self.xml.text = nick
diff --git a/sleekxmpp/stanza/presence.py b/sleekxmpp/stanza/presence.py
index f591211b..cb6bd6ce 100644
--- a/sleekxmpp/stanza/presence.py
+++ b/sleekxmpp/stanza/presence.py
@@ -19,6 +19,8 @@ class Presence(StanzaBase):
if value in self.types:
if show is not None:
self.xml.remove(show)
+ if value == 'available':
+ value = ''
self._setAttr('type', value)
elif value in self.showtypes:
if show is None:
@@ -44,8 +46,18 @@ class Presence(StanzaBase):
out = 'available'
return out
- def delType(self):
- self.setType('available')
+ def reply(self):
+ if self['type'] == 'unsubscribe':
+ self['type'] = 'unsubscribed'
+ elif self['type'] == 'subscribe':
+ self['type'] = 'subscribed'
+ return StanzaBase.reply(self)
+
+ def exception(self, text):
+ self.reply()
+ self['error']['condition'] = 'undefined-condition'
+ self['error']['text'] = text
+ self.send()
Presence.plugin_attrib_map['error'] = Error
Presence.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error
diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py
index cb1c1c6f..21aaa161 100644
--- a/sleekxmpp/stanza/roster.py
+++ b/sleekxmpp/stanza/roster.py
@@ -36,7 +36,7 @@ class Roster(ElementBase):
if groupsxml is not None:
for groupxml in groupsxml:
item['groups'].append(groupxml.text)
- items[JID(itemxml.get('jid'))] = item
+ items[JID(itemxml.get('jid'))] = item
return items
def delItems(self):