comparison src/plugins/plugin_xep_0277.py @ 1822:aaf034bc6f7a

plugin XEP-0277: moved NS_XHTML namespace to constants + adapted parsing to new behaviour of ElementParser
author Goffi <goffi@goffi.org>
date Fri, 22 Jan 2016 20:24:17 +0100
parents d6062afdd54f
children 1424cc6f8e98
comparison
equal deleted inserted replaced
1821:d6062afdd54f 1822:aaf034bc6f7a
41 import urlparse 41 import urlparse
42 import urllib 42 import urllib
43 43
44 NS_MICROBLOG = 'urn:xmpp:microblog:0' 44 NS_MICROBLOG = 'urn:xmpp:microblog:0'
45 NS_ATOM = 'http://www.w3.org/2005/Atom' 45 NS_ATOM = 'http://www.w3.org/2005/Atom'
46 NS_XHTML = 'http://www.w3.org/1999/xhtml'
47 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") 46 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event")
48 NS_COMMENT_PREFIX = '{}:comments/'.format(NS_MICROBLOG) 47 NS_COMMENT_PREFIX = '{}:comments/'.format(NS_MICROBLOG)
49 48
50 49
51 PLUGIN_INFO = { 50 PLUGIN_INFO = {
171 type_ = elem.getAttribute('type') 170 type_ = elem.getAttribute('type')
172 if type_ == 'xhtml': 171 if type_ == 'xhtml':
173 data_elt = elem.firstChildElement() 172 data_elt = elem.firstChildElement()
174 if data_elt is None: 173 if data_elt is None:
175 raise failure.Failure(exceptions.DataError(u"XHML content not wrapped in a <div/> element, this is not standard !")) 174 raise failure.Failure(exceptions.DataError(u"XHML content not wrapped in a <div/> element, this is not standard !"))
176 if data_elt.uri != NS_XHTML: 175 if data_elt.uri != C.NS_XHTML:
177 raise failure.Failure(exceptions.DataError(_('Content of type XHTML must declare its namespace!'))) 176 raise failure.Failure(exceptions.DataError(_('Content of type XHTML must declare its namespace!')))
178 key = check_conflict(u'{}_xhtml'.format(elem.name)) 177 key = check_conflict(u'{}_xhtml'.format(elem.name))
179 data = data_elt.toXml() 178 data = data_elt.toXml()
180 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].cleanXHTML(data) 179 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].cleanXHTML(data)
181 else: 180 else:
365 if '{}_xhtml'.format(elem_name) in data: 364 if '{}_xhtml'.format(elem_name) in data:
366 raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time"))) 365 raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time")))
367 else: 366 else:
368 xml_content = data[attr] 367 xml_content = data[attr]
369 368
370 div_elt = xml_tools.ElementParser()(xml_content, namespace=NS_XHTML) 369 div_elt = xml_tools.ElementParser()(xml_content, namespace=C.NS_XHTML)
371 if div_elt.name != 'div' or div_elt.uri != NS_XHTML or div_elt.attributes: 370 if div_elt.name != 'div' or div_elt.uri != C.NS_XHTML or div_elt.attributes:
372 # we need a wrapping <div/> at the top with XHTML namespace 371 # we need a wrapping <div/> at the top with XHTML namespace
373 wrap_div_elt = domish.Element((NS_XHTML, 'div')) 372 wrap_div_elt = domish.Element((C.NS_XHTML, 'div'))
374 wrap_div_elt.addChild(div_elt) 373 wrap_div_elt.addChild(div_elt)
375 div_elt = wrap_div_elt 374 div_elt = wrap_div_elt
376 elem.addChild(div_elt) 375 elem.addChild(div_elt)
377 elem['type'] = 'xhtml' 376 elem['type'] = 'xhtml'
378 if elem_name not in data: 377 if elem_name not in data: