Tested with both Python 2.7 and Python 3.7.
Reviewed By: thakis
Differential Revision: https://reviews.llvm.org/D73234
import io
import os
-import urllib2
+try:
+ # In Python 3, we need the module urllib.reqest. In Python 2, this
+ # functionality was in the urllib2 module.
+ from urllib import request as urllib_request
+except ImportError:
+ import urllib2 as urllib_request
import sys
import zipfile
"""Download an archive from url and extract gn from it into output_dir."""
print('downloading %s ...' % url, end='')
sys.stdout.flush()
- data = urllib2.urlopen(url).read()
+ data = urllib_request.urlopen(url).read()
print(' done')
zipfile.ZipFile(io.BytesIO(data)).extract(gn, path=output_dir)