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 25b804a

Browse filesBrowse files
serhiy-storchakaJohn Still
andauthored
bpo-31014: Fix the webbrowser module. (GH-7267)
webbrowser._synthesize() called webbrowser.register() with outdated signature. Co-Authored-By: John Still <john@jmsdvl.com>
1 parent 0830858 commit 25b804a
Copy full SHA for 25b804a

File tree

Expand file treeCollapse file tree

3 files changed

+25
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-3
lines changed

‎Lib/test/test_webbrowser.py

Copy file name to clipboardExpand all lines: Lib/test/test_webbrowser.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import webbrowser
22
import unittest
3+
import os
4+
import sys
35
import subprocess
46
from unittest import mock
57
from test import support
@@ -290,6 +292,23 @@ def test_get(self):
290292
webbrowser.get('fakebrowser')
291293
self.assertIsNotNone(webbrowser._tryorder)
292294

295+
def test_synthesize(self):
296+
webbrowser = support.import_fresh_module('webbrowser')
297+
name = os.path.basename(sys.executable).lower()
298+
webbrowser.register(name, None, webbrowser.GenericBrowser(name))
299+
webbrowser.get(sys.executable)
300+
301+
def test_environment(self):
302+
webbrowser = support.import_fresh_module('webbrowser')
303+
try:
304+
browser = webbrowser.get().name
305+
except (webbrowser.Error, AttributeError) as err:
306+
self.skipTest(str(err))
307+
with support.EnvironmentVarGuard() as env:
308+
env["BROWSER"] = browser
309+
webbrowser = support.import_fresh_module('webbrowser')
310+
webbrowser.get()
311+
293312

294313
if __name__=='__main__':
295314
unittest.main()

‎Lib/webbrowser.py

Copy file name to clipboardExpand all lines: Lib/webbrowser.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def open_new_tab(url):
8686
return open(url, 2)
8787

8888

89-
def _synthesize(browser, update_tryorder=1):
89+
def _synthesize(browser, *, preferred=True):
9090
"""Attempt to synthesize a controller base on existing controllers.
9191
9292
This is useful to create a controller when a user specifies a path to
@@ -113,7 +113,7 @@ def _synthesize(browser, update_tryorder=1):
113113
controller = copy.copy(controller)
114114
controller.name = browser
115115
controller.basename = os.path.basename(browser)
116-
register(browser, None, controller, update_tryorder)
116+
register(browser, None, instance=controller, preferred=preferred)
117117
return [None, controller]
118118
return [None, None]
119119

@@ -563,7 +563,7 @@ def register_standard_browsers():
563563
# and prepend to _tryorder
564564
for cmdline in userchoices:
565565
if cmdline != '':
566-
cmd = _synthesize(cmdline, -1)
566+
cmd = _synthesize(cmdline, preferred=False)
567567
if cmd[1] is None:
568568
register(cmdline, None, GenericBrowser(cmdline), preferred=True)
569569

+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed creating a controller for :mod:`webbrowser` when a user specifies a
2+
path to an entry in the BROWSER environment variable. Based on patch by
3+
John Still.

0 commit comments

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