summaryrefslogtreecommitdiff
path: root/sleekxmpp/exceptions.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-19 00:08:47 -0700
committerLance Stout <lancestout@gmail.com>2011-08-19 01:04:20 -0700
commitf92f96325ac12160554cdf94d98b6742671d67a1 (patch)
tree9b6057be903a1f96324f1c252f1141a6c130c8f8 /sleekxmpp/exceptions.py
parentb98555c512ddb7452c9a217b1024b9e3163dea99 (diff)
downloadslixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.tar.gz
slixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.tar.bz2
slixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.tar.xz
slixmpp-f92f96325ac12160554cdf94d98b6742671d67a1.zip
Make Iq exceptions more discoverable and simpler to use.
IqError and IqTimeout now extend XMPPError, so if you don't care about the difference, you can use: try: self.do_something_with_iqs() except XMPPError: # Error? Timeout? I don't care! pass If you do need to distinguish between timeouts and error replies, you can still continue to use: try: self.do_somethin_with_iqs() except IqError as err: pass except IqTimeout: pass If you don't catch any Iq errors and you're processing a stanza then an error response will be sent, just like normal if you raise XMPPError or any other exception, except that the error messages will be generic to prevent leaking too much information.
Diffstat (limited to 'sleekxmpp/exceptions.py')
-rw-r--r--sleekxmpp/exceptions.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/sleekxmpp/exceptions.py b/sleekxmpp/exceptions.py
index 49d0f940..61d24f6b 100644
--- a/sleekxmpp/exceptions.py
+++ b/sleekxmpp/exceptions.py
@@ -20,9 +20,9 @@ class XMPPError(Exception):
Meant for use in SleekXMPP plugins and applications using SleekXMPP.
"""
- def __init__(self, condition='undefined-condition', text=None, etype=None,
- extension=None, extension_ns=None, extension_args=None,
- clear=True):
+ def __init__(self, condition='undefined-condition', text=None,
+ etype='cancel', extension=None, extension_ns=None,
+ extension_args=None, clear=True):
"""
Create a new XMPPError exception.
@@ -31,8 +31,10 @@ class XMPPError(Exception):
Arguments:
condition -- The XMPP defined error condition.
+ Defaults to 'undefined-condition'.
text -- Human readable text describing the error.
etype -- The XMPP error type, such as cancel or modify.
+ Defaults to 'cancel'.
extension -- Tag name of the extension's XML content.
extension_ns -- XML namespace of the extensions' XML content.
extension_args -- Content and attributes for the extension
@@ -54,7 +56,7 @@ class XMPPError(Exception):
self.extension_args = extension_args
-class IqTimeout(Exception):
+class IqTimeout(XMPPError):
"""
An exception which indicates that an IQ request response has not been
@@ -62,10 +64,13 @@ class IqTimeout(Exception):
"""
def __init__(self, iq):
- self.iq = iq
+ super(IqTimeout, self).__init__(
+ condition='remote-server-timeout',
+ etype='cancel')
+ self.iq = iq
-class IqError(Exception):
+class IqError(XMPPError):
"""
An exception raised when an Iq stanza of type 'error' is received
@@ -73,4 +78,9 @@ class IqError(Exception):
"""
def __init__(self, iq):
+ super(IqError, self).__init__(
+ condition=iq['error']['condition'],
+ text=iq['error']['text'],
+ etype=iq['error']['type'])
+
self.iq = iq