summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-16 00:12:35 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-07-16 00:12:35 +0300
commit45b2027439e96c366e188a12bd831802d30bbddc (patch)
tree4333fb83ed667b1000f3d6bf71bc11b44e76c468
parent6f963022315d4306f50f2e7046f2872cfd3c0500 (diff)
downloadwikitrans-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.
-rw-r--r--wiki2html.py10
-rw-r--r--wiki2texi.py9
-rw-r--r--wiki2text.py3
-rwxr-xr-xwikicvt.py22
-rw-r--r--wikimarkup.py5
5 files changed, 27 insertions, 22 deletions
diff --git a/wiki2html.py b/wiki2html.py
index 0330b92..05d4642 100644
--- a/wiki2html.py
+++ b/wiki2html.py
@@ -18,6 +18,8 @@
from wikimarkup import *
-from types import TupleType
from wikins import wiki_ns_re, wiki_ns
import re
-import urllib
+try:
+ from urllib import quote as url_quote
+except ImportError:
+ from urllib.parse import quote as url_quote
@@ -50,3 +52,3 @@ class HtmlWikiMarkup (WikiMarkup):
lang = self.lang
- return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
+ return self.html_base % { 'lang' : lang } + url_quote(tgt)
@@ -86,3 +88,3 @@ class HtmlWikiMarkup (WikiMarkup):
if len(elt['content']) > 1:
- s = map(self.format, elt['content'])
+ s = [x for x in map(self.format, elt['content'])]
if s[0] == 'disambigR' or s[0] == 'wikiquote':
diff --git a/wiki2texi.py b/wiki2texi.py
index a7b5e92..6e32c56 100644
--- a/wiki2texi.py
+++ b/wiki2texi.py
@@ -18,3 +18,2 @@
from wikimarkup import *
-from types import TupleType
from wikins import wiki_ns_re, wiki_ns
@@ -60,5 +59,5 @@ class TexiWikiMarkup (WikiMarkup):
super(TexiWikiMarkup, self).__init__(*args, **keywords)
- if keywords.has_key("sectioning-model"):
+ if "sectioning-model" in keywords:
val = keywords["sectioning-model"]
- if self.sectcomm.has_key(val):
+ if val in self.sectcomm:
self.sectioning_model = val
@@ -66,3 +65,3 @@ class TexiWikiMarkup (WikiMarkup):
raise ValueError("Invalid value for sectioning model: %s" % val)
- if keywords.has_key("sectioning-start"):
+ if "sectioning-start" in keywords:
val = keywords["sectioning-start"]
@@ -219,3 +218,3 @@ class TexiWikiMarkup (WikiMarkup):
if len(elt['content']) > 1:
- s = map(self.format, elt['content'])
+ s = [x for x in map(self.format, elt['content'])]
text = s[1]
diff --git a/wiki2text.py b/wiki2text.py
index 6308da1..916391e 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -18,3 +18,2 @@
from wikimarkup import *
-from types import TupleType
from wikins import wiki_ns_re, wiki_ns
@@ -70,3 +69,3 @@ class TextWikiMarkup (WikiMarkup):
if len(elt['content']) > 1:
- s = map(self.format, elt['content'])
+ s = [x for x in map(self.format, elt['content'])]
text = s[1]
diff --git a/wikicvt.py b/wikicvt.py
index c8ca887..41bba2f 100755
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -17,5 +17,9 @@
+from __future__ import print_function
import sys
import getopt
-import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
from wiki2html import *
@@ -27,3 +31,3 @@ class DumpWikiMarkup (WikiMarkup):
if self.tree:
- s = StringIO.StringIO()
+ s = StringIO()
self.dump(self.tree, 0, s)
@@ -34,6 +38,6 @@ class DumpWikiMarkup (WikiMarkup):
def usage(code=0):
- print """
-usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val]
- [--input-type=INTYPE] [--type=OUTTYPE] [--help] [--verbose] file
-""" % (sys.argv[0])
+ print("""usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang]
+ [--option kw=val] [--input-type=INTYPE] [--type=OUTTYPE] [--help]
+ [--verbose] file
+""" % sys.argv[0])
sys.exit(code)
@@ -111,8 +115,8 @@ def main():
markup.parse()
- print str(markup)
+ print("%s" % str(markup))
exit(0)
else:
- print "unsupported input type: %s" % (itype)
+ print("unsupported input type: %s" % itype)
else:
- print "unsupported output type: %s" % (otype)
+ print("unsupported output type: %s" % otype)
exit(1)
diff --git a/wikimarkup.py b/wikimarkup.py
index adaa1a2..2ef6be1 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -17,2 +17,3 @@
+from __future__ import print_function
import sys
@@ -117,3 +118,3 @@ class BaseWikiMarkup(object):
if self.debug_level >= lev:
- print "[DEBUG]", fmt % argv
+ print("[DEBUG]", fmt % argv)
@@ -995,3 +996,3 @@ class WikiMarkup (BaseWikiMarkup):
"glk": "گیلکی",
- "got": "𐌲Œ„𐌹𐌺 ",
+ "got": "𐌲𐌿𐍄𐌹𐍃𐌺𐍉𐍂𐌰𐌶𐌳𐌰",
"gn": "Avañe'ẽ", # Guarani

Return to:

Send suggestions and report system problems to the System administrator.