mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-03 12:44:33 +02:00
Merge branch 'bugfix/idf_tools_python2' into 'master'
tools: fix idf_tools.py compatibility regression with Python 2 See merge request espressif/esp-idf!10841
This commit is contained in:
@@ -143,7 +143,7 @@ CURRENT_PLATFORM = PLATFORM_FROM_NAME.get(PYTHON_PLATFORM, UNKNOWN_PLATFORM)
|
|||||||
EXPORT_SHELL = 'shell'
|
EXPORT_SHELL = 'shell'
|
||||||
EXPORT_KEY_VALUE = 'key-value'
|
EXPORT_KEY_VALUE = 'key-value'
|
||||||
|
|
||||||
ISRG_X1_ROOT_CERT = """
|
ISRG_X1_ROOT_CERT = u"""
|
||||||
-----BEGIN CERTIFICATE-----
|
-----BEGIN CERTIFICATE-----
|
||||||
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
||||||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||||
@@ -307,7 +307,11 @@ def unpack(filename, destination):
|
|||||||
def urlretrieve_ctx(url, filename, reporthook=None, data=None, context=None):
|
def urlretrieve_ctx(url, filename, reporthook=None, data=None, context=None):
|
||||||
url_type, path = splittype(url)
|
url_type, path = splittype(url)
|
||||||
|
|
||||||
with contextlib.closing(urlopen(url, data, context=context)) as fp:
|
# urlopen doesn't have context argument in Python <=2.7.9
|
||||||
|
extra_urlopen_args = {}
|
||||||
|
if context:
|
||||||
|
extra_urlopen_args["context"] = context
|
||||||
|
with contextlib.closing(urlopen(url, data, **extra_urlopen_args)) as fp:
|
||||||
headers = fp.info()
|
headers = fp.info()
|
||||||
|
|
||||||
# Just return the local path and the "headers" for file://
|
# Just return the local path and the "headers" for file://
|
||||||
@@ -665,8 +669,13 @@ class IDFTool(object):
|
|||||||
# For dl.espressif.com, add the ISRG x1 root certificate.
|
# For dl.espressif.com, add the ISRG x1 root certificate.
|
||||||
# This works around the issue with outdated certificate stores in some installations.
|
# This works around the issue with outdated certificate stores in some installations.
|
||||||
if "dl.espressif.com" in url:
|
if "dl.espressif.com" in url:
|
||||||
ctx = ssl.create_default_context()
|
try:
|
||||||
ctx.load_verify_locations(cadata=ISRG_X1_ROOT_CERT)
|
ctx = ssl.create_default_context()
|
||||||
|
ctx.load_verify_locations(cadata=ISRG_X1_ROOT_CERT)
|
||||||
|
except AttributeError:
|
||||||
|
# no ssl.create_default_context or load_verify_locations cadata argument
|
||||||
|
# in Python <=2.7.8
|
||||||
|
pass
|
||||||
|
|
||||||
urlretrieve_ctx(url, local_temp_path, report_progress if not global_non_interactive else None, context=ctx)
|
urlretrieve_ctx(url, local_temp_path, report_progress if not global_non_interactive else None, context=ctx)
|
||||||
sys.stdout.write("\rDone\n")
|
sys.stdout.write("\rDone\n")
|
||||||
|
Reference in New Issue
Block a user