Skip to content

Commit

Permalink
Replaced legacy urllib.request.URLopener with urllib.request.build_op…
Browse files Browse the repository at this point in the history
…ener()
  • Loading branch information
corporateshark committed Jul 19, 2021
1 parent a76f4e1 commit 88f02b8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 88f02b8

Please sign in to comment.