comparison sat/plugins/plugin_xep_0060.py @ 3394:23af257ae780

plugin XEP-0060: use `xml_tools.parse` instead of `wokkel.generic.parseXml`: `xml_tools.parse` does a better parsing, as wokkel's `parseXml` may be missing text nodes.
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:15 +0100
parents 77177b13ff54
children f37e6e78db12
comparison
equal deleted inserted replaced
3393:2b6f69f6df8c 3394:23af257ae780
24 from twisted.words.xish import domish 24 from twisted.words.xish import domish
25 from twisted.words.protocols.jabber import jid, error 25 from twisted.words.protocols.jabber import jid, error
26 from twisted.internet import reactor, defer 26 from twisted.internet import reactor, defer
27 from wokkel import disco 27 from wokkel import disco
28 from wokkel import data_form 28 from wokkel import data_form
29 from wokkel import generic
30 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version 29 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version
31 # mam and rsm come from sat_tmp.wokkel too 30 # mam and rsm come from sat_tmp.wokkel too
32 from wokkel import pubsub 31 from wokkel import pubsub
33 from wokkel import rsm 32 from wokkel import rsm
34 from wokkel import mam 33 from wokkel import mam
35 from sat.core.i18n import _ 34 from sat.core.i18n import _
36 from sat.core.constants import Const as C 35 from sat.core.constants import Const as C
37 from sat.core.log import getLogger 36 from sat.core.log import getLogger
38 from sat.core import exceptions 37 from sat.core import exceptions
39 from sat.tools import sat_defer 38 from sat.tools import sat_defer
39 from sat.tools import xml_tools
40 from sat.tools.common import data_format 40 from sat.tools.common import data_format
41 41
42 42
43 log = getLogger(__name__) 43 log = getLogger(__name__)
44 44
451 451
452 def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra_ser="", 452 def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra_ser="",
453 profile_key=C.PROF_KEY_NONE): 453 profile_key=C.PROF_KEY_NONE):
454 client = self.host.getClient(profile_key) 454 client = self.host.getClient(profile_key)
455 service = None if not service else jid.JID(service) 455 service = None if not service else jid.JID(service)
456 payload = generic.parseXml(payload.encode()) 456 payload = xml_tools.parse(payload)
457 extra = data_format.deserialise(extra_ser) 457 extra = data_format.deserialise(extra_ser)
458 d = self.sendItem( 458 d = self.sendItem(
459 client, service, nodeIdentifier, payload, item_id or None, extra 459 client, service, nodeIdentifier, payload, item_id or None, extra
460 ) 460 )
461 d.addCallback(lambda ret: ret or "") 461 d.addCallback(lambda ret: ret or "")
464 def _sendItems(self, service, nodeIdentifier, items, extra_ser=None, 464 def _sendItems(self, service, nodeIdentifier, items, extra_ser=None,
465 profile_key=C.PROF_KEY_NONE): 465 profile_key=C.PROF_KEY_NONE):
466 client = self.host.getClient(profile_key) 466 client = self.host.getClient(profile_key)
467 service = None if not service else jid.JID(service) 467 service = None if not service else jid.JID(service)
468 try: 468 try:
469 items = [generic.parseXml(item.encode()) for item in items] 469 items = [xml_tools.parse(item) for item in items]
470 except Exception as e: 470 except Exception as e:
471 raise exceptions.DataError(_("Can't parse items: {msg}").format( 471 raise exceptions.DataError(_("Can't parse items: {msg}").format(
472 msg=e)) 472 msg=e))
473 extra = data_format.deserialise(extra_ser) 473 extra = data_format.deserialise(extra_ser)
474 d = self.sendItems( 474 d = self.sendItems(