From 404c722920043caf548bf10c0242aac5d22a96b3 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 19 Oct 2017 19:56:18 +0200 Subject: Only pass cafile argument to urlopen in Python versions that support it. --- python/servo/util.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'python/servo/util.py') diff --git a/python/servo/util.py b/python/servo/util.py index 485637b81f1..78158b840da 100644 --- a/python/servo/util.py +++ b/python/servo/util.py @@ -22,6 +22,20 @@ import urllib2 import certifi +try: + from ssl import HAS_SNI +except ImportError: + HAS_SNI = False + +# The cafile parameter was added in 2.7.9 +if HAS_SNI and sys.version_info >= (2, 7, 9): + STATIC_RUST_LANG_ORG_DIST = "https://static.rust-lang.org/dist" + URLOPEN_KWARGS = {"cafile": certifi.where()} +else: + STATIC_RUST_LANG_ORG_DIST = "https://static-rust-lang-org.s3.amazonaws.com/dist" + URLOPEN_KWARGS = {} + + def delete(path): if os.path.isdir(path) and not os.path.islink(path): shutil.rmtree(path) @@ -74,7 +88,7 @@ def download(desc, src, writer, start_byte=0): req = urllib2.Request(src) if start_byte: req = urllib2.Request(src, headers={'Range': 'bytes={}-'.format(start_byte)}) - resp = urllib2.urlopen(req, cafile=certifi.where()) + resp = urllib2.urlopen(req, **URLOPEN_KWARGS) fsize = None if resp.info().getheader('Content-Length'): -- cgit v1.2.3