[gn] Paper over Py3 urllib2 incompatibility in gn/get.py

Tested with both Python 2.7 and Python 3.7.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D73234
This commit is contained in:
Reid Kleckner 2020-01-22 14:31:12 -08:00
parent f65f9d3bc5
commit 2040831d05
1 changed files with 7 additions and 2 deletions

View File

@ -5,7 +5,12 @@ from __future__ import print_function
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
@ -14,7 +19,7 @@ def download_and_unpack(url, output_dir, gn):
"""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)