Commit 3f8f1643 authored by Fred Drake's avatar Fred Drake

Remove some false comments.

Reorganize so the initialization sequences does not bite us in the foot.
(There is no good reason to discard classes that clients may want to
subclass.)
parent f5fec3c8
...@@ -42,7 +42,7 @@ def get(using=None): ...@@ -42,7 +42,7 @@ def get(using=None):
def open(url, new=0, autoraise=1): def open(url, new=0, autoraise=1):
get().open(url, new, autoraise) get().open(url, new, autoraise)
def open_new(url): # Marked deprecated. May be removed in 2.1. def open_new(url):
get().open(url, 1) get().open(url, 1)
...@@ -76,26 +76,8 @@ def _synthesize(browser): ...@@ -76,26 +76,8 @@ def _synthesize(browser):
return [None, controller] return [None, controller]
ret ret
#
# Everything after this point initializes _browsers and _tryorder,
# then disappears. Some class definitions and instances remain
# live through these globals, but only the minimum set needed to
# support the user's platform.
#
#
# Platform support for Unix
#
# This is the right test because all these Unix browsers require either
# a console terminal of an X display to run. Note that we cannot split
# the TERM and DISPLAY cases, because we might be running Python from inside
# an xterm.
if os.environ.get("TERM") or os.environ.get("DISPLAY"):
PROCESS_CREATION_DELAY = 4
_tryorder = ("mozilla","netscape","kfm","grail","links","lynx","w3m")
def _iscommand(cmd): def _iscommand(cmd):
"""Return true if cmd can be found on the executable search path.""" """Return true if cmd can be found on the executable search path."""
path = os.environ.get("PATH") path = os.environ.get("PATH")
if not path: if not path:
...@@ -106,7 +88,11 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"): ...@@ -106,7 +88,11 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
return 1 return 1
return 0 return 0
class GenericBrowser:
PROCESS_CREATION_DELAY = 4
class GenericBrowser:
def __init__(self, cmd): def __init__(self, cmd):
self.name, self.args = cmd.split(None, 1) self.name, self.args = cmd.split(None, 1)
self.basename = os.path.basename(self.name) self.basename = os.path.basename(self.name)
...@@ -115,26 +101,11 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"): ...@@ -115,26 +101,11 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
command = "%s %s" % (self.name, self.args) command = "%s %s" % (self.name, self.args)
os.system(command % url) os.system(command % url)
def open_new(self, url): # Deprecated. May be removed in 2.1. def open_new(self, url):
self.open(url) self.open(url)
# Easy cases first -- register console browsers if we have them.
if os.environ.get("TERM"):
# The Links browser <http://artax.karlin.mff.cuni.cz/~mikulas/links/>
if _iscommand("links"):
register("links", None, GenericBrowser("links %s"))
# The Lynx browser <http://lynx.browser.org/>
if _iscommand("lynx"):
register("lynx", None, GenericBrowser("lynx %s"))
# The w3m browser <http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/eng/>
if _iscommand("w3m"):
register("w3m", None, GenericBrowser("w3m %s"))
# X browsers have more in the way of options class Netscape:
if os.environ.get("DISPLAY"):
# First, the Netscape series
if _iscommand("netscape") or _iscommand("mozilla"):
class Netscape:
"Launcher class for Netscape browsers." "Launcher class for Netscape browsers."
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -159,22 +130,11 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"): ...@@ -159,22 +130,11 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
else: else:
self._remote("openURL(%s)" % url, autoraise) self._remote("openURL(%s)" % url, autoraise)
# Deprecated. May be removed in 2.1.
def open_new(self, url): def open_new(self, url):
self.open(url, 1) self.open(url, 1)
if _iscommand("mozilla"):
register("mozilla", None, Netscape("mozilla"))
if _iscommand("netscape"):
register("netscape", None, Netscape("netscape"))
# Next, Mosaic -- old but still in use.
if _iscommand("mosaic"):
register("mosaic", None, GenericBrowser("mosaic %s >/dev/null &"))
# Konqueror/kfm, the KDE browser. class Konqueror:
if _iscommand("kfm") or _iscommand("konqueror"):
class Konqueror:
"""Controller for the KDE File Manager (kfm, or Konqueror). """Controller for the KDE File Manager (kfm, or Konqueror).
See http://developer.kde.org/documentation/other/kfmclient.html See http://developer.kde.org/documentation/other/kfmclient.html
...@@ -205,17 +165,13 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"): ...@@ -205,17 +165,13 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
# opening a new win. # opening a new win.
self._remote("openURL %s" % url) self._remote("openURL %s" % url)
# Deprecated. May be removed in 2.1.
open_new = open open_new = open
register("kfm", Konqueror, Konqueror())
# Grail, the Python browser. class Grail:
if _iscommand("grail"): # There should be a way to maintain a connection to Grail, but the
class Grail: # Grail remote control protocol doesn't really allow that at this
# There should be a way to maintain a connection to # point. It probably neverwill!
# Grail, but the Grail remote control protocol doesn't
# really allow that at this point. It probably neverwill!
def _find_grail_rc(self): def _find_grail_rc(self):
import glob import glob
import pwd import pwd
...@@ -256,26 +212,76 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"): ...@@ -256,26 +212,76 @@ if os.environ.get("TERM") or os.environ.get("DISPLAY"):
else: else:
self._remote("LOAD " + url) self._remote("LOAD " + url)
# Deprecated. May be removed in 2.1.
def open_new(self, url): def open_new(self, url):
self.open(url, 1) self.open(url, 1)
register("grail", Grail, None)
class WindowsDefault:
def open(self, url, new=0, autoraise=1):
os.startfile(url)
def open_new(self, url):
self.open(url)
# #
# Platform support for Windows # Platform support for Unix
# #
if sys.platform[:3] == "win": # This is the right test because all these Unix browsers require either
_tryorder = ("netscape", "windows-default") # a console terminal of an X display to run. Note that we cannot split
# the TERM and DISPLAY cases, because we might be running Python from inside
# an xterm.
if os.environ.get("TERM") or os.environ.get("DISPLAY"):
_tryorder = ("mozilla","netscape","kfm","grail","links","lynx","w3m")
# Easy cases first -- register console browsers if we have them.
if os.environ.get("TERM"):
# The Links browser <http://artax.karlin.mff.cuni.cz/~mikulas/links/>
if _iscommand("links"):
register("links", None, GenericBrowser("links %s"))
# The Lynx browser <http://lynx.browser.org/>
if _iscommand("lynx"):
register("lynx", None, GenericBrowser("lynx %s"))
# The w3m browser <http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/eng/>
if _iscommand("w3m"):
register("w3m", None, GenericBrowser("w3m %s"))
# X browsers have more in the way of options
if os.environ.get("DISPLAY"):
# First, the Netscape series
if _iscommand("netscape") or _iscommand("mozilla"):
if _iscommand("mozilla"):
register("mozilla", None, Netscape("mozilla"))
if _iscommand("netscape"):
register("netscape", None, Netscape("netscape"))
# Next, Mosaic -- old but still in use.
if _iscommand("mosaic"):
register("mosaic", None, GenericBrowser("mosaic %s >/dev/null &"))
# Konqueror/kfm, the KDE browser.
if _iscommand("kfm") or _iscommand("konqueror"):
register("kfm", Konqueror, Konqueror())
class WindowsDefault: # Grail, the Python browser.
if _iscommand("grail"):
register("grail", Grail, None)
class InternetConfig:
def open(self, url, new=0, autoraise=1): def open(self, url, new=0, autoraise=1):
os.startfile(url) ic.launchurl(url)
def open_new(self, url): # Deprecated. May be removed in 2.1. def open_new(self, url):
self.open(url) self.open(url)
#
# Platform support for Windows
#
if sys.platform[:3] == "win":
_tryorder = ("netscape", "windows-default")
register("windows-default", WindowsDefault) register("windows-default", WindowsDefault)
# #
...@@ -287,13 +293,6 @@ try: ...@@ -287,13 +293,6 @@ try:
except ImportError: except ImportError:
pass pass
else: else:
class InternetConfig:
def open(self, url, new=0, autoraise=1):
ic.launchurl(url)
def open_new(self, url): # Deprecated. May be removed in 2.1.
self.open(url)
# internet-config is the only supported controller on MacOS, # internet-config is the only supported controller on MacOS,
# so don't mess with the default! # so don't mess with the default!
_tryorder = ("internet-config") _tryorder = ("internet-config")
...@@ -315,5 +314,3 @@ for cmd in _tryorder: ...@@ -315,5 +314,3 @@ for cmd in _tryorder:
_tryorder = filter(lambda x: _browsers.has_key(x.lower()) _tryorder = filter(lambda x: _browsers.has_key(x.lower())
or x.find("%s") > -1, _tryorder) or x.find("%s") > -1, _tryorder)
# what to do if _tryorder is now empty? # what to do if _tryorder is now empty?
# end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment