Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0060.py @ 3272:4c98f4972db5
plugin XEP-0060: fixed payload parsing in sendItem
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 18 May 2020 23:38:21 +0200 |
parents | c2f958dde5d2 |
children | 384283adcce1 |
comparison
equal
deleted
inserted
replaced
3271:abca25af06d7 | 3272:4c98f4972db5 |
---|---|
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 extra = data_format.deserialise(extra_ser) | 457 extra = data_format.deserialise(extra_ser) |
457 d = self.sendItem( | 458 d = self.sendItem( |
458 client, service, nodeIdentifier, payload, item_id or None, extra | 459 client, service, nodeIdentifier, payload, item_id or None, extra |
459 ) | 460 ) |
460 d.addCallback(lambda ret: ret or "") | 461 d.addCallback(lambda ret: ret or "") |
463 def _sendItems(self, service, nodeIdentifier, items, extra_ser=None, | 464 def _sendItems(self, service, nodeIdentifier, items, extra_ser=None, |
464 profile_key=C.PROF_KEY_NONE): | 465 profile_key=C.PROF_KEY_NONE): |
465 client = self.host.getClient(profile_key) | 466 client = self.host.getClient(profile_key) |
466 service = None if not service else jid.JID(service) | 467 service = None if not service else jid.JID(service) |
467 try: | 468 try: |
468 items = [generic.parseXml(item.encode('utf-8')) for item in items] | 469 items = [generic.parseXml(item.encode()) for item in items] |
469 except Exception as e: | 470 except Exception as e: |
470 raise exceptions.DataError(_("Can't parse items: {msg}").format( | 471 raise exceptions.DataError(_("Can't parse items: {msg}").format( |
471 msg=e)) | 472 msg=e)) |
472 extra = data_format.deserialise(extra_ser) | 473 extra = data_format.deserialise(extra_ser) |
473 d = self.sendItems( | 474 d = self.sendItems( |
490 """High level method to send one item | 491 """High level method to send one item |
491 | 492 |
492 @param service(jid.JID, None): service to send the item to | 493 @param service(jid.JID, None): service to send the item to |
493 None to use PEP | 494 None to use PEP |
494 @param NodeIdentifier(unicode): PubSub node to use | 495 @param NodeIdentifier(unicode): PubSub node to use |
495 @param payload(domish.Element, unicode): payload of the item to send | 496 @param payload(domish.Element): payload of the item to send |
496 @param item_id(unicode, None): id to use or None to create one | 497 @param item_id(unicode, None): id to use or None to create one |
497 @param extra(dict, None): extra option, not used yet | 498 @param extra(dict, None): extra option, not used yet |
498 @return (unicode, None): id of the created item | 499 @return (unicode, None): id of the created item |
499 """ | 500 """ |
501 assert isinstance(payload, domish.Element) | |
500 item_elt = domish.Element((pubsub.NS_PUBSUB, 'item')) | 502 item_elt = domish.Element((pubsub.NS_PUBSUB, 'item')) |
501 if item_id is not None: | 503 if item_id is not None: |
502 item_elt['id'] = item_id | 504 item_elt['id'] = item_id |
503 item_elt.addChild(payload) | 505 item_elt.addChild(payload) |
504 d = defer.ensureDeferred(self.sendItems( | 506 d = defer.ensureDeferred(self.sendItems( |