diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-07-31 16:49:23 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-07-31 16:49:23 +0300 |
commit | a85089f4495839590c791c02c833cd0f9b49733e (patch) | |
tree | a81647f33b47be6fd2bda0ce3caa4bc1d398a008 | |
parent | 74fe0a22139f946835d50120708c9f9bd236d081 (diff) | |
download | wit-a85089f4495839590c791c02c833cd0f9b49733e.tar.gz wit-a85089f4495839590c791c02c833cd0f9b49733e.tar.bz2 |
bin/wikitrans: fix for python 3
-rwxr-xr-x | bin/wikitrans | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/bin/wikitrans b/bin/wikitrans index e794dc2..3d85915 100755 --- a/bin/wikitrans +++ b/bin/wikitrans @@ -19,7 +19,6 @@ from __future__ import print_function from __future__ import unicode_literals import sys import re -import urllib import tempfile import xml.etree.ElementTree as etree from optparse import OptionParser @@ -72,10 +71,15 @@ def setkw(option, opt, value, parser): def getwiki(url): tmp = tempfile.NamedTemporaryFile() - u = urllib.URLopener() - u.retrieve(url, tmp.name) - tree = etree.parse(tmp.name) - root = tree.getroot() + if sys.version_info[0] > 2: + import urllib.request + with urllib.request.urlopen(url) as u: + root = etree.fromstring(u.read()) + else: + import urllib + u = urllib.URLopener() + u.retrieve(url, tmp.name) + root = etree.parse(tmp.name).getroot() ns = { 'wiki':'' } if 'version' in root.attrib: ns['wiki'] = 'http://www.mediawiki.org/xml/export-%s/' % root.attrib['version'] |