mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
tools: make nodedownload module compatible with Python 3.14
FancyURLopener and URLopener have been deprecated since Python 3.3 and they are removed completely from 3.14. Fixes: https://github.com/nodejs/node/issues/58740 PR-URL: https://github.com/nodejs/node/pull/58752 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
eafbe277b0
commit
dfcb824ae3
1 changed files with 5 additions and 10 deletions
|
@ -7,10 +7,7 @@ import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import tarfile
|
import tarfile
|
||||||
import contextlib
|
import contextlib
|
||||||
try:
|
from urllib.request import build_opener, install_opener, urlretrieve
|
||||||
from urllib.request import FancyURLopener, URLopener
|
|
||||||
except ImportError:
|
|
||||||
from urllib import FancyURLopener, URLopener
|
|
||||||
|
|
||||||
def formatSize(amt):
|
def formatSize(amt):
|
||||||
"""Format a size as a string in MB"""
|
"""Format a size as a string in MB"""
|
||||||
|
@ -21,11 +18,6 @@ def spin(c):
|
||||||
spin = ".:|'"
|
spin = ".:|'"
|
||||||
return (spin[c % len(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):
|
def reporthook(count, size, total):
|
||||||
"""internal hook used by retrievefile"""
|
"""internal hook used by retrievefile"""
|
||||||
sys.stdout.write(' Fetch: %c %sMB total, %sMB downloaded \r' %
|
sys.stdout.write(' Fetch: %c %sMB total, %sMB downloaded \r' %
|
||||||
|
@ -38,7 +30,10 @@ def retrievefile(url, targetfile):
|
||||||
try:
|
try:
|
||||||
sys.stdout.write(' <%s>\nConnecting...\r' % url)
|
sys.stdout.write(' <%s>\nConnecting...\r' % url)
|
||||||
sys.stdout.flush()
|
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
|
print('') # clear the line
|
||||||
return targetfile
|
return targetfile
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue