bpo-35308: Fix regression where BROWSER env var is not respected. (GH-10693)

Regression introduced in e3ce695 and 25b804a, where the old parameter
update_tryorder to _synthesize was first ignored, then given the opposite
value in the attempt to fix bpo-31014.
This commit is contained in:
Zhiming Wang 2018-11-26 16:29:45 -05:00 committed by Serhiy Storchaka
parent 5a8c240b1d
commit 8c281ed403
3 changed files with 22 additions and 2 deletions

View File

@ -309,6 +309,24 @@ class ImportTest(unittest.TestCase):
webbrowser = support.import_fresh_module('webbrowser')
webbrowser.get()
def test_environment_preferred(self):
webbrowser = support.import_fresh_module('webbrowser')
try:
webbrowser.get()
least_preferred_browser = webbrowser.get(webbrowser._tryorder[-1]).name
except (webbrowser.Error, AttributeError, IndexError) as err:
self.skipTest(str(err))
with support.EnvironmentVarGuard() as env:
env["BROWSER"] = least_preferred_browser
webbrowser = support.import_fresh_module('webbrowser')
self.assertEqual(webbrowser.get().name, least_preferred_browser)
with support.EnvironmentVarGuard() as env:
env["BROWSER"] = sys.executable
webbrowser = support.import_fresh_module('webbrowser')
self.assertEqual(webbrowser.get().name, sys.executable)
if __name__=='__main__':
unittest.main()

View File

@ -86,7 +86,7 @@ def open_new_tab(url):
return open(url, 2)
def _synthesize(browser, *, preferred=True):
def _synthesize(browser, *, preferred=False):
"""Attempt to synthesize a controller base on existing controllers.
This is useful to create a controller when a user specifies a path to
@ -563,7 +563,7 @@ def register_standard_browsers():
# and prepend to _tryorder
for cmdline in userchoices:
if cmdline != '':
cmd = _synthesize(cmdline, preferred=False)
cmd = _synthesize(cmdline, preferred=True)
if cmd[1] is None:
register(cmdline, None, GenericBrowser(cmdline), preferred=True)

View File

@ -0,0 +1,2 @@
Fix regression in ``webbrowser`` where default browsers may be preferred
over browsers in the ``BROWSER`` environment variable.