From 2040831d0566221aa01640123451b7839fc45920 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 22 Jan 2020 14:31:12 -0800 Subject: [PATCH] [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 --- llvm/utils/gn/get.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/utils/gn/get.py b/llvm/utils/gn/get.py index c39649d..adb8eb7 100755 --- a/llvm/utils/gn/get.py +++ b/llvm/utils/gn/get.py @@ -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) -- 2.7.4