Skip to content

tools: make nodedownload module compatible with Python 3.14 #58752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions tools/configure.d/nodedownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import zipfile
import tarfile
import contextlib
try:
from urllib.request import FancyURLopener, URLopener
except ImportError:
from urllib import FancyURLopener, URLopener
from urllib.request import build_opener, install_opener, urlretrieve

def formatSize(amt):
"""Format a size as a string in MB"""
Expand All @@ -21,11 +18,6 @@ def spin(c):
spin = ".:|'"
return (spin[c % len(spin)])

class ConfigOpener(FancyURLopener):
"""fancy opener used by retrievefile. Set a UA"""
# append to existing version (UA)
version = '%s node.js/configure' % URLopener.version

def reporthook(count, size, total):
"""internal hook used by retrievefile"""
sys.stdout.write(' Fetch: %c %sMB total, %sMB downloaded \r' %
Expand All @@ -38,7 +30,10 @@ def retrievefile(url, targetfile):
try:
sys.stdout.write(' <%s>\nConnecting...\r' % url)
sys.stdout.flush()
ConfigOpener().retrieve(url, targetfile, reporthook=reporthook)
opener = build_opener()
opener.addheaders = [('User-agent', f'Python-urllib/{sys.version_info.major}.{sys.version_info.minor} node.js/configure')]
install_opener(opener)
urlretrieve(url, targetfile, reporthook=reporthook)
print('') # clear the line
return targetfile
except IOError as err:
Expand Down
Loading