From 004eabf80959ebcaeddf2e15065bd4f50ad10974 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 17 Aug 2011 21:30:47 -0700 Subject: Update plugins that use Iq stanzas to work with new exceptions. --- sleekxmpp/plugins/xep_0078/legacyauth.py | 39 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'sleekxmpp/plugins/xep_0078/legacyauth.py') diff --git a/sleekxmpp/plugins/xep_0078/legacyauth.py b/sleekxmpp/plugins/xep_0078/legacyauth.py index bdd2df67..edb8f314 100644 --- a/sleekxmpp/plugins/xep_0078/legacyauth.py +++ b/sleekxmpp/plugins/xep_0078/legacyauth.py @@ -56,11 +56,17 @@ class xep_0078(base_plugin): iq['type'] = 'get' iq['to'] = self.xmpp.boundjid.host iq['auth']['username'] = self.xmpp.boundjid.user - resp = iq.send(now=True) - if resp is None or resp['type'] != 'result': + try: + resp = iq.send(now=True) + except IqError: log.info("Authentication failed: %s" % resp['error']['condition']) - self.xmpp.event('failed_auth', resp, direct=True) + self.xmpp.event('failed_auth', direct=True) + self.xmpp.disconnect() + return True + except IqTimeout: + log.info("Authentication failed: %s" % 'timeout') + self.xmpp.event('failed_auth', direct=True) self.xmpp.disconnect() return True @@ -91,18 +97,23 @@ class xep_0078(base_plugin): iq['auth']['password'] = self.xmpp.password # Step 3: Send credentials - result = iq.send(now=True) - if result is not None and result.attrib['type'] == 'result': - self.xmpp.features.add('auth') - - self.xmpp.authenticated = True - log.debug("Established Session") - self.xmpp.sessionstarted = True - self.xmpp.session_started_event.set() - self.xmpp.event('session_start') - else: + try: + result = iq.send(now=True) + except IqError as err: log.info("Authentication failed") self.xmpp.disconnect() - self.xmpp.event("failed_auth") + self.xmpp.event("failed_auth", direct=True) + except IqTimeout: + log.info("Authentication failed") + self.xmpp.disconnect() + self.xmpp.event("failed_auth", direct=True) + + self.xmpp.features.add('auth') + + self.xmpp.authenticated = True + log.debug("Established Session") + self.xmpp.sessionstarted = True + self.xmpp.session_started_event.set() + self.xmpp.event('session_start') return True -- cgit v1.2.3