diff options
-rw-r--r-- | test.py | 2 | ||||
-rw-r--r-- | wiki2html.py | 4 | ||||
-rw-r--r-- | wiki2texi.py | 4 | ||||
-rw-r--r-- | wiki2text.py | 20 | ||||
-rw-r--r-- | wikimarkup.py | 2 |
5 files changed, 19 insertions, 13 deletions
@@ -13,12 +13,14 @@ | |||
13 | # GNU General Public License for more details. | 13 | # GNU General Public License for more details. |
14 | # | 14 | # |
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 | from __future__ import print_function |
19 | import sys, os | ||
20 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | ||
19 | import unittest | 21 | import unittest |
20 | import wiki2html | 22 | import wiki2html |
21 | 23 | ||
22 | class TestMarkupParserBasic (unittest.TestCase): | 24 | class TestMarkupParserBasic (unittest.TestCase): |
23 | 25 | ||
24 | def test_colon(self): | 26 | def test_colon(self): |
diff --git a/wiki2html.py b/wiki2html.py index 05d4642..abf851a 100644 --- a/wiki2html.py +++ b/wiki2html.py | |||
@@ -12,14 +12,14 @@ | |||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | # GNU General Public License for more details. | 13 | # GNU General Public License for more details. |
14 | # | 14 | # |
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 wikimarkup import * | 18 | from wit.wikimarkup import * |
19 | from wikins import wiki_ns_re, wiki_ns | 19 | from wit.wikins import wiki_ns_re, wiki_ns |
20 | import re | 20 | import re |
21 | try: | 21 | try: |
22 | from urllib import quote as url_quote | 22 | from urllib import quote as url_quote |
23 | except ImportError: | 23 | except ImportError: |
24 | from urllib.parse import quote as url_quote | 24 | from urllib.parse import quote as url_quote |
25 | 25 | ||
diff --git a/wiki2texi.py b/wiki2texi.py index 6e32c56..4ce32f9 100644 --- a/wiki2texi.py +++ b/wiki2texi.py | |||
@@ -12,14 +12,14 @@ | |||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | # GNU General Public License for more details. | 13 | # GNU General Public License for more details. |
14 | # | 14 | # |
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 wikimarkup import * | 18 | from wit.wikimarkup import * |
19 | from wikins import wiki_ns_re, wiki_ns | 19 | from wit.wikins import wiki_ns_re, wiki_ns |
20 | import re | 20 | import re |
21 | import urllib | 21 | import urllib |
22 | 22 | ||
23 | class TexiWikiMarkup (WikiMarkup): | 23 | class TexiWikiMarkup (WikiMarkup): |
24 | sectcomm = { | 24 | sectcomm = { |
25 | 'numbered': [ | 25 | 'numbered': [ |
diff --git a/wiki2text.py b/wiki2text.py index 916391e..5041ea0 100644 --- a/wiki2text.py +++ b/wiki2text.py | |||
@@ -12,16 +12,20 @@ | |||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | # GNU General Public License for more details. | 13 | # GNU General Public License for more details. |
14 | # | 14 | # |
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 wikimarkup import * | 18 | from wit.wikimarkup import * |
19 | from wikins import wiki_ns_re, wiki_ns | 19 | from wit.wikins import wiki_ns_re, wiki_ns |
20 | import re | 20 | import re |
21 | import urllib | 21 | try: |
22 | from urllib import quote as url_quote | ||
23 | except ImportError: | ||
24 | from urllib.parse import quote as url_quote | ||
25 | |||
22 | 26 | ||
23 | class TextWikiMarkup (WikiMarkup): | 27 | class TextWikiMarkup (WikiMarkup): |
24 | """ | 28 | """ |
25 | A (general-purpose Wiki->Text translator class. | 29 | A (general-purpose Wiki->Text translator class. |
26 | """ | 30 | """ |
27 | 31 | ||
@@ -55,17 +59,17 @@ class TextWikiMarkup (WikiMarkup): | |||
55 | return wiki_ns[self.lang][str] | 59 | return wiki_ns[self.lang][str] |
56 | elif str in wiki_ns_re[self.lang]: | 60 | elif str in wiki_ns_re[self.lang]: |
57 | for elt in wiki_ns_re[self.lang][str]: | 61 | for elt in wiki_ns_re[self.lang][str]: |
58 | if str.beginswith(elt[0]) and str.endswith(elt[1]): | 62 | if str.beginswith(elt[0]) and str.endswith(elt[1]): |
59 | return elt[2] | 63 | return elt[2] |
60 | return None | 64 | return None |
61 | 65 | ||
62 | def mktgt(self, tgt, lang = None): | 66 | def mktgt(self, tgt, lang = None): |
63 | if not lang: | 67 | if not lang: |
64 | lang = self.lang | 68 | lang = self.lang |
65 | return self.html_base % { 'lang' : lang } + urllib.quote(tgt) | 69 | return self.html_base % { 'lang' : lang } + url_quote(tgt) |
66 | 70 | ||
67 | def fmtlink(self, elt, istmpl): | 71 | def fmtlink(self, elt, istmpl): |
68 | arg = self.format(elt['content'][0]) | 72 | arg = self.format(elt['content'][0]) |
69 | if len(elt['content']) > 1: | 73 | if len(elt['content']) > 1: |
70 | s = [x for x in map(self.format, elt['content'])] | 74 | s = [x for x in map(self.format, elt['content'])] |
71 | text = s[1] | 75 | text = s[1] |
@@ -84,14 +88,14 @@ class TextWikiMarkup (WikiMarkup): | |||
84 | if ns: | 88 | if ns: |
85 | if ns == 'NS_IMAGE': | 89 | if ns == 'NS_IMAGE': |
86 | if not self.references: | 90 | if not self.references: |
87 | return "" | 91 | return "" |
88 | text = "[%s: %s]" % (qual, text if text else arg) | 92 | text = "[%s: %s]" % (qual, text if text else arg) |
89 | tgt = self.image_base + '/' + \ | 93 | tgt = self.image_base + '/' + \ |
90 | urllib.quote(tgt) + \ | 94 | url_quote(tgt) + \ |
91 | '/250px-' + urllib.quote(tgt) | 95 | '/250px-' + url_quote(tgt) |
92 | elif ns == 'NS_MEDIA': | 96 | elif ns == 'NS_MEDIA': |
93 | text = "[%s]" % (qual) | 97 | text = "[%s]" % (qual) |
94 | else: | 98 | else: |
95 | tgt = self.mktgt(tgt) | 99 | tgt = self.mktgt(tgt) |
96 | elif not istmpl and qual in self.langtab: | 100 | elif not istmpl and qual in self.langtab: |
97 | text = self.langtab[qual] + ": " + tgt | 101 | text = self.langtab[qual] + ": " + tgt |
@@ -109,13 +113,13 @@ class TextWikiMarkup (WikiMarkup): | |||
109 | 113 | ||
110 | def indent (self, lev, text): | 114 | def indent (self, lev, text): |
111 | if text.find('\n') == -1: | 115 | if text.find('\n') == -1: |
112 | s = (" " * lev) + text | 116 | s = (" " * lev) + text |
113 | else: | 117 | else: |
114 | s = "" | 118 | s = "" |
115 | for elt in text.split('\n'): | 119 | for elt in text.decode("utf-8").split('\n'): |
116 | if elt: | 120 | if elt: |
117 | s += (" " * lev) + elt + '\n' | 121 | s += (" " * lev) + elt + '\n' |
118 | if not text.endswith('\n'): | 122 | if not text.endswith('\n'): |
119 | s = s.rstrip('\n') | 123 | s = s.rstrip('\n') |
120 | # print "IN: '%s'" % (text) | 124 | # print "IN: '%s'" % (text) |
121 | # print "OUT: '%s'" % (s) | 125 | # print "OUT: '%s'" % (s) |
diff --git a/wikimarkup.py b/wikimarkup.py index 2ef6be1..9371d89 100644 --- a/wikimarkup.py +++ b/wikimarkup.py | |||
@@ -850,13 +850,13 @@ class WikiMarkup (BaseWikiMarkup): | |||
850 | for kw in keywords: | 850 | for kw in keywords: |
851 | if kw == 'file': | 851 | if kw == 'file': |
852 | self.file = keywords[kw] | 852 | self.file = keywords[kw] |
853 | elif kw == 'filename': | 853 | elif kw == 'filename': |
854 | self.file = open(keywords[kw]) | 854 | self.file = open(keywords[kw]) |
855 | elif kw == 'text': | 855 | elif kw == 'text': |
856 | self.text = keywords[kw].split("\n") | 856 | self.text = keywords[kw].decode("utf-8").split("\n") |
857 | elif kw == 'lang': | 857 | elif kw == 'lang': |
858 | self.lang = keywords[kw] | 858 | self.lang = keywords[kw] |
859 | elif kw == 'html_base': | 859 | elif kw == 'html_base': |
860 | self.html_base = keywords[kw] | 860 | self.html_base = keywords[kw] |
861 | elif kw == 'image_base': | 861 | elif kw == 'image_base': |
862 | self.image_base = keywords[kw] | 862 | self.image_base = keywords[kw] |