Mercurial > libervia-backend
diff src/plugins/plugin_xep_0033.py @ 750:c8b9f675ac17
plugin XEP-0033: avoid the controlled error to explode (use return Failure(...) instead of raise)
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 16 Dec 2013 17:49:54 +0100 |
parents | 192b804ee446 |
children | bfabeedbf32e |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0033.py Mon Dec 16 14:48:28 2013 +0100 +++ b/src/plugins/plugin_xep_0033.py Mon Dec 16 17:49:54 2013 +0100 @@ -22,6 +22,7 @@ from wokkel import disco, iwokkel from zope.interface import implements from twisted.words.protocols.jabber.jid import JID +from twisted.python.failure import Failure import copy try: from twisted.words.protocols.xmlstream import XMPPHandler @@ -83,7 +84,7 @@ def discoCallback(entity): if entity is None: - raise AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!")) + return Failure(AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!"))) to = JID(mess_data["to"].host) if to != entity: logging.warning(_("Stanzas using XEP-0033 should be addressed to %s, not %s!") % (entity, to)) @@ -94,8 +95,8 @@ for type_, jid_ in entries: element.addChild(domish.Element((None, 'address'), None, {'type': type_, 'jid': jid_})) # when the prosody plugin is completed, we can immediately return mess_data from here - return self.sendAndStoreMessage(mess_data, entries, profile) - + self.sendAndStoreMessage(mess_data, entries, profile) + return Failure(MessageSentAndStored("XEP-0033 took over")) d = self.host.requestServerDisco(NS_ADDRESS, profile_key=profile) d.addCallbacks(discoCallback, lambda dummy: discoCallback(None)) return d @@ -105,7 +106,7 @@ def sendAndStoreMessage(self, mess_data, entries, profile): """Check if target servers support XEP-0033, send and store the messages - @raise: a friendly failure to let the core know that we sent the message already + @return: a friendly failure to let the core know that we sent the message already Later we should be able to remove this method because: # XXX: sending the messages should be done by the local server @@ -145,8 +146,6 @@ d = defer.Deferred().addCallback(lambda dummy: self.internal_data.pop(timestamp)) defer.DeferredList(defer_list).chainDeferred(d) - raise MessageSentAndStored("XEP-0033 took over") - def messageReceivedTrigger(self, message, post_treat, profile): """In order to save the addressing information in the history""" def post_treat_addr(data, addresses):