# HG changeset patch # User Goffi # Date 1571592866 -7200 # Node ID 93e8793a735a7762bbe461b3b36d9d34796f0b04 # Parent 948833e3b54244c895887b6f9a713dc122585660 plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port diff -r 948833e3b542 -r 93e8793a735a sat/plugins/plugin_xep_0060.py --- a/sat/plugins/plugin_xep_0060.py Fri Oct 18 17:51:44 2019 +0200 +++ b/sat/plugins/plugin_xep_0060.py Sun Oct 20 19:34:26 2019 +0200 @@ -17,23 +17,24 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +from collections import namedtuple +import urllib.request, urllib.parse, urllib.error +from functools import reduce + from sat.core.i18n import _ from sat.core.constants import Const as C from sat.core.log import getLogger -log = getLogger(__name__) from sat.core import exceptions from sat.tools import sat_defer from sat.tools.common import data_format -from twisted.words.protocols.jabber import jid, error -from twisted.internet import reactor, defer +from zope.interface import implementer + from wokkel import disco from wokkel import data_form from wokkel import generic -from zope.interface import implementer -from collections import namedtuple -import urllib.request, urllib.parse, urllib.error # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version # mam and rsm come from sat_tmp.wokkel too @@ -41,6 +42,11 @@ from wokkel import rsm from wokkel import mam +from twisted.words.protocols.jabber import jid, error +from twisted.internet import reactor, defer + + +log = getLogger(__name__) PLUGIN_INFO = { C.PI_NAME: "Publish-Subscribe", @@ -537,14 +543,16 @@ def _unwrapMAMMessage(self, message_elt): try: - item_elt = ( - next(message_elt.elements(mam.NS_MAM, "result").next() - .elements(C.NS_FORWARD, "forwarded").next() - .elements(C.NS_CLIENT, "message").next() - .elements("http://jabber.org/protocol/pubsub#event", "event").next() - .elements("http://jabber.org/protocol/pubsub#event", "items").next() - .elements("http://jabber.org/protocol/pubsub#event", "item")) - ) + item_elt = reduce( + lambda elt, ns_name: next(elt.elements(*ns_name)), + (message_elt, + (mam.NS_MAM, "result"), + (C.NS_FORWARD, "forwarded"), + (C.NS_CLIENT, "message"), + ("http://jabber.org/protocol/pubsub#event", "event"), + ("http://jabber.org/protocol/pubsub#event", "items"), + ("http://jabber.org/protocol/pubsub#event", "item"), + )) except StopIteration: raise exceptions.DataError("Can't find Item in MAM message element") return item_elt