2011-12-05 16:55:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-03-26 21:32:16 +00:00
|
|
|
"""
|
2011-12-05 16:55:05 +00:00
|
|
|
sleekxmpp.exceptions
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
2010-03-26 21:32:16 +00:00
|
|
|
|
2011-12-05 16:55:05 +00:00
|
|
|
Part of SleekXMPP: The Sleek XMPP Library
|
|
|
|
|
|
|
|
:copyright: (c) 2011 Nathanael C. Fritz
|
|
|
|
:license: MIT, see LICENSE for more details
|
2010-03-26 21:32:16 +00:00
|
|
|
"""
|
|
|
|
|
2010-10-06 19:12:39 +00:00
|
|
|
|
2010-01-05 21:56:48 +00:00
|
|
|
class XMPPError(Exception):
|
2010-08-11 22:21:12 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
A generic exception that may be raised while processing an XMPP stanza
|
|
|
|
to indicate that an error response stanza should be sent.
|
|
|
|
|
2011-12-05 16:55:05 +00:00
|
|
|
The exception method for stanza objects extending
|
|
|
|
:class:`~sleekxmpp.stanza.rootstanza.RootStanza` will create an error
|
|
|
|
stanza and initialize any additional substanzas using the extension
|
|
|
|
information included in the exception.
|
2010-08-11 22:21:12 +00:00
|
|
|
|
|
|
|
Meant for use in SleekXMPP plugins and applications using SleekXMPP.
|
2011-12-05 16:55:05 +00:00
|
|
|
|
|
|
|
Extension information can be included to add additional XML elements
|
|
|
|
to the generated error stanza.
|
|
|
|
|
|
|
|
:param condition: The XMPP defined error condition.
|
|
|
|
Defaults to ``'undefined-condition'``.
|
|
|
|
:param text: Human readable text describing the error.
|
|
|
|
:param etype: The XMPP error type, such as ``'cancel'`` or ``'modify'``.
|
|
|
|
Defaults to ``'cancel'``.
|
|
|
|
:param extension: Tag name of the extension's XML content.
|
|
|
|
:param extension_ns: XML namespace of the extensions' XML content.
|
|
|
|
:param extension_args: Content and attributes for the extension
|
|
|
|
element. Same as the additional arguments to
|
|
|
|
the :class:`~xml.etree.ElementTree.Element`
|
|
|
|
constructor.
|
|
|
|
:param clear: Indicates if the stanza's contents should be
|
|
|
|
removed before replying with an error.
|
|
|
|
Defaults to ``True``.
|
2010-08-11 22:21:12 +00:00
|
|
|
"""
|
|
|
|
|
2011-08-19 07:08:47 +00:00
|
|
|
def __init__(self, condition='undefined-condition', text=None,
|
|
|
|
etype='cancel', extension=None, extension_ns=None,
|
|
|
|
extension_args=None, clear=True):
|
2010-10-25 19:09:56 +00:00
|
|
|
if extension_args is None:
|
|
|
|
extension_args = {}
|
|
|
|
|
2010-08-11 22:21:12 +00:00
|
|
|
self.condition = condition
|
|
|
|
self.text = text
|
|
|
|
self.etype = etype
|
2011-02-11 20:20:26 +00:00
|
|
|
self.clear = clear
|
2010-08-11 22:21:12 +00:00
|
|
|
self.extension = extension
|
|
|
|
self.extension_ns = extension_ns
|
|
|
|
self.extension_args = extension_args
|
2011-05-31 19:48:43 +00:00
|
|
|
|
|
|
|
|
2011-08-19 07:08:47 +00:00
|
|
|
class IqTimeout(XMPPError):
|
2011-05-31 19:48:43 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
An exception which indicates that an IQ request response has not been
|
|
|
|
received within the alloted time window.
|
|
|
|
"""
|
|
|
|
|
2011-06-01 22:28:33 +00:00
|
|
|
def __init__(self, iq):
|
2011-08-19 07:08:47 +00:00
|
|
|
super(IqTimeout, self).__init__(
|
|
|
|
condition='remote-server-timeout',
|
|
|
|
etype='cancel')
|
2011-06-01 22:28:33 +00:00
|
|
|
|
2012-06-19 08:29:48 +00:00
|
|
|
#: The :class:`~sleekxmpp.stanza.iq.Iq` stanza whose response
|
2011-12-05 16:55:05 +00:00
|
|
|
#: did not arrive before the timeout expired.
|
2011-08-19 07:08:47 +00:00
|
|
|
self.iq = iq
|
2011-08-18 09:46:48 +00:00
|
|
|
|
2012-06-19 08:29:48 +00:00
|
|
|
|
2011-08-19 07:08:47 +00:00
|
|
|
class IqError(XMPPError):
|
2011-05-31 19:48:43 +00:00
|
|
|
|
2011-06-01 22:28:33 +00:00
|
|
|
"""
|
|
|
|
An exception raised when an Iq stanza of type 'error' is received
|
|
|
|
after making a blocking send call.
|
|
|
|
"""
|
|
|
|
|
2011-05-31 19:48:43 +00:00
|
|
|
def __init__(self, iq):
|
2011-08-19 07:08:47 +00:00
|
|
|
super(IqError, self).__init__(
|
|
|
|
condition=iq['error']['condition'],
|
|
|
|
text=iq['error']['text'],
|
|
|
|
etype=iq['error']['type'])
|
|
|
|
|
2011-12-05 16:55:05 +00:00
|
|
|
#: The :class:`~sleekxmpp.stanza.iq.Iq` error result stanza.
|
2011-05-31 19:48:43 +00:00
|
|
|
self.iq = iq
|