diff options
author | Nathan Fritz <fritzy@netflint.net> | 2010-01-05 21:56:48 +0000 |
---|---|---|
committer | Nathan Fritz <fritzy@netflint.net> | 2010-01-05 21:56:48 +0000 |
commit | 093644ffbd6708121150c92359bce60408f924bb (patch) | |
tree | a7d6da57ff76a8e54b1ec3703aeffeed82f34fa1 /sleekxmpp/xmlstream | |
parent | 805afa4bc1f44598d786fddc92c5129c62464227 (diff) | |
download | slixmpp-093644ffbd6708121150c92359bce60408f924bb.tar.gz slixmpp-093644ffbd6708121150c92359bce60408f924bb.tar.bz2 slixmpp-093644ffbd6708121150c92359bce60408f924bb.tar.xz slixmpp-093644ffbd6708121150c92359bce60408f924bb.zip |
* major stanza improvements
* raise XMPPError in handler to reply with error stanza
* started work on pubsub stanzas
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r-- | sleekxmpp/xmlstream/stanzabase.py | 22 | ||||
-rw-r--r-- | sleekxmpp/xmlstream/xmlstream.py | 4 |
2 files changed, 16 insertions, 10 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index d941b8cb..30714dc0 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -1,5 +1,6 @@ from xml.etree import cElementTree as ET import logging +import traceback class JID(object): def __init__(self, jid): @@ -31,6 +32,7 @@ class ElementBase(object): plugin_tag_map = {} def __init__(self, xml=None, parent=None): + self.attrib = self # backwards compatibility hack self.parent = parent self.xml = xml self.plugins = {} @@ -42,6 +44,9 @@ class ElementBase(object): def match(self, xml): return xml.tag == self.tag + def find(self, xpath): # for backwards compatiblity, expose elementtree interface + return self.xml.find(xpath) + def setup(self, xml=None): if self.xml is None: self.xml = xml @@ -183,9 +188,8 @@ class StanzaBase(ElementBase): types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat')) sub_interfaces = tuple() - def __init__(self, stream, xml=None, stype=None, sto=None, sfrom=None, sid=None): + def __init__(self, stream=None, xml=None, stype=None, sto=None, sfrom=None, sid=None): self.stream = stream - self.namespace = stream.default_ns ElementBase.__init__(self, xml) if stype is not None: self['type'] = stype @@ -193,7 +197,9 @@ class StanzaBase(ElementBase): self['to'] = sto if sfrom is not None: self['from'] = sfrom - self.tag = "{%s}%s" % (self.stream.default_ns, self.name) + if stream is not None: + self.namespace = stream.default_ns + self.tag = "{%s}%s" % (self.namespace, self.name) def setType(self, value): if value in self.types: @@ -240,8 +246,8 @@ class StanzaBase(ElementBase): def unhandled(self): pass - def exception(self, text): - logging.error(text) + def exception(self, e): + logging.error(traceback.format_tb(e)) def send(self): self.stream.sendRaw(str(self)) @@ -257,13 +263,13 @@ class StanzaBase(ElementBase): else: ixmlns = '' nsbuffer = '' - if xmlns != ixmlns and ixmlns != '' and ixmlns != self.stream.default_ns: - if ixmlns in self.stream.namespace_map: + if xmlns != ixmlns and ixmlns != '' and ixmlns != self.namespace: + if self.stream is not None and ixmlns in self.stream.namespace_map: if self.stream.namespace_map[ixmlns] != '': itag = "%s:%s" % (self.stream.namespace_map[ixmlns], itag) else: nsbuffer = """ xmlns="%s\"""" % ixmlns - if ixmlns not in (xmlns, self.namespace): + if ixmlns not in ('', xmlns, self.namespace): nsbuffer = """ xmlns="%s\"""" % ixmlns newoutput.append("<%s" % itag) newoutput.append(nsbuffer) diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index ee884504..cf61ba31 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -281,8 +281,8 @@ class XMLStream(object): if etype == 'stanza': try: handler.run(args[0]) - except: - args[0].exception(traceback.format_exc()) + except Exception as e: + args[0].exception(e) elif etype == 'sched': try: handler.run(*args) |