gh-113539: Enable using `$BROWSER` to reorder default seach order in webbrowser.py (#113561)

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
Ronald Oussoren 2025-04-25 13:36:18 +02:00 committed by GitHub
parent 1a70f66ea8
commit 25e49841e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 4 deletions

View file

@ -482,10 +482,10 @@ def register_standard_browsers():
if sys.platform == 'darwin':
register("MacOSX", None, MacOSXOSAScript('default'))
register("chrome", None, MacOSXOSAScript('chrome'))
register("chrome", None, MacOSXOSAScript('google chrome'))
register("firefox", None, MacOSXOSAScript('firefox'))
register("safari", None, MacOSXOSAScript('safari'))
# OS X can use below Unix support (but we prefer using the OS X
# macOS can use below Unix support (but we prefer using the macOS
# specific stuff)
if sys.platform == "ios":
@ -559,6 +559,19 @@ def register_standard_browsers():
# Treat choices in same way as if passed into get() but do register
# and prepend to _tryorder
for cmdline in userchoices:
if all(x not in cmdline for x in " \t"):
# Assume this is the name of a registered command, use
# that unless it is a GenericBrowser.
try:
command = _browsers[cmdline.lower()]
except KeyError:
pass
else:
if not isinstance(command[1], GenericBrowser):
_tryorder.insert(0, cmdline.lower())
continue
if cmdline != '':
cmd = _synthesize(cmdline, preferred=True)
if cmd[1] is None: