summaryrefslogtreecommitdiff
path: root/wikitrans/wikidump.py
diff options
context:
space:
mode:
Diffstat (limited to 'wikitrans/wikidump.py')
-rw-r--r--wikitrans/wikidump.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/wikitrans/wikidump.py b/wikitrans/wikidump.py
index d5f651c..bc71876 100644
--- a/wikitrans/wikidump.py
+++ b/wikitrans/wikidump.py
@@ -1,16 +1,16 @@
1# Wiki "dump" format. -*- coding: utf-8 -*- 1# Wiki "dump" format. -*- coding: utf-8 -*-
2# Copyright (C) 2015-2018 Sergey Poznyakoff 2# Copyright (C) 2015-2018 Sergey Poznyakoff
3# 3#
4# This program is free software; you can redistribute it and/or modify 4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option) 6# the Free Software Foundation; either version 3, or (at your option)
7# any later version. 7# any later version.
8# 8#
9# This program is distributed in the hope that it will be useful, 9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details. 12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>. 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
@@ -28,6 +28,7 @@ from wikitrans.wikitoken import *
28import json 28import json
29from wikitrans.wikimarkup import WikiMarkup 29from wikitrans.wikimarkup import WikiMarkup
30 30
31
31class DumpReferences(object): 32class DumpReferences(object):
32 idx = 0 33 idx = 0
33 def __len__(self): 34 def __len__(self):
@@ -43,13 +44,14 @@ class DumpWikiMarkup(WikiMarkup):
43 x = DumpWikiMarkup(file="input.wiki") 44 x = DumpWikiMarkup(file="input.wiki")
44 # Parse the input: 45 # Parse the input:
45 x.parse() 46 x.parse()
46 # Print a JSON dump of the parse tree 47 # Print a JSON dump of the parse tree
47 print(str(x)) 48 print(str(x))
48 49
49 """ 50 """
50 51
51 indent = None 52 indent = None
52 references = DumpReferences() 53 references = DumpReferences()
54
53 def __init__(self, **kwarg): 55 def __init__(self, **kwarg):
54 """Create a DumpWikiMarkup object. 56 """Create a DumpWikiMarkup object.
55 57
@@ -64,14 +66,14 @@ class DumpWikiMarkup(WikiMarkup):
64 indent=N 66 indent=N
65 Basic indent offset for JSON objects. 67 Basic indent offset for JSON objects.
66 """ 68 """
67
68 n = kwarg.pop('indent', None) 69 n = kwarg.pop('indent', None)
69 if n != None: 70 if n != None:
70 self.indent = int(n) 71 self.indent = int(n)
71 super(DumpWikiMarkup,self).__init__(self, **kwarg) 72 super(DumpWikiMarkup, self).__init__(self, **kwarg)
73
72 def __str__(self): 74 def __str__(self):
73 return json.dumps(self.tree, 75 return json.dumps(self.tree,
74 cls=WikiNodeEncoder, 76 cls=WikiNodeEncoder,
75 indent=self.indent, 77 indent=self.indent,
76 separators=(',',': '), 78 separators=(',', ': '),
77 sort_keys=True) 79 sort_keys=True)

Return to:

Send suggestions and report system problems to the System administrator.