diff options
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/clientxmpp.py | 11 | ||||
-rw-r--r-- | sleekxmpp/exceptions.py | 21 | ||||
-rw-r--r-- | sleekxmpp/stanza/iq.py | 8 | ||||
-rw-r--r-- | sleekxmpp/test/sleektest.py | 1 |
4 files changed, 32 insertions, 9 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py index 2019b239..91106076 100644 --- a/sleekxmpp/clientxmpp.py +++ b/sleekxmpp/clientxmpp.py @@ -236,8 +236,8 @@ class ClientXMPP(BaseXMPP): 'subscription': subscription, 'groups': groups}} response = iq.send(block, timeout, callback) - if response in [False, None] or not isinstance(response, Iq): - return response + if response is None: + return None return response['type'] == 'result' def del_roster_item(self, jid): @@ -270,12 +270,7 @@ class ClientXMPP(BaseXMPP): iq.enable('roster') response = iq.send(block, timeout, callback) - if response == False: - self.event('roster_timeout') - - if response in [False, None] or not isinstance(response, Iq): - return response - else: + if callback is None: return self._handle_roster(response, request=True) def _handle_stream_features(self, features): diff --git a/sleekxmpp/exceptions.py b/sleekxmpp/exceptions.py index 4727f0c6..8329a3c3 100644 --- a/sleekxmpp/exceptions.py +++ b/sleekxmpp/exceptions.py @@ -52,3 +52,24 @@ class XMPPError(Exception): self.extension = extension self.extension_ns = extension_ns self.extension_args = extension_args + + +class IqTimeout(Exception): + + """ + An exception which indicates that an IQ request response has not been + received within the alloted time window. + """ + + def __init__(self, iq): + self.iq = iq + +class IqError(Exception): + + """ + An exception raised when an Iq stanza of type 'error' is received + after making a blocking send call. + """ + + def __init__(self, iq): + self.iq = iq diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py index 4a12a87e..f05dad17 100644 --- a/sleekxmpp/stanza/iq.py +++ b/sleekxmpp/stanza/iq.py @@ -11,6 +11,7 @@ from sleekxmpp.stanza.rootstanza import RootStanza from sleekxmpp.xmlstream import StanzaBase, ET from sleekxmpp.xmlstream.handler import Waiter, Callback from sleekxmpp.xmlstream.matcher import MatcherId +from sleekxmpp.exceptions import IqTimeout, IqError class Iq(RootStanza): @@ -197,7 +198,12 @@ class Iq(RootStanza): waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id'])) self.stream.register_handler(waitfor) StanzaBase.send(self, now=now) - return waitfor.wait(timeout) + result = waitfor.wait(timeout) + if not result: + raise IqTimeout(self) + if result['type'] == 'error': + raise IqError(result) + return result else: return StanzaBase.send(self, now=now) diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py index 7802a9bc..b607a94b 100644 --- a/sleekxmpp/test/sleektest.py +++ b/sleekxmpp/test/sleektest.py @@ -16,6 +16,7 @@ import sleekxmpp from sleekxmpp import ClientXMPP, ComponentXMPP from sleekxmpp.stanza import Message, Iq, Presence from sleekxmpp.test import TestSocket, TestLiveSocket +from sleekxmpp.exceptions import XMPPError, IqTimeout, IqError from sleekxmpp.xmlstream import ET, register_stanza_plugin from sleekxmpp.xmlstream import ElementBase, StanzaBase from sleekxmpp.xmlstream.tostring import tostring |