comparison sat/plugins/plugin_xep_0060.py @ 3062:93e8793a735a

plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
author Goffi <goffi@goffi.org>
date Sun, 20 Oct 2019 19:34:26 +0200
parents ab2696e34d29
children 73db9db8b9e1
comparison
equal deleted inserted replaced
3061:948833e3b542 3062:93e8793a735a
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20
21 from collections import namedtuple
22 import urllib.request, urllib.parse, urllib.error
23 from functools import reduce
24
20 from sat.core.i18n import _ 25 from sat.core.i18n import _
21 from sat.core.constants import Const as C 26 from sat.core.constants import Const as C
22 from sat.core.log import getLogger 27 from sat.core.log import getLogger
23 28
24 log = getLogger(__name__)
25 from sat.core import exceptions 29 from sat.core import exceptions
26 from sat.tools import sat_defer 30 from sat.tools import sat_defer
27 from sat.tools.common import data_format 31 from sat.tools.common import data_format
28 32
29 from twisted.words.protocols.jabber import jid, error 33 from zope.interface import implementer
30 from twisted.internet import reactor, defer 34
31 from wokkel import disco 35 from wokkel import disco
32 from wokkel import data_form 36 from wokkel import data_form
33 from wokkel import generic 37 from wokkel import generic
34 from zope.interface import implementer
35 from collections import namedtuple
36 import urllib.request, urllib.parse, urllib.error
37 38
38 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version 39 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version
39 # mam and rsm come from sat_tmp.wokkel too 40 # mam and rsm come from sat_tmp.wokkel too
40 from wokkel import pubsub 41 from wokkel import pubsub
41 from wokkel import rsm 42 from wokkel import rsm
42 from wokkel import mam 43 from wokkel import mam
43 44
45 from twisted.words.protocols.jabber import jid, error
46 from twisted.internet import reactor, defer
47
48
49 log = getLogger(__name__)
44 50
45 PLUGIN_INFO = { 51 PLUGIN_INFO = {
46 C.PI_NAME: "Publish-Subscribe", 52 C.PI_NAME: "Publish-Subscribe",
47 C.PI_IMPORT_NAME: "XEP-0060", 53 C.PI_IMPORT_NAME: "XEP-0060",
48 C.PI_TYPE: "XEP", 54 C.PI_TYPE: "XEP",
535 service, nodeIdentifier, items, client.pubsub_client.parent.jid 541 service, nodeIdentifier, items, client.pubsub_client.parent.jid
536 ) 542 )
537 543
538 def _unwrapMAMMessage(self, message_elt): 544 def _unwrapMAMMessage(self, message_elt):
539 try: 545 try:
540 item_elt = ( 546 item_elt = reduce(
541 next(message_elt.elements(mam.NS_MAM, "result").next() 547 lambda elt, ns_name: next(elt.elements(*ns_name)),
542 .elements(C.NS_FORWARD, "forwarded").next() 548 (message_elt,
543 .elements(C.NS_CLIENT, "message").next() 549 (mam.NS_MAM, "result"),
544 .elements("http://jabber.org/protocol/pubsub#event", "event").next() 550 (C.NS_FORWARD, "forwarded"),
545 .elements("http://jabber.org/protocol/pubsub#event", "items").next() 551 (C.NS_CLIENT, "message"),
546 .elements("http://jabber.org/protocol/pubsub#event", "item")) 552 ("http://jabber.org/protocol/pubsub#event", "event"),
547 ) 553 ("http://jabber.org/protocol/pubsub#event", "items"),
554 ("http://jabber.org/protocol/pubsub#event", "item"),
555 ))
548 except StopIteration: 556 except StopIteration:
549 raise exceptions.DataError("Can't find Item in MAM message element") 557 raise exceptions.DataError("Can't find Item in MAM message element")
550 return item_elt 558 return item_elt
551 559
552 def _getItems(self, service="", node="", max_items=10, item_ids=None, sub_id=None, 560 def _getItems(self, service="", node="", max_items=10, item_ids=None, sub_id=None,