summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-08-04 19:29:21 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-08-04 19:30:13 (GMT)
commit1fb7bc5aefaebf830b969c418f7987f50f4187f7 (patch) (side-by-side diff)
treee7e8e1ec9ff165a7324b526815f8a9937ec0784b
parent0f45f681cf167c6259d8a8aafb7c58c25156bde0 (diff)
downloadwikitrans-1fb7bc5aefaebf830b969c418f7987f50f4187f7.tar.gz
wikitrans-1fb7bc5aefaebf830b969c418f7987f50f4187f7.tar.bz2
wikitrans: fixes
* bin/wikitrans (getwiki): fix downloading for Python 2.7 Return a properly encoded string. Fix help output. Allow to use -t dump with -I wiktionary
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xbin/wikitrans16
1 files changed, 8 insertions, 8 deletions
diff --git a/bin/wikitrans b/bin/wikitrans
index ffbc048..c2ed4d3 100755
--- a/bin/wikitrans
+++ b/bin/wikitrans
@@ -32,7 +32,7 @@ from WikiTrans.wiki2texi import TexiWikiMarkup
from WikiTrans.wikimarkup import WikiMarkup
from WikiTrans.wikidump import DumpWikiMarkup
-# Set utf-8 as the default encoding.
+# Set utf-8 as the default encoding for Python 2.7.
# Trying to do so using encode('utf_8')/unicode, which is
# supposed to be the right way, does not work in Python 2.7
# Simply calling sys.setdefaultencoding is not possible,
@@ -47,7 +47,8 @@ except:
handlers = {
'dump': {
- 'default': DumpWikiMarkup
+ 'default': DumpWikiMarkup,
+ 'wiktionary': DumpWikiMarkup
},
'html': {
'default': HtmlWikiMarkup,
@@ -77,8 +78,7 @@ def getwiki(url):
root = etree.fromstring(u.read())
else:
import urllib
- u = urllib.URLopener()
- u.retrieve(url, tmp.name)
+ urllib.urlretrieve(url, tmp.name)
root = etree.parse(tmp.name).getroot()
ns = { 'wiki':'' }
if 'version' in root.attrib:
@@ -87,7 +87,7 @@ def getwiki(url):
if text is None:
print("no page/revision/text element in the downloaded page")
exit(0)
- return text.text
+ return text.text.encode()
def main():
usage = '%prog [OPTIONS] ARG'
@@ -111,11 +111,11 @@ Otherwise, ARG is name of the file to read wiki material from.
parser.add_option('-I', '--input-type',
action='store', type='string', dest='itype',
default='default',
- help='set input document type')
+ help='set input document type ("default" or "wiktionary")')
parser.add_option('-t', '--to', '--type',
action='store', type='string', dest='otype',
default='html',
- help='set output document type')
+ help='set output document type ("html" (default), "texi" or "text")')
parser.add_option('-l', '--lang',
action='store', type='string', dest='lang',
default='pl',
@@ -163,7 +163,7 @@ Otherwise, ARG is name of the file to read wiki material from.
print("%s" % str(markup))
exit(0)
else:
- print("unsupported input type: %s" % options.itype)
+ print("input type %s is not supported for %s output" % (options.itype, options.otype))
else:
print("unsupported output type: %s" % options.otype)
exit(1)

Return to:

Send suggestions and report system problems to the System administrator.