* 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)
This commit is contained in:
Nathan Fritz
2009-12-17 01:54:22 +00:00
parent 6897a0b57c
commit 07018c0afa
13 changed files with 262 additions and 125 deletions

View File

@@ -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):

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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):