Mercurial > libervia-backend
changeset 3620:f568f304c982
plugin text syntaxes: remove side effect on init:
When text syntaxes was initialised, `syntaxes` dict was filled, but it was a class
attribute. As a result, re-initialising it (which may happen for tests, and maybe in the
future dynamically), was not starting with an empty dict, but with an already-filled one,
resulting in conflicts.
This patch fixes it by moving `syntaxes` to an instance attribute.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Aug 2021 21:52:17 +0200 |
parents | 32181a45d54b |
children | 9e1a993ad1bf |
files | sat/plugins/plugin_misc_text_syntaxes.py |
diffstat | 1 files changed, 27 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_text_syntaxes.py Mon Aug 02 21:52:17 2021 +0200 +++ b/sat/plugins/plugin_misc_text_syntaxes.py Mon Aug 02 21:52:17 2021 +0200 @@ -156,33 +156,35 @@ SYNTAX_XHTML = _SYNTAX_XHTML SYNTAX_MARKDOWN = "markdown" SYNTAX_TEXT = "text" - syntaxes = {} # default_syntax must be lower case default_syntax = SYNTAX_XHTML - params = """ - <params> - <individual> - <category name="%(category_name)s" label="%(category_label)s"> - <param name="%(name)s" label="%(label)s" type="list" security="0"> - %(options)s - </param> - </category> - </individual> - </params> - """ - - params_data = { - "category_name": CATEGORY, - "category_label": _(CATEGORY), - "name": NAME, - "label": _(NAME), - "syntaxes": syntaxes, - } def __init__(self, host): log.info(_("Text syntaxes plugin initialization")) self.host = host + self.syntaxes = {} + + self.params = """ + <params> + <individual> + <category name="%(category_name)s" label="%(category_label)s"> + <param name="%(name)s" label="%(label)s" type="list" security="0"> + %(options)s + </param> + </category> + </individual> + </params> + """ + + self.params_data = { + "category_name": CATEGORY, + "category_label": _(CATEGORY), + "name": NAME, + "label": _(NAME), + "syntaxes": self.syntaxes, + } + self.addSyntax( self.SYNTAX_XHTML, lambda xhtml: defer.succeed(xhtml), @@ -253,7 +255,7 @@ xml_tools.cleanXHTML = self.cleanXHTML def _updateParamOptions(self): - data_synt = TextSyntaxes.syntaxes + data_synt = self.syntaxes default_synt = TextSyntaxes.default_syntax syntaxes = [] @@ -269,8 +271,8 @@ selected = 'selected="true"' if syntax == default_synt else "" options.append('<option value="%s" %s/>' % (syntax, selected)) - TextSyntaxes.params_data["options"] = "\n".join(options) - self.host.memory.updateParams(TextSyntaxes.params % TextSyntaxes.params_data) + self.params_data["options"] = "\n".join(options) + self.host.memory.updateParams(self.params % self.params_data) def getCurrentSyntax(self, profile): """ Return the selected syntax for the given profile @@ -372,7 +374,7 @@ syntax_to = self.getCurrentSyntax(profile) else: syntax_to = syntax_to.lower().strip() - syntaxes = TextSyntaxes.syntaxes + syntaxes = self.syntaxes if syntax_from not in syntaxes: raise exceptions.NotFound(syntax_from) if syntax_to not in syntaxes: @@ -417,7 +419,7 @@ ) ) - syntaxes = TextSyntaxes.syntaxes + syntaxes = self.syntaxes key = name.lower().strip() if key in syntaxes: raise exceptions.ConflictError(