comparison src/plugins/plugin_xep_0277.py @ 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 a72f04c67ac9
children c47ba491a85a
comparison
equal deleted inserted replaced
1707:94c450972346 1708:6d6eae490681
205 microblog_data['atom_id'] = "" 205 microblog_data['atom_id'] = ""
206 else: 206 else:
207 microblog_data['atom_id'] = unicode(id_elt) 207 microblog_data['atom_id'] = unicode(id_elt)
208 208
209 # title/content(s) 209 # title/content(s)
210 try: 210
211 title_elt = entry_elt.elements(NS_ATOM, 'title').next() 211 # FIXME: ATOM and XEP-0277 only allow 1 <title/> element
212 except StopIteration: 212 # but in the wild we have some blogs with several ones
213 # so we don't respect the standard for now (it doesn't break
214 # anything anyway), and we'll find a better option later
215 # try:
216 # title_elt = entry_elt.elements(NS_ATOM, 'title').next()
217 # except StopIteration:
218 # msg = u'No atom title found in the pubsub item {}'.format(id_)
219 # raise failure.Failure(exceptions.DataError(msg))
220 title_elts = list(entry_elt.elements(NS_ATOM, 'title'))
221 if not title_elts:
213 msg = u'No atom title found in the pubsub item {}'.format(id_) 222 msg = u'No atom title found in the pubsub item {}'.format(id_)
214 raise failure.Failure(exceptions.DataError(msg)) 223 raise failure.Failure(exceptions.DataError(msg))
215 224 for title_elt in title_elts:
216 yield parseElement(title_elt) 225 yield parseElement(title_elt)
217 226
227 # FIXME: as for <title/>, Atom only authorise at most 1 content
228 # but XEP-0277 allows several ones. So for no we handle as
229 # if more than one can be present
218 for content_elt in entry_elt.elements(NS_ATOM, 'content'): 230 for content_elt in entry_elt.elements(NS_ATOM, 'content'):
219 yield parseElement(content_elt) 231 yield parseElement(content_elt)
220 232
221 # we check that text content is present 233 # we check that text content is present
222 for key in ('title', 'content'): 234 for key in ('title', 'content'):