diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-09-01 22:10:01 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-09-01 22:24:02 +0300 |
commit | 5320bea15e388200e613e6a2bdac3c1449030986 (patch) | |
tree | 7d8571c63f72cc690cea8323e43be09c18527c45 /wikitrans | |
parent | 0aae19835045bac0be0f22ecd0e84527cdaee21c (diff) | |
download | wikitrans-5320bea15e388200e613e6a2bdac3c1449030986.tar.gz wikitrans-5320bea15e388200e613e6a2bdac3c1449030986.tar.bz2 |
Bugfixes
* README.rst: Describe new options.
* bin/wikitrans: Change handling of the --debug option.
* wikitrans/wikimarkup.py (WikiMarkupParser): New attribute - strict.
(parse_para): Don't throw UnexpectedTokenError if self.strict is False,
instead ignore invalid token.
(WikiMarkup): Fix Python 3 compatibility
* wikitrans/wikitoken.py: Fix Python 3 compatibility
Diffstat (limited to 'wikitrans')
-rw-r--r-- | wikitrans/wikimarkup.py | 35 | ||||
-rw-r--r-- | wikitrans/wikitoken.py | 2 |
2 files changed, 31 insertions, 6 deletions
diff --git a/wikitrans/wikimarkup.py b/wikitrans/wikimarkup.py index 19f69e6..1e2429f 100644 --- a/wikitrans/wikimarkup.py +++ b/wikitrans/wikimarkup.py @@ -147,2 +147,9 @@ class WikiMarkupParser(object): + Input: + debug_level -- debug verbosity level (0 - no debug info, 100 - excessively + copious debug messages). Default is 0. + strict -- if True, parser will throw exception upon encountering + invalid markup tag (mostly for future use) + + Output: tree -- constructed parse tree (a subclass of WikiNode) @@ -177,2 +184,3 @@ class WikiMarkupParser(object): debug_level = 0 + strict = False @@ -189,3 +197,3 @@ class WikiMarkupParser(object): token_class = {} - + def _new_node(self, **kwarg): @@ -376,3 +384,3 @@ class WikiMarkupParser(object): for i in stack: - # FIXME + # FIXME: How to convert node to TEXT? self.toklist[i] = self._new_node(type='TEXT', @@ -494,3 +502,6 @@ class WikiMarkupParser(object): else: - raise UnexpectedTokenError(tok) + if self.strict: + raise UnexpectedTokenError(tok) + # FIXME: Another possible variant of handling this case is to + # convert tok to TEXT node and append it to acc['seq'] tok = self.getkn() @@ -978,2 +989,9 @@ class WikiMarkup(WikiMarkupParser): 'http://www.mediawiki.org/xml/export-0.3' + + debug_level=INT + debug verbosity level (0 - no debug info, 100 - excessively + copious debug messages). Default is 0. + strict=BOOL + Strict parsing mode. Throw exceptions on syntax errors. Default + is False. """ @@ -1001,3 +1019,3 @@ class WikiMarkup(WikiMarkupParser): } - + for kw in keywords: @@ -1008,3 +1026,6 @@ class WikiMarkup(WikiMarkupParser): elif kw == 'text': - self.text = keywords[kw].split("\n") + if sys.version_info[0] > 2: + self.text = keywords[kw].decode('utf-8').split("\n") + else: + self.text = keywords[kw].split("\n") elif kw == 'lang': @@ -1017,2 +1038,6 @@ class WikiMarkup(WikiMarkupParser): self.media_base = keywords[kw] + elif kw == 'strict': + self.strict = keywords[kw] + elif kw == 'debug_level': + self.debug_level = keywords[kw] diff --git a/wikitrans/wikitoken.py b/wikitrans/wikitoken.py index deedea8..1f81092 100644 --- a/wikitrans/wikitoken.py +++ b/wikitrans/wikitoken.py @@ -313,3 +313,3 @@ class WikiEnvNode(WikiContentNode): 'level': self.level, - 'content': map(lambda x: x.json_encode(), self.content) + 'content': [x for x in map(lambda x: x.json_encode(), self.content)] } |