summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -13,16 +13,18 @@
# GNU General Public License for more details.
#
# 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 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):
"""
A (hopefully) general-purpose Wiki->HTML translator class.
FIXME: 1. See WikiMarkup for a list
2. [[official position]]s : final 's' gets after closing </a> tag.
@@ -45,13 +47,13 @@ class HtmlWikiMarkup (WikiMarkup):
"defn": { "hdr": "dl",
"elt": ["dt","dd"] } }
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:
return s[1]
text = None
trans = None
@@ -81,13 +83,13 @@ class HtmlWikiMarkup (WikiMarkup):
def fmtlink(self, elt, istmpl):
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':
return ""
text = '<span class="template">' + s[1] + '</span>'
if istmpl:
diff --git a/wiki2texi.py b/wiki2texi.py
index a7b5e92..6e32c56 100644
--- a/wiki2texi.py
+++ b/wiki2texi.py
@@ -13,13 +13,12 @@
# GNU General Public License for more details.
#
# 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 wikimarkup import *
-from types import TupleType
from wikins import wiki_ns_re, wiki_ns
import re
import urllib
class TexiWikiMarkup (WikiMarkup):
sectcomm = {
@@ -55,19 +54,19 @@ class TexiWikiMarkup (WikiMarkup):
sectioning_model = 'numbered'
sectioning_start = 0
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)
else:
self.sectioning_start = val
@@ -214,13 +213,13 @@ class TexiWikiMarkup (WikiMarkup):
return string
def str_link(self, elt):
# 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
text = None
if s:
diff --git a/wiki2text.py b/wiki2text.py
index 6308da1..916391e 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -13,13 +13,12 @@
# GNU General Public License for more details.
#
# 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 wikimarkup import *
-from types import TupleType
from wikins import wiki_ns_re, wiki_ns
import re
import urllib
class TextWikiMarkup (WikiMarkup):
"""
@@ -65,13 +64,13 @@ class TextWikiMarkup (WikiMarkup):
lang = self.lang
return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
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
text = None
if s:
diff --git a/wikicvt.py b/wikicvt.py
index c8ca887..41bba2f 100755
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -12,33 +12,37 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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 *
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 = {
'dump': {
'default': DumpWikiMarkup
},
@@ -106,16 +110,16 @@ def main():
if otype in handlers:
if itype in handlers[otype]:
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__':
main()
diff --git a/wikimarkup.py b/wikimarkup.py
index adaa1a2..2ef6be1 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -12,12 +12,13 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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 *
__all__ = [ "BaseWikiMarkup", "WikiMarkup",
"TagAttributes", "TagAttributeSyntax" ]
@@ -112,13 +113,13 @@ class BaseWikiMarkup(object):
nested = 0
debug_level = 0
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))
def dump_nil(self, node, level, file):
pass
@@ -990,13 +991,13 @@ class WikiMarkup (BaseWikiMarkup):
"ga": "Gaeilge", # Irish
"gan": "贛語 (Gànyŭ)",
"gd": "Gàidhlig", # Scots; Gaelic
"gl": "Gallego" , # Gallegan; Galician
"glk": "گیلکی",
- "got": "𐌲Œ„𐌹𐌺 ",
+ "got": "𐌲𐌿𐍄𐌹𐍃𐌺𐍉𐍂𐌰𐌶𐌳𐌰",
"gn": "Avañe'ẽ", # Guarani
"g": "ગુજરાતી", # Gujarati
"gv": "Gaelg", # Manx
"ha": "هَوُسَ", # Hausa
"hak": "Hak-kâ-fa / 客家話",

Return to:

Send suggestions and report system problems to the System administrator.