diff options
Diffstat (limited to 'Lib/webbrowser.py')
-rw-r--r-- | Lib/webbrowser.py | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py index 55aa04c..dd5e019 100644 --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -2,6 +2,7 @@ """Interfaces for launching and remotely controlling Web browsers.""" import os +import shlex import sys import stat import subprocess @@ -32,7 +33,11 @@ def get(using=None): for browser in alternatives: if '%s' in browser: # User gave us a command line, split it into name and args - return GenericBrowser(browser.split()) + browser = shlex.split(browser) + if browser[-1] == '&': + return BackgroundBrowser(browser[:-1]) + else: + return GenericBrowser(browser) else: # User gave us a browser name or path. try: @@ -437,19 +442,16 @@ class Grail(BaseBrowser): # a console terminal or an X display to run. def register_X_browsers(): - # The default Gnome browser - if _iscommand("gconftool-2"): - # get the web browser string from gconftool - gc = 'gconftool-2 -g /desktop/gnome/url-handlers/http/command 2>/dev/null' - out = os.popen(gc) - commd = out.read().strip() - retncode = out.close() - - # if successful, register it - if retncode is None and commd: - register("gnome", None, BackgroundBrowser(commd.split())) - - # First, the Mozilla/Netscape browsers + + # The default GNOME browser + if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gnome-open"): + register("gnome-open", None, BackgroundBrowser("gnome-open")) + + # The default KDE browser + if "KDE_FULL_SESSION" in os.environ and _iscommand("kfmclient"): + register("kfmclient", Konqueror, Konqueror("kfmclient")) + + # The Mozilla/Netscape browsers for browser in ("mozilla-firefox", "firefox", "mozilla-firebird", "firebird", "seamonkey", "mozilla", "netscape"): @@ -508,17 +510,28 @@ if os.environ.get("TERM"): if sys.platform[:3] == "win": class WindowsDefault(BaseBrowser): def open(self, url, new=0, autoraise=1): - os.startfile(url) - return True # Oh, my... + try: + os.startfile(url) + except WindowsError: + # [Error 22] No application is associated with the specified + # file for this operation: '<URL>' + return False + else: + return True _tryorder = [] _browsers = {} - # Prefer mozilla/netscape/opera if present + + # First try to use the default Windows browser + register("windows-default", WindowsDefault) + + # Detect some common Windows browsers, fallback to IE + iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"), + "Internet Explorer\\IEXPLORE.EXE") for browser in ("firefox", "firebird", "seamonkey", "mozilla", - "netscape", "opera"): + "netscape", "opera", iexplore): if _iscommand(browser): register(browser, None, BackgroundBrowser(browser)) - register("windows-default", WindowsDefault) # # Platform support for MacOS |