mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Add StreamError stanza and a stream_error event.
Note that the stream may automatically attempt to reconnect when a stream error is received.
This commit is contained in:
parent
cb85d4a529
commit
2004ddd678
4 changed files with 72 additions and 5 deletions
|
@ -15,7 +15,7 @@ import logging
|
||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
from sleekxmpp import plugins
|
from sleekxmpp import plugins
|
||||||
|
|
||||||
from sleekxmpp.stanza import Message, Presence, Iq, Error
|
from sleekxmpp.stanza import Message, Presence, Iq, Error, StreamError
|
||||||
from sleekxmpp.stanza.roster import Roster
|
from sleekxmpp.stanza.roster import Roster
|
||||||
from sleekxmpp.stanza.nick import Nick
|
from sleekxmpp.stanza.nick import Nick
|
||||||
from sleekxmpp.stanza.htmlim import HTMLIM
|
from sleekxmpp.stanza.htmlim import HTMLIM
|
||||||
|
@ -128,6 +128,10 @@ class BaseXMPP(XMLStream):
|
||||||
Callback('Presence',
|
Callback('Presence',
|
||||||
MatchXPath("{%s}presence" % self.default_ns),
|
MatchXPath("{%s}presence" % self.default_ns),
|
||||||
self._handle_presence))
|
self._handle_presence))
|
||||||
|
self.register_handler(
|
||||||
|
Callback('Stream Error',
|
||||||
|
MatchXPath("{%s}error" % self.stream_ns),
|
||||||
|
self._handle_stream_error))
|
||||||
|
|
||||||
self.add_event_handler('presence_subscribe',
|
self.add_event_handler('presence_subscribe',
|
||||||
self._handle_subscribe)
|
self._handle_subscribe)
|
||||||
|
@ -135,9 +139,10 @@ class BaseXMPP(XMLStream):
|
||||||
self._handle_disconnected)
|
self._handle_disconnected)
|
||||||
|
|
||||||
# Set up the XML stream with XMPP's root stanzas.
|
# Set up the XML stream with XMPP's root stanzas.
|
||||||
self.registerStanza(Message)
|
self.register_stanza(Message)
|
||||||
self.registerStanza(Iq)
|
self.register_stanza(Iq)
|
||||||
self.registerStanza(Presence)
|
self.register_stanza(Presence)
|
||||||
|
self.register_stanza(StreamError)
|
||||||
|
|
||||||
# Initialize a few default stanza plugins.
|
# Initialize a few default stanza plugins.
|
||||||
register_stanza_plugin(Iq, Roster)
|
register_stanza_plugin(Iq, Roster)
|
||||||
|
@ -579,6 +584,9 @@ class BaseXMPP(XMLStream):
|
||||||
"""When disconnected, reset the roster"""
|
"""When disconnected, reset the roster"""
|
||||||
self.roster = {}
|
self.roster = {}
|
||||||
|
|
||||||
|
def _handle_stream_error(self, error):
|
||||||
|
self.event('stream_error', error)
|
||||||
|
|
||||||
def _handle_message(self, msg):
|
def _handle_message(self, msg):
|
||||||
"""Process incoming message stanzas."""
|
"""Process incoming message stanzas."""
|
||||||
self.event('message', msg)
|
self.event('message', msg)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
|
|
||||||
from sleekxmpp.stanza.error import Error
|
from sleekxmpp.stanza.error import Error
|
||||||
|
from sleekxmpp.stanza.stream_error import StreamError
|
||||||
from sleekxmpp.stanza.iq import Iq
|
from sleekxmpp.stanza.iq import Iq
|
||||||
from sleekxmpp.stanza.message import Message
|
from sleekxmpp.stanza.message import Message
|
||||||
from sleekxmpp.stanza.presence import Presence
|
from sleekxmpp.stanza.presence import Presence
|
||||||
|
|
|
@ -224,4 +224,3 @@ class Iq(RootStanza):
|
||||||
else:
|
else:
|
||||||
StanzaBase._set_stanza_values(self, values)
|
StanzaBase._set_stanza_values(self, values)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
59
sleekxmpp/stanza/stream_error.py
Normal file
59
sleekxmpp/stanza/stream_error.py
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
"""
|
||||||
|
SleekXMPP: The Sleek XMPP Library
|
||||||
|
Copyright (C) 2010 Nathanael C. Fritz
|
||||||
|
This file is part of SleekXMPP.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from sleekxmpp.stanza.error import Error
|
||||||
|
from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin
|
||||||
|
|
||||||
|
|
||||||
|
class StreamError(Error):
|
||||||
|
|
||||||
|
"""
|
||||||
|
XMPP stanzas of type 'error' should include an <error> stanza that
|
||||||
|
describes the nature of the error and how it should be handled.
|
||||||
|
|
||||||
|
Use the 'XEP-0086: Error Condition Mappings' plugin to include error
|
||||||
|
codes used in older XMPP versions.
|
||||||
|
|
||||||
|
The stream:error stanza is used to provide more information for
|
||||||
|
error that occur with the underlying XML stream itself, and not
|
||||||
|
a particular stanza.
|
||||||
|
|
||||||
|
Note: The StreamError stanza is the same as the normal Error stanza,
|
||||||
|
but with a different namespace.
|
||||||
|
|
||||||
|
Example error stanza:
|
||||||
|
<error type="cancel" code="404">
|
||||||
|
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
||||||
|
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">
|
||||||
|
The item was not found.
|
||||||
|
</text>
|
||||||
|
</error>
|
||||||
|
|
||||||
|
Stanza Interface:
|
||||||
|
code -- The error code used in older XMPP versions.
|
||||||
|
condition -- The name of the condition element.
|
||||||
|
text -- Human readable description of the error.
|
||||||
|
type -- Error type indicating how the error should be handled.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
conditions -- The set of allowable error condition elements.
|
||||||
|
condition_ns -- The namespace for the condition element.
|
||||||
|
types -- A set of values indicating how the error
|
||||||
|
should be treated.
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
setup -- Overrides ElementBase.setup.
|
||||||
|
get_condition -- Retrieve the name of the condition element.
|
||||||
|
set_condition -- Add a condition element.
|
||||||
|
del_condition -- Remove the condition element.
|
||||||
|
get_text -- Retrieve the contents of the <text> element.
|
||||||
|
set_text -- Set the contents of the <text> element.
|
||||||
|
del_text -- Remove the <text> element.
|
||||||
|
"""
|
||||||
|
|
||||||
|
namespace = 'http://etherx.jabber.org/streams'
|
Loading…
Reference in a new issue