Only pass cafile argument to urlopen in Python versions that support it.

This commit is contained in:
Simon Sapin 2017-10-19 19:56:18 +02:00
parent aa62942fbd
commit 404c722920
4 changed files with 22 additions and 15 deletions

View file

@ -27,8 +27,9 @@ from mach.decorators import (
)
import servo.bootstrap as bootstrap
from servo.command_base import CommandBase, BIN_SUFFIX, cd, STATIC_RUST_LANG_ORG_DIST
from servo.command_base import CommandBase, BIN_SUFFIX, cd
from servo.util import delete, download_bytes, download_file, extract, host_triple
from servo.util import STATIC_RUST_LANG_ORG_DIST, URLOPEN_KWARGS
@CommandProvider
@ -94,7 +95,8 @@ class MachCommands(CommandBase):
else:
import toml
channel = nightly_dist + "/channel-rust-nightly.toml"
nightly_commit_hash = toml.load(urllib2.urlopen(channel))["pkg"]["rustc"]["git_commit_hash"]
manifest = toml.load(urllib2.urlopen(channel, **URLOPEN_KWARGS))
nightly_commit_hash = manifest["pkg"]["rustc"]["git_commit_hash"]
base_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds-alt/" + nightly_commit_hash

View file

@ -25,16 +25,6 @@ import toml
from servo.packages import WINDOWS_MSVC as msvc_deps
from servo.util import host_triple, host_platform
try:
from ssl import HAS_SNI
except ImportError:
HAS_SNI = False
if HAS_SNI:
STATIC_RUST_LANG_ORG_DIST = "https://static.rust-lang.org/dist"
else:
STATIC_RUST_LANG_ORG_DIST = "https://static-rust-lang-org.s3.amazonaws.com/dist"
BIN_SUFFIX = ".exe" if sys.platform == "win32" else ""

View file

@ -21,8 +21,9 @@ from mach.decorators import (
Command,
)
from servo.command_base import CommandBase, cd, call, STATIC_RUST_LANG_ORG_DIST
from servo.command_base import CommandBase, cd, call
from servo.build_commands import notify_build_done
from servo.util import STATIC_RUST_LANG_ORG_DIST, URLOPEN_KWARGS
@CommandProvider
@ -263,7 +264,7 @@ class MachCommands(CommandBase):
category='devenv')
def rustup(self):
url = STATIC_RUST_LANG_ORG_DIST + "/channel-rust-nightly-date.txt"
nightly_date = urllib2.urlopen(url).read()
nightly_date = urllib2.urlopen(url, **URLOPEN_KWARGS).read()
filename = path.join(self.context.topdir, "rust-toolchain")
with open(filename, "w") as f:
f.write("nightly-%s\n" % nightly_date)

View file

@ -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'):