aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-07-31 16:49:23 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-07-31 16:49:23 +0300
commita85089f4495839590c791c02c833cd0f9b49733e (patch)
treea81647f33b47be6fd2bda0ce3caa4bc1d398a008
parent74fe0a22139f946835d50120708c9f9bd236d081 (diff)
downloadwit-a85089f4495839590c791c02c833cd0f9b49733e.tar.gz
wit-a85089f4495839590c791c02c833cd0f9b49733e.tar.bz2
bin/wikitrans: fix for python 3
-rwxr-xr-xbin/wikitrans14
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']

Return to:

Send suggestions and report system problems to the System administrator.