Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83b9f8e

Browse filesBrowse files
frenzymadnessmarco-ippolito
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 4106bfc commit 83b9f8e
Copy full SHA for 83b9f8e

1 file changed

+5-10Lines changed: 5 additions & 10 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tools/configure.d/nodedownload.py‎

Copy file name to clipboardExpand all lines: tools/configure.d/nodedownload.py
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import zipfile
88
import tarfile
99
import contextlib
10-
try:
11-
from urllib.request import FancyURLopener, URLopener
12-
except ImportError:
13-
from urllib import FancyURLopener, URLopener
10+
from urllib.request import build_opener, install_opener, urlretrieve
1411

1512
def formatSize(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-
class ConfigOpener(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
def reporthook(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
return targetfile
4439
except IOError as err:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.