diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2017-10-19 19:56:18 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2017-10-19 19:56:18 +0200 |
commit | 404c722920043caf548bf10c0242aac5d22a96b3 (patch) | |
tree | 4d499b5c5ef99d693cae65b8e0b061e89f79c237 /python/servo/util.py | |
parent | aa62942fbd836279da8ea41d2e5d4ca9dd61fad3 (diff) | |
download | servo-404c722920043caf548bf10c0242aac5d22a96b3.tar.gz servo-404c722920043caf548bf10c0242aac5d22a96b3.zip |
Only pass cafile argument to urlopen in Python versions that support it.
Diffstat (limited to 'python/servo/util.py')
-rw-r--r-- | python/servo/util.py | 16 |
1 files changed, 15 insertions, 1 deletions
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'): |