changeset 1708:6d6eae490681

plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
author Goffi <goffi@goffi.org>
date Tue, 01 Dec 2015 13:55:48 +0100
parents 94c450972346
children c47ba491a85a
files src/plugins/plugin_xep_0277.py
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Tue Dec 01 12:45:14 2015 +0100
+++ b/src/plugins/plugin_xep_0277.py	Tue Dec 01 13:55:48 2015 +0100
@@ -207,14 +207,26 @@
             microblog_data['atom_id'] = unicode(id_elt)
 
         # title/content(s)
-        try:
-            title_elt = entry_elt.elements(NS_ATOM, 'title').next()
-        except StopIteration:
+
+        # FIXME: ATOM and XEP-0277 only allow 1 <title/> element
+        #        but in the wild we have some blogs with several ones
+        #        so we don't respect the standard for now (it doesn't break
+        #        anything anyway), and we'll find a better option later
+        # try:
+        #     title_elt = entry_elt.elements(NS_ATOM, 'title').next()
+        # except StopIteration:
+        #     msg = u'No atom title found in the pubsub item {}'.format(id_)
+        #     raise failure.Failure(exceptions.DataError(msg))
+        title_elts = list(entry_elt.elements(NS_ATOM, 'title'))
+        if not title_elts:
             msg = u'No atom title found in the pubsub item {}'.format(id_)
             raise failure.Failure(exceptions.DataError(msg))
+        for title_elt in title_elts:
+            yield parseElement(title_elt)
 
-        yield parseElement(title_elt)
-
+        # FIXME: as for <title/>, Atom only authorise at most 1 content
+        #        but XEP-0277 allows several ones. So for no we handle as
+        #        if more than one can be present
         for content_elt in entry_elt.elements(NS_ATOM, 'content'):
             yield parseElement(content_elt)