Eryk Sun <[email protected]> added the comment:
Windows Vista is no longer a concern, so find_windows_browsers() doesn't have
to worry about the KEY_WOW64_* flags. IMO, it should get the browser's real
name (the default value of the key) and the fully-qualified path of the
executable, instead of depending solely on an "App Paths" entry being
configured for the base executable name. For example:
def find_windows_browsers():
""" Read the installed browsers from the Windows registry."""
import winreg
browsers = []
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"Software\Clients\StartMenuInternet") as hkey:
i = 0
while True:
try:
subkey = winreg.EnumKey(hkey, i)
i += 1
except OSError as e:
if e.winerror != 259: # ERROR_NO_MORE_ITEMS
raise
break
try:
name = winreg.QueryValue(hkey, subkey)
if not name or not isinstance(name, str):
name = subkey
except OSError:
name = subkey
try:
cmd = winreg.QueryValue(hkey,
rf"{subkey}\shell\open\command")
cmd = cmd.strip('"')
os.stat(cmd)
except (OSError, AttributeError, TypeError, ValueError):
cmd = ""
browsers.append((name, cmd))
return browsers
The loop over the result would change to `for browser, cmd in
find_windows_browsers()`. The string to match for Internet Explorer, using the
real name instead of the registry key name, would be "internet explorer". A
class for Microsoft Edge ("msedge") should be added.
The browser would get instantiated with the cmd value, which ideally is the
fully-qualified path of the executable. The fallback behavior wouldn't change
for the case where self.cmd is an empty string. For example:
class WindowsDefault(BaseBrowser):
cmd = newwindow = newtab = ""
def __init__(self, name="", cmd=""):
super().__init__(name)
if cmd:
self.cmd = cmd
...
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue8232>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com