From 509047fcdaa8afb11074c355c7ab7c4f6d6fac7f Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 24 Aug 2018 15:57:43 +0300 Subject: Make sure subclasses can't alter the initial settings of token_class --- wikitrans/wikimarkup.py | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'wikitrans') diff --git a/wikitrans/wikimarkup.py b/wikitrans/wikimarkup.py index d199335..0ce0e15 100644 --- a/wikitrans/wikimarkup.py +++ b/wikitrans/wikimarkup.py @@ -186,29 +186,8 @@ class WikiMarkupParser(object): inline_delims = [ "''", "'''", "[", "]", "[[", "]]", "{{", "}}", "|" ] - token_class = { - 'NIL': WikiNode, - 'NL': WikiNode, - 'OTAG': WikiTagNode, - 'CTAG': WikiTagNode, - 'TAG': WikiTagNode, - 'DELIM': WikiDelimNode, - 'TEXT': WikiTextNode, - 'PRE': WikiContentNode, - 'PARA': WikiSeqNode, - 'BAR': WikiNode, - 'SEQ': WikiSeqNode, - 'IND': WikiIndNode, - 'REF': WikiRefNode, - 'TMPL': WikiSeqNode, - 'IT': WikiSeqNode, - 'BOLD': WikiSeqNode, - 'ELT': WikiEltNode, - 'ENV': WikiEnvNode, - 'LINK': WikiSeqNode, - 'HDR': WikiHdrNode - } - + token_class = {} + def _new_node(self, **kwarg): return self.token_class[kwarg['type']](self, **kwarg) @@ -992,6 +971,29 @@ class WikiMarkup(WikiMarkupParser): Base URL for media files. Default is 'http://www.mediawiki.org/xml/export-0.3' """ + self.token_class = { + 'NIL': WikiNode, + 'NL': WikiNode, + 'OTAG': WikiTagNode, + 'CTAG': WikiTagNode, + 'TAG': WikiTagNode, + 'DELIM': WikiDelimNode, + 'TEXT': WikiTextNode, + 'PRE': WikiContentNode, + 'PARA': WikiSeqNode, + 'BAR': WikiNode, + 'SEQ': WikiSeqNode, + 'IND': WikiIndNode, + 'REF': WikiRefNode, + 'TMPL': WikiSeqNode, + 'IT': WikiSeqNode, + 'BOLD': WikiSeqNode, + 'ELT': WikiEltNode, + 'ENV': WikiEnvNode, + 'LINK': WikiSeqNode, + 'HDR': WikiHdrNode + } + for kw in keywords: if kw == 'file': self.file = keywords[kw] -- cgit v1.2.1