Skip to content

Commit 39fc85f

Browse files
committed
Merge pull request #1931 from andig/andig-patch-2
Python 3 compatibility
2 parents 8c65f2f + 1092b42 commit 39fc85f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/get.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Written by Ivan Grokhotkov, 2015.
55
#
66
from __future__ import print_function
7-
import urllib
87
import os
98
import shutil
109
import errno
@@ -16,6 +15,11 @@
1615
import tarfile
1716
import zipfile
1817
import re
18+
if sys.version_info[0] == 3:
19+
from urllib.request import urlretrieve
20+
else:
21+
# Not Python 3 - today, it is most likely to be Python 2
22+
from urllib import urlretrieve
1923

2024
dist_dir = 'dist/'
2125

@@ -54,7 +58,7 @@ def unpack(filename, destination):
5458
raise NotImplementedError('Unsupported archive type')
5559

5660
# a little trick to rename tool directories so they don't contain version number
57-
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).encode('ascii').strip('-')
61+
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-')
5862
if rename_to != dirname:
5963
print('Renaming {0} to {1}'.format(dirname, rename_to))
6064
if os.path.isdir(rename_to):
@@ -68,7 +72,7 @@ def get_tool(tool):
6872
real_hash = tool['checksum'].split(':')[1]
6973
if not os.path.isfile(local_path):
7074
print('Downloading ' + archive_name);
71-
urllib.urlretrieve(url, local_path, report_progress)
75+
urlretrieve(url, local_path, report_progress)
7276
sys.stdout.write("\rDone\n")
7377
sys.stdout.flush()
7478
else:

0 commit comments

Comments
 (0)