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 | |
parent | 6f963022315d4306f50f2e7046f2872cfd3c0500 (diff) | |
download | wit-45b2027439e96c366e188a12bd831802d30bbddc.tar.gz wit-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.py | 10 | ||||
-rw-r--r-- | wiki2texi.py | 9 | ||||
-rw-r--r-- | wiki2text.py | 3 | ||||
-rwxr-xr-x | wikicvt.py | 22 | ||||
-rw-r--r-- | wikimarkup.py | 5 |
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 @@ -16,10 +16,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. 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 class HtmlWikiMarkup (WikiMarkup): """ @@ -48,7 +50,7 @@ class HtmlWikiMarkup (WikiMarkup): def mktgt(self, tgt, lang = None): if not lang: lang = self.lang - return self.html_base % { 'lang' : lang } + urllib.quote(tgt) + return self.html_base % { 'lang' : lang } + url_quote(tgt) def tmpl_term(self, s): if len(s) == 2: @@ -84,7 +86,7 @@ class HtmlWikiMarkup (WikiMarkup): arg = self.format(elt['content'][0]) text = None 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': return "" elif len(s) > 1 and s[1] == 'thumb': diff --git a/wiki2texi.py b/wiki2texi.py index a7b5e92..6e32c56 100644 --- a/wiki2texi.py +++ b/wiki2texi.py @@ -16,7 +16,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from wikimarkup import * -from types import TupleType from wikins import wiki_ns_re, wiki_ns import re import urllib @@ -58,13 +57,13 @@ class TexiWikiMarkup (WikiMarkup): def __init__(self, *args, **keywords): 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 else: raise ValueError("Invalid value for sectioning model: %s" % val) - if keywords.has_key("sectioning-start"): + if "sectioning-start" in keywords: val = keywords["sectioning-start"] if val < 0 or val > 4: raise ValueError("Invalid value for sectioning start: %s" % val) @@ -217,7 +216,7 @@ class TexiWikiMarkup (WikiMarkup): # FIXME: A very crude version arg = self.format(elt['content'][0]) if len(elt['content']) > 1: - s = map(self.format, elt['content']) + s = [x for x in map(self.format, elt['content'])] text = s[1] else: s = None diff --git a/wiki2text.py b/wiki2text.py index 6308da1..916391e 100644 --- a/wiki2text.py +++ b/wiki2text.py @@ -16,7 +16,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from wikimarkup import * -from types import TupleType from wikins import wiki_ns_re, wiki_ns import re import urllib @@ -68,7 +67,7 @@ class TextWikiMarkup (WikiMarkup): def fmtlink(self, elt, istmpl): arg = self.format(elt['content'][0]) if len(elt['content']) > 1: - s = map(self.format, elt['content']) + s = [x for x in map(self.format, elt['content'])] text = s[1] else: s = None @@ -15,9 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +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 * from wiki2text import * from wiki2texi import * @@ -25,17 +29,17 @@ from wiki2texi import * class DumpWikiMarkup (WikiMarkup): def __str__(self): if self.tree: - s = StringIO.StringIO() + s = StringIO() self.dump(self.tree, 0, s) return s.getvalue() else: return "" 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) handlers = { @@ -109,12 +113,12 @@ def main(): markup = handlers[otype][itype](**kwdict) markup.debug_level = debug 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) if __name__ == '__main__': diff --git a/wikimarkup.py b/wikimarkup.py index adaa1a2..2ef6be1 100644 --- a/wikimarkup.py +++ b/wikimarkup.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from __future__ import print_function import sys import re from types import * @@ -115,7 +116,7 @@ class BaseWikiMarkup(object): def dprint(self, lev, fmt, *argv): if self.debug_level >= lev: - print "[DEBUG]", fmt % argv + print("[DEBUG]", fmt % argv) def print_dump_prefix(self, level, file): file.write("[DUMP]" + ' ' * (2*level + 1)) @@ -993,7 +994,7 @@ class WikiMarkup (BaseWikiMarkup): "gd": "Gàidhlig", # Scots; Gaelic "gl": "Gallego" , # Gallegan; Galician "glk": "گیلکی", - "got": "𐌲𐌹𐌺 ", + "got": "𐌲𐌿𐍄𐌹𐍃𐌺𐍉𐍂𐌰𐌶𐌳𐌰", "gn": "Avañe'ẽ", # Guarani "g": "ગુજરાતી", # Gujarati "gv": "Gaelg", # Manx |