summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-08-18 14:43:36 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-08-18 14:43:36 (GMT)
commit8c0de7a515aa9d6db7b3ce4110a4e29261851abb (patch) (side-by-side diff)
tree228c2bb1be5a907b373158c6c94cd8d51f23c419
parent0c03a5a7b40b598b88f22f46b9e9086af6c59877 (diff)
downloadwikitrans-8c0de7a515aa9d6db7b3ce4110a4e29261851abb.tar.gz
wikitrans-8c0de7a515aa9d6db7b3ce4110a4e29261851abb.tar.bz2
Minor stylistic fixes.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--README.rst6
-rwxr-xr-xbin/wikitrans3
-rw-r--r--wikitrans/wiki2html.py53
-rw-r--r--wikitrans/wiki2texi.py82
-rw-r--r--wikitrans/wiki2text.py66
-rw-r--r--wikitrans/wikidump.py20
-rw-r--r--wikitrans/wikimarkup.py46
-rw-r--r--wikitrans/wikitoken.py72
8 files changed, 205 insertions, 143 deletions
diff --git a/README.rst b/README.rst
index d189c98..7c53e3c 100644
--- a/README.rst
+++ b/README.rst
@@ -126,3 +126,3 @@ The ``wikitrans`` utility
=========================
-This command line utility converts the supplied text to a selected
+This command line utility converts the supplied text to selected
output format. The usage syntax is::
@@ -162,3 +162,3 @@ Options are:
``-l LANG``, ``--lang=LANG``
- Set input document language
+ Set input document language.
``-o KW=VAL``, ``--option=KW=VAL``
@@ -166,3 +166,3 @@ Options are:
``-d DEBUG``, ``--debug=DEBUG``
- Set debug level (0..100)
+ Set debug level (0..100).
``-D``, ``--dump``
diff --git a/bin/wikitrans b/bin/wikitrans
index caaa885..87de020 100755
--- a/bin/wikitrans
+++ b/bin/wikitrans
@@ -61,3 +61,4 @@ handlers = {
'texi': {
- 'default': TexiWikiMarkup
+ 'default': TexiWikiMarkup,
+ 'wiktionary': TextWikiMarkup
}
diff --git a/wikitrans/wiki2html.py b/wikitrans/wiki2html.py
index fc6b142..0696dce 100644
--- a/wikitrans/wiki2html.py
+++ b/wikitrans/wiki2html.py
@@ -3,3 +3,3 @@
# Copyright (C) 2008-2018 Sergey Poznyakoff
-#
+#
# This program is free software; you can redistribute it and/or modify
@@ -8,3 +8,3 @@
# any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
@@ -13,3 +13,3 @@
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
@@ -42,5 +42,6 @@ except ImportError:
from cgi import escape as html_escape
-
+
__all__ = [ "HtmlWikiMarkup", "HtmlWiktionaryMarkup" ]
+
class HtmlSeqNode(WikiSeqNode):
@@ -51,3 +52,4 @@ class HtmlSeqNode(WikiSeqNode):
return s
-
+
+
class HtmlLinkNode(HtmlSeqNode):
@@ -72,4 +74,4 @@ class HtmlLinkNode(HtmlSeqNode):
return text
-
- (qual,sep,tgt) = arg.partition(':')
+
+ (qual, sep, tgt) = arg.partition(':')
if tgt != '':
@@ -94,2 +96,3 @@ class HtmlLinkNode(HtmlSeqNode):
+
class HtmlRefNode(WikiRefNode):
@@ -103,2 +106,3 @@ class HtmlRefNode(WikiRefNode):
+
class HtmlFontNode(HtmlSeqNode):
@@ -113,5 +117,6 @@ class HtmlFontNode(HtmlSeqNode):
+
class HtmlTextNode(HtmlSeqNode):
def format(self):
- if isinstance(self.content,list):
+ if isinstance(self.content, list):
s = ''.join(self.content)
@@ -121,2 +126,3 @@ class HtmlTextNode(HtmlSeqNode):
+
class HtmlHdrNode(WikiHdrNode):
@@ -128,2 +134,3 @@ class HtmlHdrNode(WikiHdrNode):
+
class HtmlBarNode(WikiNode):
@@ -132,2 +139,3 @@ class HtmlBarNode(WikiNode):
+
class HtmlEnvNode(WikiEnvNode):
@@ -148,3 +156,4 @@ class HtmlEnvNode(WikiEnvNode):
return string
-
+
+
class HtmlTagNode(WikiTagNode):
@@ -158,3 +167,3 @@ class HtmlTagNode(WikiTagNode):
n = self.idx+1
- return '<sup id="cite_ref-%d" class="reference"><a name="cite_ref-%d" href=#cite_note-%d">%d</a></sup>' % (n,n,n,n)
+ return '<sup id="cite_ref-%d" class="reference"><a name="cite_ref-%d" href=#cite_note-%d">%d</a></sup>' % (n, n, n, n)
elif self.tag == 'references':
@@ -164,3 +173,3 @@ class HtmlTagNode(WikiTagNode):
for ref in self.parser.references:
- n += 1
+ n += 1
s += ('<li id="cite_note-%d">'
@@ -172,3 +181,3 @@ class HtmlTagNode(WikiTagNode):
+ '</span>'
- + '</li>\n') % (n,n)
+ + '</li>\n') % (n, n)
s += '</ol>\n</div>\n'
@@ -182,3 +191,4 @@ class HtmlTagNode(WikiTagNode):
return s + '</' + self.tag + '>'
-
+
+
class HtmlParaNode(HtmlSeqNode):
@@ -187,2 +197,3 @@ class HtmlParaNode(HtmlSeqNode):
+
class HtmlPreNode(HtmlSeqNode):
@@ -195,2 +206,3 @@ class HtmlPreNode(HtmlSeqNode):
+
class HtmlIndNode(WikiIndNode):
@@ -198,3 +210,3 @@ class HtmlIndNode(WikiIndNode):
return ("<dl><dd>" * self.level) + self.content.format() + "</dd></dl>" * self.level
-
+
@@ -225,5 +237,5 @@ class HtmlWikiMarkup(WikiMarkup):
The arguments have the same meaning as in the WikiMarkup constructor.
-
+
"""
-
+
super(HtmlWikiMarkup, self).__init__(*args, **kwargs)
@@ -251,4 +263,4 @@ class HtmlWikiMarkup(WikiMarkup):
return elt[2]
- return None
-
+ return None
+
envt = { "unnumbered": { "hdr": "ul",
@@ -258,3 +270,3 @@ class HtmlWikiMarkup(WikiMarkup):
"defn": { "hdr": "dl",
- "elt": ["dt","dd"] } }
+ "elt": ["dt","dd"] } }
@@ -293,3 +305,3 @@ class HtmlWikiMarkup(WikiMarkup):
return text
-
+
def __str__(self):
@@ -300,2 +312,3 @@ class HtmlWikiMarkup(WikiMarkup):
+
class HtmlWiktionaryMarkup(HtmlWikiMarkup):
diff --git a/wikitrans/wiki2texi.py b/wikitrans/wiki2texi.py
index 55dffe2..936a133 100644
--- a/wikitrans/wiki2texi.py
+++ b/wikitrans/wiki2texi.py
@@ -3,3 +3,3 @@
# Copyright (C) 2015-2018 Sergey Poznyakoff
-#
+#
# This program is free software; you can redistribute it and/or modify
@@ -8,3 +8,3 @@
# any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
@@ -13,3 +13,3 @@
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
@@ -32,12 +32,13 @@ import urllib
+
class Acc(list):
- def prepend(self,x):
- self.insert(0,x)
-
+ def prepend(self, x):
+ self.insert(0, x)
+
def is_empty(self):
return len(self) == 0
-
+
def clear(self):
self = []
-
+
def tail(self, n = 1):
@@ -67,3 +68,3 @@ class Acc(list):
n -= l
-
+
def trimnl(self):
@@ -71,3 +72,3 @@ class Acc(list):
self.trim(1)
-
+
def trimpara(self):
@@ -75,9 +76,9 @@ class Acc(list):
self.trim(2)
-
+
def endswith(self, x):
return self.tail(len(x)) == x
-
+
def in_new_para(self):
return self.is_empty() or self.endswith('\n\n')
-
+
def __str__(self):
@@ -85,2 +86,3 @@ class Acc(list):
+
class TexiTextNode(WikiTextNode):
@@ -88,3 +90,3 @@ class TexiTextNode(WikiTextNode):
parser = self.parser
- if isinstance(self.content,list):
+ if isinstance(self.content, list):
for s in self.content:
@@ -94,2 +96,3 @@ class TexiTextNode(WikiTextNode):
+
class TexiTagNode(WikiTagNode):
@@ -127,5 +130,6 @@ class TexiTagNode(WikiTagNode):
parser._print('</' + self.tag + '>')
-
+
+
class TexiParaNode(WikiSeqNode):
- def format(self):
+ def format(self):
parser = self.parser
@@ -137,3 +141,4 @@ class TexiParaNode(WikiSeqNode):
parser._print('\n', nl=True)
-
+
+
class TexiPreNode(WikiSeqNode):
@@ -148,2 +153,3 @@ class TexiPreNode(WikiSeqNode):
+
class TexiFontNode(WikiSeqNode):
@@ -158,2 +164,3 @@ class TexiFontNode(WikiSeqNode):
+
class TexiHdrNode(WikiHdrNode):
@@ -176,2 +183,3 @@ class TexiHdrNode(WikiHdrNode):
+
class TexiBarNode(WikiNode):
@@ -180,2 +188,3 @@ class TexiBarNode(WikiNode):
+
class TexiIndNode(WikiIndNode):
@@ -187,2 +196,3 @@ class TexiIndNode(WikiIndNode):
+
class TexiEnvNode(WikiEnvNode):
@@ -218,3 +228,4 @@ class TexiEnvNode(WikiEnvNode):
parser._print('@end table\n', nl=True, escape=False)
-
+
+
class TexiLinkNode(WikiSeqNode):
@@ -244,3 +255,3 @@ class TexiLinkNode(WikiSeqNode):
- (qual,sep,tgt) = arg.partition(':')
+ (qual, sep, tgt) = arg.partition(':')
if text:
@@ -250,2 +261,3 @@ class TexiLinkNode(WikiSeqNode):
+
class TexiRefNode(WikiRefNode):
@@ -261,6 +273,7 @@ class TexiRefNode(WikiRefNode):
parser._print("@uref{%s}" % target, escape=False)
-
+
+
class TexiWikiMarkup(WikiMarkup):
"""Wiki markup to Texinfo translator class.
-
+
Usage:
@@ -272,5 +285,5 @@ class TexiWikiMarkup(WikiMarkup):
print(str(x))
-
+
"""
-
+
nested = 0
@@ -279,5 +292,5 @@ class TexiWikiMarkup(WikiMarkup):
'@top',
- '@chapter',
- '@section',
- '@subsection',
+ '@chapter',
+ '@section',
+ '@subsection',
'@subsubsection'
@@ -319,3 +332,3 @@ class TexiWikiMarkup(WikiMarkup):
the WikiMarkup class.
-
+
Additional arguments:
@@ -344,5 +357,5 @@ class TexiWikiMarkup(WikiMarkup):
"""
-
+
super(TexiWikiMarkup, self).__init__(*args, **keywords)
-
+
self.token_class['TEXT'] = TexiTextNode
@@ -359,3 +372,3 @@ class TexiWikiMarkup(WikiMarkup):
self.token_class['REF'] = TexiRefNode
-
+
if "sectioning_model" in keywords:
@@ -396,3 +409,3 @@ class TexiWikiMarkup(WikiMarkup):
return str(s)
-
+
def __str__(self):
@@ -403,8 +416 @@ class TexiWikiMarkup(WikiMarkup):
return self._end_print()
-
-
-
-
-
-
-
diff --git a/wikitrans/wiki2text.py b/wikitrans/wiki2text.py
index 88e7610..7585bff 100644
--- a/wikitrans/wiki2text.py
+++ b/wikitrans/wiki2text.py
@@ -3,3 +3,3 @@
# Copyright (C) 2008-2018 Sergey Poznyakoff
-#
+#
# This program is free software; you can redistribute it and/or modify
@@ -8,3 +8,3 @@
# any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
@@ -13,3 +13,3 @@
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
@@ -37,2 +37,3 @@ except ImportError:
+
class TextSeqNode(WikiSeqNode):
@@ -45,6 +46,7 @@ class TextSeqNode(WikiSeqNode):
return string
-
+
+
class TextTextNode(WikiTextNode):
def format(self):
- if isinstance(self.content,list):
+ if isinstance(self.content, list):
string = ""
@@ -61,2 +63,3 @@ class TextTextNode(WikiTextNode):
+
class TextPreNode(WikiSeqNode):
@@ -69,2 +72,3 @@ class TextPreNode(WikiSeqNode):
+
class TextParaNode(WikiSeqNode):
@@ -77,2 +81,3 @@ class TextParaNode(WikiSeqNode):
+
class TextItNode(WikiSeqNode):
@@ -85,3 +90,4 @@ class TextItNode(WikiSeqNode):
return "_" + string.lstrip(" ") + "_"
-
+
+
class TextBoldNode(WikiSeqNode):
@@ -97,2 +103,3 @@ class TextBoldNode(WikiSeqNode):
+
class TextLinkNode(WikiSeqNode):
@@ -112,3 +119,3 @@ class TextLinkNode(WikiSeqNode):
return ""
- (qual,sep,tgt) = arg.partition(':')
+ (qual, sep, tgt) = arg.partition(':')
if tgt != '':
@@ -140,3 +147,4 @@ class TextLinkNode(WikiSeqNode):
return text
-
+
+
class TextTmplNode(TextLinkNode):
@@ -144,3 +152,4 @@ class TextTmplNode(TextLinkNode):
return '[' + super(TextTmplNode, self).format() + ']'
-
+
+
class TextBarNode(WikiNode):
@@ -152,2 +161,3 @@ class TextBarNode(WikiNode):
+
class TextHdrNode(WikiHdrNode):
@@ -159,3 +169,4 @@ class TextHdrNode(WikiHdrNode):
+ "\n\n")
-
+
+
class TextRefNode(WikiRefNode):
@@ -168,2 +179,3 @@ class TextRefNode(WikiRefNode):
+
class TextEnvNode(WikiEnvNode):
@@ -190,8 +202,7 @@ class TextEnvNode(WikiEnvNode):
string += self.parser.indent(lev+3, x)
-
if not string.endswith("\n"):
string += "\n"
-
return string
+
class TextIndNode(WikiIndNode):
@@ -200,2 +211,3 @@ class TextIndNode(WikiIndNode):
+
class TextTagNode(WikiTagNode):
@@ -217,4 +229,4 @@ class TextTagNode(WikiTagNode):
s += '>' + self.content.format() + '</' + self.tag + '>'
- return s
-
+ return s
+
@@ -230,3 +242,3 @@ class TextWikiMarkup(WikiMarkup):
print(str(x))
-
+
"""
@@ -245,3 +257,3 @@ class TextWikiMarkup(WikiMarkup):
references = []
-
+
def __init__(self, *args, **keywords):
@@ -256,5 +268,5 @@ class TextWikiMarkup(WikiMarkup):
Class-specific arguments:
-
+
width=N
- Limit output width to N columns. Default is 78.
+ Limit output width to N columns. Default is 78.
show_urls=False
@@ -264,4 +276,4 @@ class TextWikiMarkup(WikiMarkup):
"""
-
- super(TextWikiMarkup,self).__init__(*args, **keywords)
+
+ super(TextWikiMarkup, self).__init__(*args, **keywords)
if 'width' in keywords:
@@ -285,3 +297,3 @@ class TextWikiMarkup(WikiMarkup):
self.token_class['TAG'] = TextTagNode
-
+
def wiki_ns_name(self, str):
@@ -294,3 +306,3 @@ class TextWikiMarkup(WikiMarkup):
return None
-
+
def mktgt(self, tgt, lang = None):
@@ -299,6 +311,6 @@ class TextWikiMarkup(WikiMarkup):
return self.html_base % { 'lang' : lang } + url_quote(tgt)
-
+
def indent(self, lev, text):
if text.find('\n') == -1:
- s = (" " * lev) + text
+ s = (" " * lev) + text
else:
@@ -311,3 +323,3 @@ class TextWikiMarkup(WikiMarkup):
return s
-
+
def fmtpara(self, input):
@@ -333,3 +345,3 @@ class TextWikiMarkup(WikiMarkup):
return output + linebuf
-
+
def __str__(self):
@@ -340,2 +352,3 @@ class TextWikiMarkup(WikiMarkup):
+
class TextWiktionaryMarkup(TextWikiMarkup):
@@ -347,2 +360 @@ class TextWiktionaryMarkup(TextWikiMarkup):
html_base='http://%(lang)s.wiktionary.org/wiki/'
-
diff --git a/wikitrans/wikidump.py b/wikitrans/wikidump.py
index d5f651c..bc71876 100644
--- a/wikitrans/wikidump.py
+++ b/wikitrans/wikidump.py
@@ -2,3 +2,3 @@
# Copyright (C) 2015-2018 Sergey Poznyakoff
-#
+#
# This program is free software; you can redistribute it and/or modify
@@ -7,3 +7,3 @@
# any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
@@ -12,3 +12,3 @@
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
@@ -30,2 +30,3 @@ from wikitrans.wikimarkup import WikiMarkup
+
class DumpReferences(object):
@@ -45,9 +46,10 @@ class DumpWikiMarkup(WikiMarkup):
x.parse()
- # Print a JSON dump of the parse tree
+ # Print a JSON dump of the parse tree
print(str(x))
-
+
"""
-
+
indent = None
references = DumpReferences()
+
def __init__(self, **kwarg):
@@ -66,3 +68,2 @@ class DumpWikiMarkup(WikiMarkup):
"""
-
n = kwarg.pop('indent', None)
@@ -70,3 +71,4 @@ class DumpWikiMarkup(WikiMarkup):
self.indent = int(n)
- super(DumpWikiMarkup,self).__init__(self, **kwarg)
+ super(DumpWikiMarkup, self).__init__(self, **kwarg)
+
def __str__(self):
@@ -75,3 +77,3 @@ class DumpWikiMarkup(WikiMarkup):
indent=self.indent,
- separators=(',',': '),
+ separators=(',', ': '),
sort_keys=True)
diff --git a/wikitrans/wikimarkup.py b/wikitrans/wikimarkup.py
index a3e17d5..d199335 100644
--- a/wikitrans/wikimarkup.py
+++ b/wikitrans/wikimarkup.py
@@ -40,2 +40,3 @@ __all__ = [ "WikiMarkupParser", "WikiMarkup",
+
class UnexpectedTokenError(Exception):
@@ -44,2 +45,3 @@ class UnexpectedTokenError(Exception):
+
class TagAttributeSyntaxError(Exception):
@@ -47,2 +49,3 @@ class TagAttributeSyntaxError(Exception):
self.value = value
+
def __str__(self):
@@ -50,2 +53,3 @@ class TagAttributeSyntaxError(Exception):
+
class TagAttributes(object):
@@ -61,3 +65,3 @@ class TagAttributes(object):
"""
-
+
attrstart = re.compile("^(?P<attr>[a-zA-Z0-9_-]+)(?P<eq>=\")?")
@@ -96,8 +100,12 @@ class TagAttributes(object):
raise TagAttributeSyntaxError(s)
+
def __len__(self):
return len(self.tab)
+
def __getitem__(self, key):
return self.tab[key]
+
def __contains__(self, key):
return key in self.tab
+
def __iter__(self):
@@ -105,10 +113,15 @@ class TagAttributes(object):
yield(key)
+
def has_key(self, key):
return self.__contains__(key)
+
def __setitem__(self, key, value):
self.tab[key] = value
+
def __delitem__(self, key):
del self.tab[key]
+
def __str__(self):
return self.printable
+
def __repr__(self):
@@ -116,2 +129,3 @@ class TagAttributes(object):
+
class WikiMarkupParser(object):
@@ -197,3 +211,3 @@ class WikiMarkupParser(object):
- def _new_node(self,**kwarg):
+ def _new_node(self, **kwarg):
return self.token_class[kwarg['type']](self, **kwarg)
@@ -268,3 +282,3 @@ class WikiMarkupParser(object):
else:
- yield(self._new_node(type='TEXT',content=m.group(0)))
+ yield(self._new_node(type='TEXT', content=m.group(0)))
continue
@@ -308,9 +322,8 @@ class WikiMarkupParser(object):
if line[pos:-1] != '':
- yield(self._new_node(type='TEXT',content=line[pos:-1]))
+ yield(self._new_node(type='TEXT', content=line[pos:-1]))
yield(self._new_node(type='NL'))
else:
- yield(self._new_node(type='TEXT',content=line[pos:]))
+ yield(self._new_node(type='TEXT', content=line[pos:]))
line = None
-
def input(self):
@@ -351,3 +364,3 @@ class WikiMarkupParser(object):
stack = []
- for i in range(0,len(self.toklist)):
+ for i in range(0, len(self.toklist)):
if (self.toklist[i].type == 'DELIM'
@@ -402,3 +415,3 @@ class WikiMarkupParser(object):
- def setkn(self,val):
+ def setkn(self, val):
"""Store token val at the current token index."""
@@ -473,3 +486,3 @@ class WikiMarkupParser(object):
if (isinstance(tok, WikiContentNode)
- and isinstance(tok.content,str)
+ and isinstance(tok.content, str)
and re.match("^[ \t]", tok.content)):
@@ -576,3 +589,3 @@ class WikiMarkupParser(object):
- def parse_fontmod(self,delim,what):
+ def parse_fontmod(self, delim, what):
"""Parse font modification directive (bold or italics).
@@ -629,3 +642,3 @@ class WikiMarkupParser(object):
seq = []
- (ref,sep,text) = tok.content.partition(' ')
+ (ref, sep, text) = tok.content.partition(' ')
if text:
@@ -737,3 +750,3 @@ class WikiMarkupParser(object):
lev = 0
- for i,tok in enumerate(self.toklist[self.tokind+1:]):
+ for i, tok in enumerate(self.toklist[self.tokind+1:]):
if tok.type == 'NIL':
@@ -768,3 +781,3 @@ class WikiMarkupParser(object):
s += '>'
- node = self._new_node(type='TEXT',content=s)
+ node = self._new_node(type='TEXT', content=s)
if tag.content:
@@ -788,3 +801,2 @@ class WikiMarkupParser(object):
list.append(tok)
-
self.clear_mark()
@@ -794,3 +806,4 @@ class WikiMarkupParser(object):
isblock = tag.isblock,
- content = self._new_node(type = 'SEQ', content = list))
+ content = self._new_node(type = 'SEQ',
+ content = list))
self.dprint(80, "LEAVE parse_tag = %s", ret)
@@ -802,3 +815,3 @@ class WikiMarkupParser(object):
lev = len(tok.content)
- self.dprint(80, "ENTER parse_env(%s,%s)",type,lev)
+ self.dprint(80, "ENTER parse_env(%s,%s)", type, lev)
list = []
@@ -833,3 +846,2 @@ class WikiMarkupParser(object):
tok = self.getkn()
-
ret = self._new_node(type='ENV',
diff --git a/wikitrans/wikitoken.py b/wikitrans/wikitoken.py
index 49c6c68..0678a75 100644
--- a/wikitrans/wikitoken.py
+++ b/wikitrans/wikitoken.py
@@ -43,9 +43,12 @@ import json
+
class WikiNodeEncoder(json.JSONEncoder):
"""Custom JSONEncoder subclass for serializing WikiNode and its subclasses."""
+
def default(self, obj):
- if isinstance(obj,WikiNode):
- return obj.jsonEncode()
+ if isinstance(obj, WikiNode):
+ return obj.json_encode()
return json.JSONEncoder.default(self, obj)
+
def jsonencoder(func):
@@ -56,4 +59,6 @@ def jsonencoder(func):
return json
+
return _mkencoder
+
class WikiNode(object):
@@ -73,3 +78,3 @@ class WikiNode(object):
for key in kwargs:
- if hasattr(self,key):
+ if hasattr(self, key):
self.__dict__[key] = kwargs[key]
@@ -82,3 +87,3 @@ class WikiNode(object):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
ret = {}
@@ -98,2 +103,3 @@ class WikiNode(object):
+
class WikiContentNode(WikiNode):
@@ -112,3 +118,3 @@ class WikiContentNode(WikiNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
ret = {}
@@ -117,6 +123,6 @@ class WikiContentNode(WikiNode):
ret['content'] = self.content
- elif isinstance(self.content,list):
- ret['content'] = map(lambda x: x.jsonEncode(), self.content)
- elif isinstance(self.content,WikiNode):
- ret['content'] = self.content.jsonEncode()
+ elif isinstance(self.content, list):
+ ret['content'] = map(lambda x: x.json_encode(), self.content)
+ elif isinstance(self.content, WikiNode):
+ ret['content'] = self.content.json_encode()
else:
@@ -127,2 +133,3 @@ class WikiContentNode(WikiNode):
+
class WikiSeqNode(WikiContentNode):
@@ -140,3 +147,3 @@ class WikiSeqNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
ret = {}
@@ -144,6 +151,6 @@ class WikiSeqNode(WikiContentNode):
ret['content'] = None
- elif isinstance(self.content,list):
- ret['content'] = map(lambda x: x.jsonEncode(), self.content)
- elif isinstance(self.content,WikiNode):
- ret['content'] = self.content.jsonEncode()
+ elif isinstance(self.content, list):
+ ret['content'] = map(lambda x: x.json_encode(), self.content)
+ elif isinstance(self.content, WikiNode):
+ ret['content'] = self.content.json_encode()
else:
@@ -167,3 +174,3 @@ class WikiTextNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
@@ -172,2 +179,3 @@ class WikiTextNode(WikiContentNode):
+
class WikiDelimNode(WikiContentNode):
@@ -187,2 +195,3 @@ class WikiDelimNode(WikiContentNode):
+
class WikiTagNode(WikiContentNode):
@@ -207,3 +216,5 @@ class WikiTagNode(WikiContentNode):
super(WikiTagNode, self).__init__(*args, **keywords)
- if self.type == 'TAG' and self.tag == 'ref' and hasattr(self.parser,'references'):
+ if (self.type == 'TAG'
+ and self.tag == 'ref'
+ and hasattr(self.parser, 'references')):
self.idx = len(self.parser.references)
@@ -212,3 +223,3 @@ class WikiTagNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
@@ -217,3 +228,3 @@ class WikiTagNode(WikiContentNode):
'args': self.args.tab if self.args else None,
- 'content': self.content.jsonEncode() if self.content else None,
+ 'content': self.content.json_encode() if self.content else None,
'idx': self.idx
@@ -221,2 +232,3 @@ class WikiTagNode(WikiContentNode):
+
class WikiRefNode(WikiContentNode):
@@ -235,8 +247,9 @@ class WikiRefNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
'ref': self.ref,
- 'content': self.content.jsonEncode()
+ 'content': self.content.json_encode()
}
+
class WikiHdrNode(WikiContentNode):
@@ -254,8 +267,9 @@ class WikiHdrNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
'level': self.level,
- 'content': self.content.jsonEncode()
+ 'content': self.content.json_encode()
}
+
class WikiEltNode(WikiContentNode):
@@ -273,8 +287,9 @@ class WikiEltNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
'subtype': self.subtype,
- 'content': self.content.jsonEncode()
+ 'content': self.content.json_encode()
}
+
class WikiEnvNode(WikiContentNode):
@@ -293,3 +308,3 @@ class WikiEnvNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
@@ -297,5 +312,6 @@ class WikiEnvNode(WikiContentNode):
'level': self.level,
- 'content': map(lambda x: x.jsonEncode(), self.content)
+ 'content': map(lambda x: x.json_encode(), self.content)
}
+
class WikiIndNode(WikiContentNode):
@@ -313,6 +329,6 @@ class WikiIndNode(WikiContentNode):
@jsonencoder
- def jsonEncode(self):
+ def json_encode(self):
return {
'level': self.level,
- 'content': self.content.jsonEncode()
+ 'content': self.content.json_encode()
}

Return to:

Send suggestions and report system problems to the System administrator.