Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0277.py @ 2780:85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Jan 2019 11:39:02 +0100 |
parents | 003b8b4b56a7 |
children | 0b7ce5daee9b |
comparison
equal
deleted
inserted
replaced
2779:4cfa2085aebf | 2780:85d3240a400f |
---|---|
53 PLUGIN_INFO = { | 53 PLUGIN_INFO = { |
54 C.PI_NAME: "Microblogging over XMPP Plugin", | 54 C.PI_NAME: "Microblogging over XMPP Plugin", |
55 C.PI_IMPORT_NAME: "XEP-0277", | 55 C.PI_IMPORT_NAME: "XEP-0277", |
56 C.PI_TYPE: "XEP", | 56 C.PI_TYPE: "XEP", |
57 C.PI_PROTOCOLS: ["XEP-0277"], | 57 C.PI_PROTOCOLS: ["XEP-0277"], |
58 C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0060", "TEXT-SYNTAXES"], | 58 C.PI_DEPENDENCIES: ["XEP-0163", "XEP-0060", "TEXT_SYNTAXES"], |
59 C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP"], | 59 C.PI_RECOMMENDATIONS: ["XEP-0059", "EXTRA-PEP"], |
60 C.PI_MAIN: "XEP_0277", | 60 C.PI_MAIN: "XEP_0277", |
61 C.PI_HANDLER: "yes", | 61 C.PI_HANDLER: "yes", |
62 C.PI_DESCRIPTION: _("""Implementation of microblogging Protocol"""), | 62 C.PI_DESCRIPTION: _("""Implementation of microblogging Protocol"""), |
63 } | 63 } |
247 _("Content of type XHTML must declare its namespace!") | 247 _("Content of type XHTML must declare its namespace!") |
248 ) | 248 ) |
249 ) | 249 ) |
250 key = check_conflict(u"{}_xhtml".format(elem.name)) | 250 key = check_conflict(u"{}_xhtml".format(elem.name)) |
251 data = data_elt.toXml() | 251 data = data_elt.toXml() |
252 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].cleanXHTML( | 252 microblog_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].cleanXHTML( |
253 data | 253 data |
254 ) | 254 ) |
255 else: | 255 else: |
256 key = check_conflict(elem.name) | 256 key = check_conflict(elem.name) |
257 microblog_data[key] = unicode(elem) | 257 microblog_data[key] = unicode(elem) |
320 u"item {id_} provide a {key}_xhtml data but not a text one".format( | 320 u"item {id_} provide a {key}_xhtml data but not a text one".format( |
321 id_=id_, key=key | 321 id_=id_, key=key |
322 ) | 322 ) |
323 ) | 323 ) |
324 # ... and do the conversion if it's not | 324 # ... and do the conversion if it's not |
325 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].convert( | 325 microblog_data[key] = yield self.host.plugins["TEXT_SYNTAXES"].convert( |
326 microblog_data[u"{}_xhtml".format(key)], | 326 microblog_data[u"{}_xhtml".format(key)], |
327 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_XHTML, | 327 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_XHTML, |
328 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_TEXT, | 328 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
329 False, | 329 False, |
330 ) | 330 ) |
331 | 331 |
332 if "content" not in microblog_data: | 332 if "content" not in microblog_data: |
333 # use the atom title data as the microblog body content | 333 # use the atom title data as the microblog body content |
470 ## language ## | 470 ## language ## |
471 if u"language" in data: | 471 if u"language" in data: |
472 entry_elt[(C.NS_XML, u"lang")] = data[u"language"].strip() | 472 entry_elt[(C.NS_XML, u"lang")] = data[u"language"].strip() |
473 | 473 |
474 ## content and title ## | 474 ## content and title ## |
475 synt = self.host.plugins["TEXT-SYNTAXES"] | 475 synt = self.host.plugins["TEXT_SYNTAXES"] |
476 | 476 |
477 for elem_name in ("title", "content"): | 477 for elem_name in ("title", "content"): |
478 for type_ in ["", "_rich", "_xhtml"]: | 478 for type_ in ["", "_rich", "_xhtml"]: |
479 attr = "{}{}".format(elem_name, type_) | 479 attr = "{}{}".format(elem_name, type_) |
480 if attr in data: | 480 if attr in data: |
512 if elem_name not in data: | 512 if elem_name not in data: |
513 # there is raw text content, which is mandatory | 513 # there is raw text content, which is mandatory |
514 # so we create one from xhtml content | 514 # so we create one from xhtml content |
515 elem_txt = entry_elt.addElement(elem_name) | 515 elem_txt = entry_elt.addElement(elem_name) |
516 text_content = yield self.host.plugins[ | 516 text_content = yield self.host.plugins[ |
517 "TEXT-SYNTAXES" | 517 "TEXT_SYNTAXES" |
518 ].convert( | 518 ].convert( |
519 xml_content, | 519 xml_content, |
520 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_XHTML, | 520 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_XHTML, |
521 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_TEXT, | 521 self.host.plugins["TEXT_SYNTAXES"].SYNTAX_TEXT, |
522 False, | 522 False, |
523 ) | 523 ) |
524 elem_txt.addContent(text_content) | 524 elem_txt.addContent(text_content) |
525 elem_txt["type"] = "text" | 525 elem_txt["type"] = "text" |
526 | 526 |