From 88f02b8540b39d24aba1a19435474039a829a1f8 Mon Sep 17 00:00:00 2001 From: Sergey Kosarevsky Date: Mon, 19 Jul 2021 14:30:33 +0300 Subject: [PATCH] Replaced legacy urllib.request.URLopener with urllib.request.build_opener() --- bootstrap.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index beb70c2..7f14c9b 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -20,7 +20,6 @@ from urllib.request import urlparse from urllib.request import urlunparse from urllib.request import urlretrieve - from urllib.request import URLopener from urllib.request import quote except ImportError: from urlparse import urlparse @@ -87,11 +86,6 @@ def dlog(string): if DEBUG_OUTPUT: print("*** " + string) - -class MyURLOpener(URLopener): - pass - - def executeCommand(command, printCommand = False, quiet = False): printCommand = printCommand or DEBUG_OUTPUT @@ -345,8 +339,11 @@ def downloadFile(url, download_dir, target_dir_name, sha1_hash = None, force_dow downloadSCP(p.hostname, p.username, p.path, download_dir) else: if user_agent is not None: - MyURLOpener.version = user_agent - MyURLOpener().retrieve(url, target_filename) + opener = urllib.request.build_opener() + opener.addheaders = [('User-agent', user_agent)] + f = open(target_filename, 'wb') + f.write(opener.open(url).read()) + f.close() else: urlretrieve(url, target_filename) else: