Rename to slixmpp
[slixmpp.git] / slixmpp / exceptions.py
blob94bbf202044df0cbe81dd8b1e00363c90a292d00
1 # -*- coding: utf-8 -*-
2 """
3 slixmpp.exceptions
4 ~~~~~~~~~~~~~~~~~~~~
6 Part of Slixmpp: The Slick XMPP Library
8 :copyright: (c) 2011 Nathanael C. Fritz
9 :license: MIT, see LICENSE for more details
10 """
13 class XMPPError(Exception):
15 """
16 A generic exception that may be raised while processing an XMPP stanza
17 to indicate that an error response stanza should be sent.
19 The exception method for stanza objects extending
20 :class:`~slixmpp.stanza.rootstanza.RootStanza` will create an error
21 stanza and initialize any additional substanzas using the extension
22 information included in the exception.
24 Meant for use in Slixmpp plugins and applications using Slixmpp.
26 Extension information can be included to add additional XML elements
27 to the generated error stanza.
29 :param condition: The XMPP defined error condition.
30 Defaults to ``'undefined-condition'``.
31 :param text: Human readable text describing the error.
32 :param etype: The XMPP error type, such as ``'cancel'`` or ``'modify'``.
33 Defaults to ``'cancel'``.
34 :param extension: Tag name of the extension's XML content.
35 :param extension_ns: XML namespace of the extensions' XML content.
36 :param extension_args: Content and attributes for the extension
37 element. Same as the additional arguments to
38 the :class:`~xml.etree.ElementTree.Element`
39 constructor.
40 :param clear: Indicates if the stanza's contents should be
41 removed before replying with an error.
42 Defaults to ``True``.
43 """
45 def __init__(self, condition='undefined-condition', text='',
46 etype='cancel', extension=None, extension_ns=None,
47 extension_args=None, clear=True):
48 if extension_args is None:
49 extension_args = {}
51 self.condition = condition
52 self.text = text
53 self.etype = etype
54 self.clear = clear
55 self.extension = extension
56 self.extension_ns = extension_ns
57 self.extension_args = extension_args
60 class IqTimeout(XMPPError):
62 """
63 An exception which indicates that an IQ request response has not been
64 received within the alloted time window.
65 """
67 def __init__(self, iq):
68 super(IqTimeout, self).__init__(
69 condition='remote-server-timeout',
70 etype='cancel')
72 #: The :class:`~slixmpp.stanza.iq.Iq` stanza whose response
73 #: did not arrive before the timeout expired.
74 self.iq = iq
77 class IqError(XMPPError):
79 """
80 An exception raised when an Iq stanza of type 'error' is received
81 after making a blocking send call.
82 """
84 def __init__(self, iq):
85 super(IqError, self).__init__(
86 condition=iq['error']['condition'],
87 text=iq['error']['text'],
88 etype=iq['error']['type'])
90 #: The :class:`~slixmpp.stanza.iq.Iq` error result stanza.
91 self.iq = iq