Mercurial > libervia-backend
comparison src/plugins/plugin_misc_text_syntaxes.py @ 2106:5874da3811b7
plugin text syntaxes: log error on cleanXHTML failure
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 01 Jan 2017 16:38:32 +0100 |
parents | 2daf7b4c6756 |
children | 33c8c4973743 |
comparison
equal
deleted
inserted
replaced
2105:c96fe007ca41 | 2106:5874da3811b7 |
---|---|
145 | 145 |
146 @param profile: %(doc_profile)s | 146 @param profile: %(doc_profile)s |
147 @return: profile selected syntax | 147 @return: profile selected syntax |
148 """ | 148 """ |
149 return self.host.memory.getParamA(NAME, CATEGORY , profile_key=profile) | 149 return self.host.memory.getParamA(NAME, CATEGORY , profile_key=profile) |
150 | |
151 def _logError(self, failure, action=u"converting syntax"): | |
152 log.error(u"Error while {action}: {failure}".format(action=action, failure=failure)) | |
153 return failure | |
150 | 154 |
151 def cleanXHTML(self, xhtml): | 155 def cleanXHTML(self, xhtml): |
152 """ Clean XHTML text by removing potentially dangerous/malicious parts | 156 """ Clean XHTML text by removing potentially dangerous/malicious parts |
153 @param xhtml: raw xhtml text to clean (or lxml's HtmlElement) | 157 @param xhtml: raw xhtml text to clean (or lxml's HtmlElement) |
154 """ | 158 """ |
189 xhtml_elt = cleaner.clean_html(xhtml_elt) | 193 xhtml_elt = cleaner.clean_html(xhtml_elt) |
190 for elt in xhtml_elt.xpath("//*[@style]"): | 194 for elt in xhtml_elt.xpath("//*[@style]"): |
191 elt.set("style", clean_style(elt.get('style'))) | 195 elt.set("style", clean_style(elt.get('style'))) |
192 return html.tostring(xhtml_elt, encoding=unicode, method='xml') | 196 return html.tostring(xhtml_elt, encoding=unicode, method='xml') |
193 | 197 |
194 return deferToThread(blocking_cleaning, xhtml) | 198 d = deferToThread(blocking_cleaning, xhtml) |
199 d.addErrback(self._logError, action=u"cleaning syntax") | |
200 return d | |
195 | 201 |
196 def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True, profile=None): | 202 def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True, profile=None): |
197 """Convert a text between two syntaxes | 203 """Convert a text between two syntaxes |
198 | 204 |
199 @param text: text to convert | 205 @param text: text to convert |