mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Only pass cafile argument to urlopen in Python versions that support it.
This commit is contained in:
parent
aa62942fbd
commit
404c722920
4 changed files with 22 additions and 15 deletions
|
@ -27,8 +27,9 @@ from mach.decorators import (
|
||||||
)
|
)
|
||||||
|
|
||||||
import servo.bootstrap as bootstrap
|
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 delete, download_bytes, download_file, extract, host_triple
|
||||||
|
from servo.util import STATIC_RUST_LANG_ORG_DIST, URLOPEN_KWARGS
|
||||||
|
|
||||||
|
|
||||||
@CommandProvider
|
@CommandProvider
|
||||||
|
@ -94,7 +95,8 @@ class MachCommands(CommandBase):
|
||||||
else:
|
else:
|
||||||
import toml
|
import toml
|
||||||
channel = nightly_dist + "/channel-rust-nightly.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
|
base_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds-alt/" + nightly_commit_hash
|
||||||
|
|
||||||
|
|
|
@ -25,16 +25,6 @@ import toml
|
||||||
from servo.packages import WINDOWS_MSVC as msvc_deps
|
from servo.packages import WINDOWS_MSVC as msvc_deps
|
||||||
from servo.util import host_triple, host_platform
|
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 ""
|
BIN_SUFFIX = ".exe" if sys.platform == "win32" else ""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,9 @@ from mach.decorators import (
|
||||||
Command,
|
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.build_commands import notify_build_done
|
||||||
|
from servo.util import STATIC_RUST_LANG_ORG_DIST, URLOPEN_KWARGS
|
||||||
|
|
||||||
|
|
||||||
@CommandProvider
|
@CommandProvider
|
||||||
|
@ -263,7 +264,7 @@ class MachCommands(CommandBase):
|
||||||
category='devenv')
|
category='devenv')
|
||||||
def rustup(self):
|
def rustup(self):
|
||||||
url = STATIC_RUST_LANG_ORG_DIST + "/channel-rust-nightly-date.txt"
|
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")
|
filename = path.join(self.context.topdir, "rust-toolchain")
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w") as f:
|
||||||
f.write("nightly-%s\n" % nightly_date)
|
f.write("nightly-%s\n" % nightly_date)
|
||||||
|
|
|
@ -22,6 +22,20 @@ import urllib2
|
||||||
import certifi
|
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):
|
def delete(path):
|
||||||
if os.path.isdir(path) and not os.path.islink(path):
|
if os.path.isdir(path) and not os.path.islink(path):
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
@ -74,7 +88,7 @@ def download(desc, src, writer, start_byte=0):
|
||||||
req = urllib2.Request(src)
|
req = urllib2.Request(src)
|
||||||
if start_byte:
|
if start_byte:
|
||||||
req = urllib2.Request(src, headers={'Range': 'bytes={}-'.format(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
|
fsize = None
|
||||||
if resp.info().getheader('Content-Length'):
|
if resp.info().getheader('Content-Length'):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue