plugin XEP-0060: fixed payload parsing in sendItem

This commit is contained in:
Goffi 2020-05-18 23:38:21 +02:00
commit abbd14484b

View file

@ -453,6 +453,7 @@ class XEP_0060(object):
profile_key=C.PROF_KEY_NONE): profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key) client = self.host.getClient(profile_key)
service = None if not service else jid.JID(service) service = None if not service else jid.JID(service)
payload = generic.parseXml(payload.encode())
extra = data_format.deserialise(extra_ser) extra = data_format.deserialise(extra_ser)
d = self.sendItem( d = self.sendItem(
client, service, nodeIdentifier, payload, item_id or None, extra client, service, nodeIdentifier, payload, item_id or None, extra
@ -465,7 +466,7 @@ class XEP_0060(object):
client = self.host.getClient(profile_key) client = self.host.getClient(profile_key)
service = None if not service else jid.JID(service) service = None if not service else jid.JID(service)
try: try:
items = [generic.parseXml(item.encode('utf-8')) for item in items] items = [generic.parseXml(item.encode()) for item in items]
except Exception as e: except Exception as e:
raise exceptions.DataError(_("Can't parse items: {msg}").format( raise exceptions.DataError(_("Can't parse items: {msg}").format(
msg=e)) msg=e))
@ -492,11 +493,12 @@ class XEP_0060(object):
@param service(jid.JID, None): service to send the item to @param service(jid.JID, None): service to send the item to
None to use PEP None to use PEP
@param NodeIdentifier(unicode): PubSub node to use @param NodeIdentifier(unicode): PubSub node to use
@param payload(domish.Element, unicode): payload of the item to send @param payload(domish.Element): payload of the item to send
@param item_id(unicode, None): id to use or None to create one @param item_id(unicode, None): id to use or None to create one
@param extra(dict, None): extra option, not used yet @param extra(dict, None): extra option, not used yet
@return (unicode, None): id of the created item @return (unicode, None): id of the created item
""" """
assert isinstance(payload, domish.Element)
item_elt = domish.Element((pubsub.NS_PUBSUB, 'item')) item_elt = domish.Element((pubsub.NS_PUBSUB, 'item'))
if item_id is not None: if item_id is not None:
item_elt['id'] = item_id item_elt['id'] = item_id