Skip to content

Commit a2d2d36

Browse files
frenzymadnessaduh95
authored andcommitted
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: #58740 PR-URL: #58752 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ac6b822 commit a2d2d36

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

‎tools/configure.d/nodedownload.py‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
importzipfile
88
importtarfile
99
importcontextlib
10-
try:
11-
fromurllib.requestimportFancyURLopener, URLopener
12-
exceptImportError:
13-
fromurllibimportFancyURLopener, URLopener
10+
fromurllib.requestimportbuild_opener, install_opener, urlretrieve
1411

1512
defformatSize(amt):
1613
"""Format a size as a string in MB"""
@@ -21,11 +18,6 @@ def spin(c):
2118
spin=".:|'"
2219
return (spin[c%len(spin)])
2320

24-
classConfigOpener(FancyURLopener):
25-
"""fancy opener used by retrievefile. Set a UA"""
26-
# append to existing version (UA)
27-
version='%s node.js/configure'%URLopener.version
28-
2921
defreporthook(count, size, total):
3022
"""internal hook used by retrievefile"""
3123
sys.stdout.write(' Fetch: %c %sMB total, %sMB downloaded \r'%
@@ -38,7 +30,10 @@ def retrievefile(url, targetfile):
3830
try:
3931
sys.stdout.write(' <%s>\nConnecting...\r'%url)
4032
sys.stdout.flush()
41-
ConfigOpener().retrieve(url, targetfile, reporthook=reporthook)
33+
opener=build_opener()
34+
opener.addheaders= [('User-agent', f'Python-urllib/{sys.version_info.major}.{sys.version_info.minor} node.js/configure')]
35+
install_opener(opener)
36+
urlretrieve(url, targetfile, reporthook=reporthook)
4237
print('') # clear the line
4338
returntargetfile
4439
exceptIOErroraserr:

0 commit comments

Comments
 (0)