plugin XEP-0277: better resilience to broken items:

- if `author` element can't be found, `publisher` attribute, then `IQ`'s `from` attributes
  are used as fallback to find author jid
- fix categories (tags) parsing if `author` element is not found
- remove items which have failed parsing from `mbGet` results (instead of using `None`).
This commit is contained in:
Goffi 2021-03-27 14:38:27 +01:00
commit 69112bcd79
2 changed files with 18 additions and 8 deletions

View file

@ -1181,7 +1181,10 @@ class XEP_0060(object):
log.warning(f"Error while parsing item: {failure_.value}")
d = defer.gatherResults([item_cb(item).addErrback(eb) for item in items])
d.addCallback(lambda parsed_items: (parsed_items, metadata))
d.addCallback(lambda parsed_items: (
[i for i in parsed_items if i is not None],
metadata
))
return d
def serDList(self, results, failure_result=None):

View file

@ -415,12 +415,19 @@ class XEP_0277(object):
)
# author
publisher = item_elt.getAttribute("publisher")
try:
author_elt = next(entry_elt.elements(NS_ATOM, "author"))
except StopIteration:
log.debug("Can't find author element in item {}".format(id_))
if publisher:
microblog_data["author_jid"] = publisher
microblog_data["author_jid_verified"] = True
else:
iq_elt = xml_tools.findAncestor(item_elt, "iq", C.NS_CLIENT)
microblog_data["author_jid"] = iq_elt["from"]
microblog_data["author_jid_verified"] = False
else:
publisher = item_elt.getAttribute("publisher")
# name
try:
name_elt = next(author_elt.elements(NS_ATOM, "name"))
@ -470,12 +477,12 @@ class XEP_0277(object):
else:
microblog_data["author_email"] = str(email_elt)
# categories
categories = [
category_elt.getAttribute("term", "")
for category_elt in entry_elt.elements(NS_ATOM, "category")
]
microblog_data["tags"] = categories
# categories
categories = [
category_elt.getAttribute("term", "")
for category_elt in entry_elt.elements(NS_ATOM, "category")
]
microblog_data["tags"] = categories
## the trigger ##
# if other plugins have things to add or change