aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/util.py
diff options
context:
space:
mode:
authorShanavas M <shanavas.m2@gmail.com>2019-01-03 12:15:31 +0530
committerShanavas M <shanavas.m2@gmail.com>2019-01-03 14:41:54 +0530
commit1bc8f23232ea0960d32f7ffa34f86c80b8d4e403 (patch)
treeb33cef0ec1feccf2c52b2d0d5ea0b55f74b086fa /python/servo/util.py
parente68585a26f21c70e70b85f9c79fc0edd0a12fb23 (diff)
downloadservo-1bc8f23232ea0960d32f7ffa34f86c80b8d4e403.tar.gz
servo-1bc8f23232ea0960d32f7ffa34f86c80b8d4e403.zip
Fix certifi import error while running ./match bootstrap
Fixes #22590
Diffstat (limited to 'python/servo/util.py')
-rw-r--r--python/servo/util.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/python/servo/util.py b/python/servo/util.py
index 8359ad90b28..818240d39e6 100644
--- a/python/servo/util.py
+++ b/python/servo/util.py
@@ -28,14 +28,22 @@ try:
except ImportError:
HAS_SNI = False
-# The cafile parameter was added in 2.7.9
-if HAS_SNI and sys.version_info >= (2, 7, 9):
- import certifi
- 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 = {}
+HAS_SNI_AND_RECENT_PYTHON = HAS_SNI and sys.version_info >= (2, 7, 9)
+
+
+def get_static_rust_lang_org_dist():
+ if HAS_SNI_AND_RECENT_PYTHON:
+ return "https://static.rust-lang.org/dist"
+
+ return "https://static-rust-lang-org.s3.amazonaws.com/dist"
+
+
+def get_urlopen_kwargs():
+ # The cafile parameter was added in 2.7.9
+ if HAS_SNI_AND_RECENT_PYTHON:
+ import certifi
+ return {"cafile": certifi.where()}
+ return {}
def remove_readonly(func, path, _):
@@ -96,7 +104,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, **URLOPEN_KWARGS)
+ resp = urllib2.urlopen(req, **get_urlopen_kwargs())
fsize = None
if resp.info().getheader('Content-Length'):