Пример #1
0
    def _winStartURL(self, url):
        """'start' the given URL.
        
        Typically this just means running os.startfile(). However that
        drops HTML anchors (i.e. foo.html#anchor -> foo.html), so if it
        looks like the URL has an anchor we try to do better.
        """
        import wininteg
        if url.find("#") != -1:
            # Attempt to find the associated default action for this file
            # and run that. If cannot, then fallback to just running
            # os.startfile().
            #
            #XXX Note that we are not doing this perfectly. There are some
            #    some registered action mechanisms that we are not handling.
            #    As well we don't handle any of the ddeexec keys in the
            #    registry.
            page, anchor = url.split("#", 1)
            ext = os.path.splitext(page)[1]
            try:
                type, name, actions = wininteg.getFileAssociation(ext)
            except wininteg.WinIntegError:
                pass
            else:
                if actions:
                    command = actions[0][2]
                    # See "help ftype" in cmd.exe for description of %-codes.
                    command = self._cmdInterpolate(command, url)
                    return self._spawn(command)

        try:
            os.startfile(url)
            return 1
        except WindowsError, e:
            # I don't know who is at fault here but if Netscape 6 (and
            # presumable, therefore, some versions of Mozilla) is set as
            # the default then (1) the browser successfully loads the
            # file *and* (2) this is raised:
            #    Traceback (most recent call last):
            #      File "C:\mozilla_source\moz.09apr.trentm.winnt.release.komodo5\mozilla\dist\WIN32_O.OBJ\bin\components\koWebbrowser.py", line 27, in open_new
            #        os.startfile(url)
            #    WindowsError: [Errno 2] The system cannot find the file specified: 'http://www.ActiveState.com/ASPN/Downloads/Komodo/NeedLicense?os=Windows2000v.5.0.2195&build=19520&version=1.1.0-devel'
            #
            if e.errno == 2:
                return 1
            else:
                return 0
Пример #2
0
    def _winStartURL(self, url):
        """'start' the given URL.
        
        Typically this just means running os.startfile(). However that
        drops HTML anchors (i.e. foo.html#anchor -> foo.html), so if it
        looks like the URL has an anchor we try to do better.
        """
        import wininteg
        if url.find("#") != -1:
            # Attempt to find the associated default action for this file
            # and run that. If cannot, then fallback to just running
            # os.startfile().
            #
            #XXX Note that we are not doing this perfectly. There are some
            #    some registered action mechanisms that we are not handling.
            #    As well we don't handle any of the ddeexec keys in the
            #    registry.
            page, anchor = url.split("#", 1)
            ext = os.path.splitext(page)[1]
            try:
                type, name, actions = wininteg.getFileAssociation(ext)
            except wininteg.WinIntegError:
                pass
            else:
                if actions:
                    command = actions[0][2]
                    # See "help ftype" in cmd.exe for description of %-codes.
                    command = self._cmdInterpolate(command, url)
                    return self._spawn(command)

        try:
            os.startfile(url)
            return 1
        except WindowsError, e:
            # I don't know who is at fault here but if Netscape 6 (and
            # presumable, therefore, some versions of Mozilla) is set as
            # the default then (1) the browser successfully loads the
            # file *and* (2) this is raised:
            #    Traceback (most recent call last):
            #      File "C:\mozilla_source\moz.09apr.trentm.winnt.release.komodo5\mozilla\dist\WIN32_O.OBJ\bin\components\koWebbrowser.py", line 27, in open_new
            #        os.startfile(url)
            #    WindowsError: [Errno 2] The system cannot find the file specified: 'http://www.ActiveState.com/ASPN/Downloads/Komodo/NeedLicense?os=Windows2000v.5.0.2195&build=19520&version=1.1.0-devel'
            #
            if e.errno == 2:
                return 1
            else:
                return 0
Пример #3
0
    def get_firefox_paths(self):
        #TODO: Could just use the new `self._gen_possible_browsers_and_types()`
        #      and only use the `browser_type == 'firefox'` results.
        firefoxes = []
        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if argv and "firefox" in argv[0].lower():
                            firefoxes.append(argv[0])

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)
        if sys.platform.startswith('win'):
            firefoxes += which.whichall("firefox", exts=['.exe'], path=path)
        elif sys.platform == 'darwin':
            path = ['/Applications', '/Network/Applications'] + path
            firefoxes += which.whichall("Firefox.app", path=path)
        else:
            firefoxes += which.whichall("firefox", path=path)

        # check for duplicates
        firefoxesWithoutDups = []
        for i in range(len(firefoxes)):
            for j in range(i+1, len(firefoxes)):
                if self._SameFile(firefoxes[i], firefoxes[j]):
                    break
            else:
                firefoxesWithoutDups.append(firefoxes[i])
        return firefoxesWithoutDups
