diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-16 00:12:35 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-07-16 00:12:35 +0300 |
commit | 45b2027439e96c366e188a12bd831802d30bbddc (patch) | |
tree | 4333fb83ed667b1000f3d6bf71bc11b44e76c468 /wikicvt.py | |
parent | 6f963022315d4306f50f2e7046f2872cfd3c0500 (diff) | |
download | wikitrans-45b2027439e96c366e188a12bd831802d30bbddc.tar.gz wikitrans-45b2027439e96c366e188a12bd831802d30bbddc.tar.bz2 |
Support for Python 3
* wiki2html.py: Import urllib.parse if importing urllib fails.
Use list comprehensions to build lists from maps.
* wiki2texi.py: Use 'in' instead of has_key.
Use list comprehensions to build lists from maps.
* wiki2text.py: Likewise.
* wikicvt.py: Use print function.
Import StringIO from io if unable to import is as a module
* wikimarkup.py: Use print function.
Fix some UTF strings.
Diffstat (limited to 'wikicvt.py')
-rwxr-xr-x | wikicvt.py | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -15,9 +15,13 @@ | |||
15 | # You should have received a copy of the GNU General Public License | 15 | # You should have received a copy of the GNU General Public License |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | from __future__ import print_function | ||
18 | import sys | 19 | import sys |
19 | import getopt | 20 | import getopt |
20 | import StringIO | 21 | try: |
22 | from StringIO import StringIO | ||
23 | except ImportError: | ||
24 | from io import StringIO | ||
21 | from wiki2html import * | 25 | from wiki2html import * |
22 | from wiki2text import * | 26 | from wiki2text import * |
23 | from wiki2texi import * | 27 | from wiki2texi import * |
@@ -25,17 +29,17 @@ from wiki2texi import * | |||
25 | class DumpWikiMarkup (WikiMarkup): | 29 | class DumpWikiMarkup (WikiMarkup): |
26 | def __str__(self): | 30 | def __str__(self): |
27 | if self.tree: | 31 | if self.tree: |
28 | s = StringIO.StringIO() | 32 | s = StringIO() |
29 | self.dump(self.tree, 0, s) | 33 | self.dump(self.tree, 0, s) |
30 | return s.getvalue() | 34 | return s.getvalue() |
31 | else: | 35 | else: |
32 | return "" | 36 | return "" |
33 | 37 | ||
34 | def usage(code=0): | 38 | def usage(code=0): |
35 | print """ | 39 | print("""usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] |
36 | usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val] | 40 | [--option kw=val] [--input-type=INTYPE] [--type=OUTTYPE] [--help] |
37 | [--input-type=INTYPE] [--type=OUTTYPE] [--help] [--verbose] file | 41 | [--verbose] file |
38 | """ % (sys.argv[0]) | 42 | """ % sys.argv[0]) |
39 | sys.exit(code) | 43 | sys.exit(code) |
40 | 44 | ||
41 | handlers = { | 45 | handlers = { |
@@ -109,12 +113,12 @@ def main(): | |||
109 | markup = handlers[otype][itype](**kwdict) | 113 | markup = handlers[otype][itype](**kwdict) |
110 | markup.debug_level = debug | 114 | markup.debug_level = debug |
111 | markup.parse() | 115 | markup.parse() |
112 | print str(markup) | 116 | print("%s" % str(markup)) |
113 | exit(0) | 117 | exit(0) |
114 | else: | 118 | else: |
115 | print "unsupported input type: %s" % (itype) | 119 | print("unsupported input type: %s" % itype) |
116 | else: | 120 | else: |
117 | print "unsupported output type: %s" % (otype) | 121 | print("unsupported output type: %s" % otype) |
118 | exit(1) | 122 | exit(1) |
119 | 123 | ||
120 | if __name__ == '__main__': | 124 | if __name__ == '__main__': |