[llvm] 2040831 - [gn] Paper over Py3 urllib2 incompatibility in gn/get.py
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 11:39:23 PST 2020
Author: Reid Kleckner
Date: 2020-02-11T11:39:16-08:00
New Revision: 2040831d0566221aa01640123451b7839fc45920
URL: https://github.com/llvm/llvm-project/commit/2040831d0566221aa01640123451b7839fc45920
DIFF: https://github.com/llvm/llvm-project/commit/2040831d0566221aa01640123451b7839fc45920.diff
LOG: [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
Added:
Modified:
llvm/utils/gn/get.py
Removed:
################################################################################
diff --git a/llvm/utils/gn/get.py b/llvm/utils/gn/get.py
index c39649df78a4..adb8eb7d5715 100755
--- a/llvm/utils/gn/get.py
+++ b/llvm/utils/gn/get.py
@@ -5,7 +5,12 @@
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)
More information about the llvm-commits
mailing list