This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Arfrever, Mariatta, PedanticHacker, devplayer, eryksun, jbmilam, joncwchao, paul.moore, python-dev, r.david.murray, steve.dower, tim.golden, zach.ware
Date 2021-03-18.07:42:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616053370.87.0.406052708988.issue8232@roundup.psfhosted.org>
In-reply-to
Content
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
        ...
History
Date User Action Args
2021-03-18 07:42:51eryksunsetrecipients: + eryksun, paul.moore, tim.golden, Arfrever, r.david.murray, joncwchao, devplayer, python-dev, zach.ware, steve.dower, jbmilam, PedanticHacker, Mariatta
2021-03-18 07:42:50eryksunsetmessageid: <1616053370.87.0.406052708988.issue8232@roundup.psfhosted.org>
2021-03-18 07:42:50eryksunlinkissue8232 messages
2021-03-18 07:42:50eryksuncreate