summaryrefslogtreecommitdiff
path: root/sleekxmpp/basexmpp.py
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/basexmpp.py
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/basexmpp.py')
-rw-r--r--sleekxmpp/basexmpp.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py
index 2049206b..8f32c8f5 100644
--- a/sleekxmpp/basexmpp.py
+++ b/sleekxmpp/basexmpp.py
@@ -30,6 +30,8 @@ from . stanza.message import Message
from . stanza.iq import Iq
from . stanza.presence import Presence
from . stanza.roster import Roster
+from . stanza.nick import Nick
+from . stanza.htmlim import HTMLIM
import logging
import threading
@@ -38,7 +40,6 @@ def stanzaPlugin(stanza, plugin):
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
-stanzaPlugin(Iq, Roster)
class basexmpp(object):
def __init__(self):
@@ -61,9 +62,16 @@ class basexmpp(object):
self.registerStanza(Message)
self.registerStanza(Iq)
self.registerStanza(Presence)
+ self.stanzaPlugin(Iq, Roster)
+ self.stanzaPlugin(Message, Nick)
+ self.stanzaPlugin(Message, HTMLIM)
+
+ def stanzaPlugin(self, stanza, plugin):
+ stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
+ stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
def Message(self, *args, **kwargs):
- return Presence(self, *args, **kwargs)
+ return Message(self, *args, **kwargs)
def Iq(self, *args, **kwargs):
return Iq(self, *args, **kwargs)
@@ -191,14 +199,13 @@ class basexmpp(object):
message = self.Message(sto=mto, stype=mtype, sfrom=mfrom)
message['body'] = mbody
message['subject'] = msubject
- message['nick'] = mnick
- message['html'] = mhtml
+ if mnick is not None: message['nick'] = mnick
+ if mhtml is not None: message['html'] = mhtml
return message
def makePresence(self, pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None):
presence = self.Presence(stype=ptype, sfrom=pfrom, sto=pto)
- if pshow is not None:
- presence['type'] = pshow
+ if pshow is not None: presence['type'] = pshow
if pfrom is None: #maybe this should be done in stanzabase
presence['from'] = self.fulljid
presence['priority'] = ppriority
@@ -237,7 +244,10 @@ class basexmpp(object):
def _handlePresence(self, presence):
"""Update roster items based on presence"""
self.event("presence_%s" % presence['type'], presence)
- if not presence['type'] in ('available', 'unavailable'):
+ if presence['type'] in ('subscribe', 'subscribed', 'unsubscribe', 'unsubscribed'):
+ self.event('changed_subscription', presence)
+ return
+ elif not presence['type'] in ('available', 'unavailable'):
return
jid = presence['from'].bare
resource = presence['from'].resource
@@ -260,7 +270,7 @@ class basexmpp(object):
if wasoffline and show in ('available', 'away', 'xa', 'na', 'ffc'):
self.event("got_online", presence)
elif not wasoffline and show == 'unavailable':
- self.event("got_offline", eventdata)
+ self.event("got_offline", presence)
if len(self.roster[jid]['presence']) > 1:
del self.roster[jid]['presence'][resource]
else: