# HG changeset patch # User Goffi # Date 1616852307 -3600 # Node ID fa796612adad82aac90e3062370304109c91e30d # Parent 2bd75fc2555d83c3f8ab62d7080f481c73ef2879 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`). diff -r 2bd75fc2555d -r fa796612adad sat/plugins/plugin_xep_0060.py --- a/sat/plugins/plugin_xep_0060.py Sat Mar 27 14:35:07 2021 +0100 +++ b/sat/plugins/plugin_xep_0060.py Sat Mar 27 14:38:27 2021 +0100 @@ -1181,7 +1181,10 @@ 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): diff -r 2bd75fc2555d -r fa796612adad sat/plugins/plugin_xep_0277.py --- a/sat/plugins/plugin_xep_0277.py Sat Mar 27 14:35:07 2021 +0100 +++ b/sat/plugins/plugin_xep_0277.py Sat Mar 27 14:38:27 2021 +0100 @@ -415,12 +415,19 @@ ) # 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 @@ 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