changeset 1803:14a97a5fe1c0

plugin text syntaxes: a non blocking syntax callback can now return a unicode directly instead of a Deferred
author Goffi <>
date Fri, 15 Jan 2016 17:13:59 +0100
parents fed95a6c56f8
children 33e73c70d78a
files src/plugins/
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/	Fri Jan 15 17:13:59 2016 +0100
+++ b/src/plugins/	Fri Jan 15 17:13:59 2016 +0100
@@ -189,13 +189,15 @@
         return deferToThread(blocking_cleaning, xhtml)
     def convert(self, text, syntax_from, syntax_to=_SYNTAX_XHTML, safe=True, profile=None):
-        """ Convert a text between two syntaxes
+        """Convert a text between two syntaxes
         @param text: text to convert
         @param syntax_from: source syntax (e.g. "markdown")
         @param syntax_to: dest syntax (e.g.: "XHTML")
         @param safe: clean resulting XHTML to avoid malicious code if True
         @param profile: needed only when syntax_from or syntax_to is set to _SYNTAX_CURRENT
-        @return: converted text """
+        @return(unicode): converted text
+        """
         if syntax_from == _SYNTAX_CURRENT:
             syntax_from = self.getCurrentSyntax(profile)
@@ -209,7 +211,7 @@
         d = None
         if TextSyntaxes.OPT_NO_THREAD in syntaxes[syntax_from]["flags"]:
-            d = syntaxes[syntax_from]["to"](text)
+            d = defer.maybeDeferred(syntaxes[syntax_from]["to"], text)
             d = deferToThread(syntaxes[syntax_from]["to"], text)
@@ -228,20 +230,20 @@
         return d
     def addSyntax(self, name, to_xhtml_cb, from_xhtml_cb, flags = None):
-        """ Add a new syntax to the manager
+        """Add a new syntax to the manager
         @param name: unique name of the syntax
         @param to_xhtml_cb: callback to convert from syntax to XHTML
         @param from_xhtml_cb: callback to convert from XHTML to syntax
         @param flags: set of optional flags, can be:
             TextSyntaxes.OPT_DEFAULT: use as the default syntax (replace former one)
             TextSyntaxes.OPT_HIDDEN: do not show in parameters
-            TextSyntaxes.OPT_NO_THREAD: do not defer to thread when converting (the callback must then return a deferred)
+            TextSyntaxes.OPT_NO_THREAD: do not defer to thread when converting (the callback may then return a deferred)
         name = unicode(name)
         flags = flags or []
         if TextSyntaxes.OPT_HIDDEN in flags and TextSyntaxes.OPT_DEFAULT in flags:
-            raise ValueError("%s and %s are mutually exclusive" % (TextSyntaxes.OPT_HIDDEN, TextSyntaxes.OPT_DEFAULT))
+            raise ValueError(u"{} and {} are mutually exclusive".format(TextSyntaxes.OPT_HIDDEN, TextSyntaxes.OPT_DEFAULT))
         syntaxes = TextSyntaxes.params_data['syntaxes']
         syntaxes[name] = {"to": to_xhtml_cb, "from": from_xhtml_cb, "flags": flags}