From e43a4d51f2da1d359f7fccc622e2f4292d5158a4 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 14 Oct 2020 18:24:55 +0200 Subject: [PATCH 1/2] tools: fix idf_tools.py compatibility regression with Python 2 In Python 2, cadata must be explicitly converted to unicode: https://bugs.python.org/issue37079 Regression from 081ebcf1e7776b4a67e3c350020068d66ce0e416 --- tools/idf_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index 9e6c6c8537..eba2a53e76 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -143,7 +143,7 @@ CURRENT_PLATFORM = PLATFORM_FROM_NAME.get(PYTHON_PLATFORM, UNKNOWN_PLATFORM) EXPORT_SHELL = 'shell' EXPORT_KEY_VALUE = 'key-value' -ISRG_X1_ROOT_CERT = """ +ISRG_X1_ROOT_CERT = u""" -----BEGIN CERTIFICATE----- MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh From d9db49d9f7f3f2906339aee5ec226866300dc0a8 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 14 Oct 2020 20:19:32 +0200 Subject: [PATCH 2/2] tools: idf_tools.py: fix compatibility with Python <= 2.7.8 Multiple ssl-related features have been backported from Python 3.x to Python 2.7.9. This adds a fallback so that idf_tools.py can work on older versions. --- tools/idf_tools.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index eba2a53e76..7dbe56a4d1 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -307,7 +307,11 @@ def unpack(filename, destination): def urlretrieve_ctx(url, filename, reporthook=None, data=None, context=None): 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() # 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. # This works around the issue with outdated certificate stores in some installations. if "dl.espressif.com" in url: - ctx = ssl.create_default_context() - ctx.load_verify_locations(cadata=ISRG_X1_ROOT_CERT) + try: + 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) sys.stdout.write("\rDone\n")