Пример #4
0
    def get_firefox_paths(self):
        #TODO: Could just use the new `self._gen_possible_browsers_and_types()`
        #      and only use the `browser_type == 'firefox'` results.
        firefoxes = []
        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if argv and "firefox" in argv[0].lower():
                            firefoxes.append(argv[0])

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)
        if sys.platform.startswith('win'):
            firefoxes += which.whichall("firefox", exts=['.exe'], path=path)
        elif sys.platform == 'darwin':
            path = ['/Applications', '/Network/Applications'] + path
            firefoxes += which.whichall("Firefox.app", path=path)
        else:
            firefoxes += which.whichall("firefox", path=path)

        # check for duplicates
        firefoxesWithoutDups = []
        for i in range(len(firefoxes)):
            for j in range(i + 1, len(firefoxes)):
                if self._SameFile(firefoxes[i], firefoxes[j]):
                    break
            else:
                firefoxesWithoutDups.append(firefoxes[i])
        return firefoxesWithoutDups
Пример #5
0
    def _gen_possible_browsers_and_types(self):
        browser_paths = _PathSet()  # set of yielded browser paths, used to avoid dupes

        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if not argv:
                            continue
                        browser = argv[0]
                        if browser not in browser_paths:
                            browser_paths.add(browser)
                            yield browser, self._guess_browser_type_from_path(browser)

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)

        if sys.platform.startswith('win'):
            from applib import _get_win_folder

            # Gather some default install dirs on Windows, because some of the
            # current stock of Windows browsers don't register themselves in
            # the usual ways.
            default_install_dirs_from_browser_type = defaultdict(list)
            programFiles = os.environ.get("ProgramFiles")
            if programFiles:
                default_install_dirs_from_browser_type["safari"].append(
                    join(programFiles, "Safari"))
                default_install_dirs_from_browser_type["opera"].append(
                    join(programFiles, "Opera"))
            try:
                localAppDataDir = _get_win_folder("CSIDL_LOCAL_APPDATA")
            except Exception, ex:
                log.warn("error getting local appdata dir: %s", ex)
            else:
                if localAppDataDir:
                    default_install_dirs_from_browser_type["googlechrome"].append(
                        join(localAppDataDir, "Google", "Chrome", "Application"))
            matches = []
            for browser_type in ("firefox",
                                 "internetexplorer",
                                 "safari",
                                 "googlechrome",
                                 "chromium",
                                 "opera",
                                 "mozilla",
                                 "msnexplorer",
                                 "flock"):
                exe_name = self._exe_name_from_browser_type.get(browser_type, browser_type)
                bpath = path + default_install_dirs_from_browser_type.get(browser_type, [])
                for browser in which.whichall(exe_name, exts=[".exe"], path=bpath):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type
Пример #6
0
    def _gen_possible_browsers_and_types(self):
        browser_paths = _PathSet(
        )  # set of yielded browser paths, used to avoid dupes

        # If on Windows, add the browser(s) assigned as the default handlers
        # for .html, .htm, etc. (i.e. for common browser-y filetypes).
        if sys.platform.startswith("win"):
            import wininteg
            for ext in (".html", ".htm"):
                try:
                    type, name, actions = wininteg.getFileAssociation(ext)
                except wininteg.WinIntegError:
                    pass
                else:
                    if actions:
                        command = actions[0][2]
                        argv = self._parseAssociationAction(command)
                        if not argv:
                            continue
                        browser = argv[0]
                        if browser not in browser_paths:
                            browser_paths.add(browser)
                            yield browser, self._guess_browser_type_from_path(
                                browser)

        # Search the PATH as it was when Komodo started, otherwise Komodo's
        # internal mozilla.exe might be listed as a possible browser.
        #   http://bugs.activestate.com/show_bug.cgi?id=26373
        PATH = koprocessutils.getUserEnv().get("PATH", "")
        path = PATH.split(os.pathsep)

        if sys.platform.startswith('win'):
            from applib import _get_win_folder

            # Gather some default install dirs on Windows, because some of the
            # current stock of Windows browsers don't register themselves in
            # the usual ways.
            default_install_dirs_from_browser_type = defaultdict(list)
            programFiles = os.environ.get("ProgramFiles")
            if programFiles:
                default_install_dirs_from_browser_type["safari"].append(
                    join(programFiles, "Safari"))
                default_install_dirs_from_browser_type["opera"].append(
                    join(programFiles, "Opera"))
            try:
                localAppDataDir = _get_win_folder("CSIDL_LOCAL_APPDATA")
            except Exception, ex:
                log.warn("error getting local appdata dir: %s", ex)
            else:
                if localAppDataDir:
                    default_install_dirs_from_browser_type[
                        "googlechrome"].append(
                            join(localAppDataDir, "Google", "Chrome",
                                 "Application"))
            matches = []
            for browser_type in ("firefox", "internetexplorer", "safari",
                                 "googlechrome", "chromium", "opera",
                                 "mozilla", "msnexplorer", "flock"):
                exe_name = self._exe_name_from_browser_type.get(
                    browser_type, browser_type)
                bpath = path + default_install_dirs_from_browser_type.get(
                    browser_type, [])
                for browser in which.whichall(exe_name,
                                              exts=[".exe"],
                                              path=bpath):
                    if browser not in browser_paths:
                        browser_paths.add(browser)
                        yield browser, browser_type