Mercurial > libervia-backend
comparison src/plugins/plugin_misc_text_syntaxes.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | 75f3b3b430ff |
children | 7b4600ad73ad |
comparison
equal
deleted
inserted
replaced
992:f51a1895275c | 993:301b342c697a |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _, D_ | 20 from sat.core.i18n import _, D_ |
21 from logging import debug, info, error, warning | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | |
22 | 23 |
23 from wokkel import disco, pubsub | 24 from wokkel import disco, pubsub |
24 from twisted.internet import defer | 25 from twisted.internet import defer |
25 from twisted.internet.threads import deferToThread | 26 from twisted.internet.threads import deferToThread |
26 from sat.core import exceptions | 27 from sat.core import exceptions |
92 'label': _(NAME), | 93 'label': _(NAME), |
93 'syntaxes': {}, | 94 'syntaxes': {}, |
94 } | 95 } |
95 | 96 |
96 def __init__(self, host): | 97 def __init__(self, host): |
97 info(_("Text syntaxes plugin initialization")) | 98 log.info(_("Text syntaxes plugin initialization")) |
98 self.host = host | 99 self.host = host |
99 self.syntaxes = {} | 100 self.syntaxes = {} |
100 self.addSyntax(self.SYNTAX_XHTML, lambda xhtml: defer.succeed(xhtml), lambda xhtml: defer.succeed(xhtml), | 101 self.addSyntax(self.SYNTAX_XHTML, lambda xhtml: defer.succeed(xhtml), lambda xhtml: defer.succeed(xhtml), |
101 TextSyntaxes.OPT_NO_THREAD) | 102 TextSyntaxes.OPT_NO_THREAD) |
102 self.addSyntax(self.SYNTAX_TEXT, lambda text: escape(text), lambda xhtml: self._removeMarkups(xhtml), [TextSyntaxes.OPT_HIDDEN]) | 103 self.addSyntax(self.SYNTAX_TEXT, lambda text: escape(text), lambda xhtml: self._removeMarkups(xhtml), [TextSyntaxes.OPT_HIDDEN]) |
107 h = html2text.HTML2Text(baseurl=baseurl) | 108 h = html2text.HTML2Text(baseurl=baseurl) |
108 h.body_width = 0 # do not truncate the lines, it breaks the long URLs | 109 h.body_width = 0 # do not truncate the lines, it breaks the long URLs |
109 return h.handle(html) | 110 return h.handle(html) |
110 self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, _html2text, [TextSyntaxes.OPT_DEFAULT]) | 111 self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, _html2text, [TextSyntaxes.OPT_DEFAULT]) |
111 except ImportError: | 112 except ImportError: |
112 warning("markdown or html2text not found, can't use Markdown syntax") | 113 log.warning("markdown or html2text not found, can't use Markdown syntax") |
113 host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s', | 114 host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s', |
114 async=True, method=self.convert) | 115 async=True, method=self.convert) |
115 | 116 |
116 def _updateParamOptions(self): | 117 def _updateParamOptions(self): |
117 data_synt = TextSyntaxes.params_data['syntaxes'] | 118 data_synt = TextSyntaxes.params_data['syntaxes'] |
171 if isinstance(xhtml, basestring): | 172 if isinstance(xhtml, basestring): |
172 xhtml_elt = html.fromstring(xhtml) | 173 xhtml_elt = html.fromstring(xhtml) |
173 elif isinstance(xhtml, html.HtmlElement): | 174 elif isinstance(xhtml, html.HtmlElement): |
174 xhtml_elt = xhtml | 175 xhtml_elt = xhtml |
175 else: | 176 else: |
176 error("Only strings and HtmlElements can be cleaned") | 177 log.error("Only strings and HtmlElements can be cleaned") |
177 raise exceptions.DataError | 178 raise exceptions.DataError |
178 cleaner = clean.Cleaner(style=False, | 179 cleaner = clean.Cleaner(style=False, |
179 add_nofollow=False, | 180 add_nofollow=False, |
180 safe_attrs=SAFE_ATTRS) | 181 safe_attrs=SAFE_ATTRS) |
181 xhtml_elt = cleaner.clean_html(xhtml_elt) | 182 xhtml_elt = cleaner.clean_html(xhtml_elt) |