summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-04-12 22:07:27 (GMT)
committerFred Drake <fdrake@acm.org>2001-04-12 22:07:27 (GMT)
commitf4e5bd9df540aa5b24e47d03dbb798ed277793f7 (patch)
tree3955ef589db0215e1ef79fe149c640e6921f6021
parentbb0bae6da2c322971041d7943d1096d0590a9d3f (diff)
downloadcpython-f4e5bd9df540aa5b24e47d03dbb798ed277793f7.zip
cpython-f4e5bd9df540aa5b24e47d03dbb798ed277793f7.tar.gz
cpython-f4e5bd9df540aa5b24e47d03dbb798ed277793f7.tar.bz2
_synthesize(): Helper function: when the users passes a specific
value for the 'using' parameter of the get() function or the BROWSER environment variable, if the thing passed in is a path (as seems to be the case with KDE) instead of a short name, examine the available controllers to see if we can synthesize one based on a pre-registered controller that shares the same base name. get(): If the user specifies a browser we don't know about, use _synthesize() to attempt to create a usable controller. Some small adjustments were needed in some of the browser classes to support this.
-rw-r--r--Lib/webbrowser.py57
1 files changed, 50 insertions, 7 deletions
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index d882e7f..ad195e0 100644
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -27,7 +27,10 @@ def get(using=None):
return GenericBrowser(browser)
else:
# User gave us a browser name.
- command = _browsers[browser.lower()]
+ try:
+ command = _browsers[browser.lower()]
+ except KeyError:
+ command = _synthesize(browser)
if command[1] is None:
return command[0]()
else:
@@ -42,6 +45,37 @@ def open(url, new=0, autoraise=1):
def open_new(url): # Marked deprecated. May be removed in 2.1.
get().open(url, 1)
+
+def _synthesize(browser):
+ """Attempt to synthesize a controller base on existing controllers.
+
+ This is useful to create a controller when a user specifies a path to
+ an entry in the BROWSER environment variable -- we can copy a general
+ controller to operate using a specific installation of the desired
+ browser in this way.
+
+ If we can't create a controller in this way, or if there is no
+ executable for the requested browser, return [None, None].
+
+ """
+ if not os.path.exists(browser):
+ return [None, None]
+ name = os.path.basename(browser)
+ try:
+ command = _browsers[name.lower()]
+ except KeyError:
+ return [None, None]
+ # now attempt to clone to fit the new name:
+ controller = command[1]
+ if controller and name.lower() == controller.basename:
+ import copy
+ controller = copy.copy(controller)
+ controller.name = browser
+ controller.basename = os.path.basename(browser)
+ register(browser, None, controller)
+ return [None, controller]
+ ret
+
#
# Everything after this point initializes _browsers and _tryorder,
# then disappears. Some class definitions and instances remain
@@ -74,10 +108,12 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
class GenericBrowser:
def __init__(self, cmd):
- self.command = cmd
+ self.name, self.args = cmd.split(None, 1)
+ self.basename = os.path.basename(self.name)
def open(self, url, new=0, autoraise=1):
- os.system(self.command % url)
+ command = "%s %s" % (self.name, self.args)
+ os.system(command % url)
def open_new(self, url): # Deprecated. May be removed in 2.1.
self.open(url)
@@ -102,6 +138,7 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
"Launcher class for Netscape browsers."
def __init__(self, name):
self.name = name
+ self.basename = os.path.basename(name)
def _remote(self, action, autoraise):
raise_opt = ("-noraise", "-raise")[autoraise]
@@ -144,15 +181,21 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
for more information on the Konqueror remote-control interface.
"""
+ def __init__(self):
+ if _iscommand("konqueror"):
+ self.name = self.basename = "konqueror"
+ else:
+ self.name = self.basename = "kfm"
+
def _remote(self, action):
cmd = "kfmclient %s >/dev/null 2>&1" % action
rc = os.system(cmd)
if rc:
import time
- if _iscommand("konqueror"):
- os.system("konqueror --silent &")
+ if self.basename == "konqueror":
+ os.system(self.name + " --silent &")
else:
- os.system("kfm -d &")
+ os.system(self.name + " -d &")
time.sleep(PROCESS_CREATION_DELAY)
rc = os.system(cmd)
return not rc
@@ -165,7 +208,7 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
# Deprecated. May be removed in 2.1.
open_new = open
- register("kfm", Konqueror, None)
+ register("kfm", Konqueror, Konqueror())
# Grail, the Python browser.
if _iscommand("grail"):