| 
									
										
										
										
											2001-03-02 02:01:40 +00:00
										 |  |  | """Interfaces for launching and remotely controlling Web browsers.""" | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-01 04:27:19 +00:00
										 |  |  | __all__ = ["Error", "open", "get", "register"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | class Error(Exception): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-09 20:06:00 +00:00
										 |  |  | _browsers = {}          # Dictionary of available browser controllers | 
					
						
							|  |  |  | _tryorder = []          # Preference order of available browsers | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def register(name, klass, instance=None): | 
					
						
							|  |  |  |     """Register a browser connector and, optionally, connection.""" | 
					
						
							|  |  |  |     _browsers[name.lower()] = [klass, instance] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | def get(using=None): | 
					
						
							|  |  |  |     """Return a browser launcher instance appropriate for the environment.""" | 
					
						
							| 
									
										
										
										
											2002-06-02 03:04:52 +00:00
										 |  |  |     if using is not None: | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |         alternatives = [using] | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         alternatives = _tryorder | 
					
						
							|  |  |  |     for browser in alternatives: | 
					
						
							| 
									
										
										
										
											2004-05-04 09:21:43 +00:00
										 |  |  |         if '%s' in browser: | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |             # User gave us a command line, don't mess with it. | 
					
						
							| 
									
										
										
										
											2001-03-31 01:50:52 +00:00
										 |  |  |             return GenericBrowser(browser) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2001-02-09 20:06:00 +00:00
										 |  |  |             # User gave us a browser name. | 
					
						
							| 
									
										
										
										
											2001-04-12 22:07:27 +00:00
										 |  |  |             try: | 
					
						
							|  |  |  |                 command = _browsers[browser.lower()] | 
					
						
							|  |  |  |             except KeyError: | 
					
						
							|  |  |  |                 command = _synthesize(browser) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |             if command[1] is None: | 
					
						
							|  |  |  |                 return command[0]() | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 return command[1] | 
					
						
							|  |  |  |     raise Error("could not locate runnable browser") | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Please note: the following definition hides a builtin function. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:49:44 +00:00
										 |  |  | def open(url, new=0, autoraise=1): | 
					
						
							|  |  |  |     get().open(url, new, autoraise) | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  | def open_new(url): | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |     get().open(url, 1) | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-12 22:07:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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] | 
					
						
							| 
									
										
										
										
											2001-08-13 14:37:23 +00:00
										 |  |  |     return [None, None] | 
					
						
							| 
									
										
										
										
											2001-04-12 22:07:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def _iscommand(cmd): | 
					
						
							| 
									
										
										
										
											2002-04-04 22:55:58 +00:00
										 |  |  |     """Return True if cmd can be found on the executable search path.""" | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  |     path = os.environ.get("PATH") | 
					
						
							|  |  |  |     if not path: | 
					
						
							| 
									
										
										
										
											2002-04-04 22:55:58 +00:00
										 |  |  |         return False | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  |     for d in path.split(os.pathsep): | 
					
						
							|  |  |  |         exe = os.path.join(d, cmd) | 
					
						
							|  |  |  |         if os.path.isfile(exe): | 
					
						
							| 
									
										
										
										
											2002-04-04 22:55:58 +00:00
										 |  |  |             return True | 
					
						
							|  |  |  |     return False | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PROCESS_CREATION_DELAY = 4 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GenericBrowser: | 
					
						
							|  |  |  |     def __init__(self, cmd): | 
					
						
							|  |  |  |         self.name, self.args = cmd.split(None, 1) | 
					
						
							|  |  |  |         self.basename = os.path.basename(self.name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open(self, url, new=0, autoraise=1): | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |         assert "'" not in url | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  |         command = "%s %s" % (self.name, self.args) | 
					
						
							|  |  |  |         os.system(command % url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open_new(self, url): | 
					
						
							|  |  |  |         self.open(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Netscape: | 
					
						
							|  |  |  |     "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] | 
					
						
							|  |  |  |         cmd = "%s %s -remote '%s' >/dev/null 2>&1" % (self.name, | 
					
						
							|  |  |  |                                                       raise_opt, | 
					
						
							|  |  |  |                                                       action) | 
					
						
							|  |  |  |         rc = os.system(cmd) | 
					
						
							|  |  |  |         if rc: | 
					
						
							|  |  |  |             import time | 
					
						
							|  |  |  |             os.system("%s &" % self.name) | 
					
						
							|  |  |  |             time.sleep(PROCESS_CREATION_DELAY) | 
					
						
							|  |  |  |             rc = os.system(cmd) | 
					
						
							|  |  |  |         return not rc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open(self, url, new=0, autoraise=1): | 
					
						
							|  |  |  |         if new: | 
					
						
							|  |  |  |             self._remote("openURL(%s, new-window)"%url, autoraise) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self._remote("openURL(%s)" % url, autoraise) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open_new(self, url): | 
					
						
							|  |  |  |         self.open(url, 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-10 22:49:29 +00:00
										 |  |  | class Galeon: | 
					
						
							|  |  |  |     """Launcher class for Galeon browsers.""" | 
					
						
							|  |  |  |     def __init__(self, name): | 
					
						
							|  |  |  |         self.name = name | 
					
						
							|  |  |  |         self.basename = os.path.basename(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _remote(self, action, autoraise): | 
					
						
							|  |  |  |         raise_opt = ("--noraise", "")[autoraise] | 
					
						
							|  |  |  |         cmd = "%s %s %s >/dev/null 2>&1" % (self.name, raise_opt, action) | 
					
						
							|  |  |  |         rc = os.system(cmd) | 
					
						
							|  |  |  |         if rc: | 
					
						
							|  |  |  |             import time | 
					
						
							|  |  |  |             os.system("%s >/dev/null 2>&1 &" % self.name) | 
					
						
							|  |  |  |             time.sleep(PROCESS_CREATION_DELAY) | 
					
						
							|  |  |  |             rc = os.system(cmd) | 
					
						
							|  |  |  |         return not rc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open(self, url, new=0, autoraise=1): | 
					
						
							|  |  |  |         if new: | 
					
						
							|  |  |  |             self._remote("-w '%s'" % url, autoraise) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self._remote("-n '%s'" % url, autoraise) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open_new(self, url): | 
					
						
							|  |  |  |         self.open(url, 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  | class Konqueror: | 
					
						
							|  |  |  |     """Controller for the KDE File Manager (kfm, or Konqueror).
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     See http://developer.kde.org/documentation/other/kfmclient.html | 
					
						
							|  |  |  |     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): | 
					
						
							| 
									
										
										
										
											2002-10-11 22:04:22 +00:00
										 |  |  |         cmd = "kfmclient %s >/dev/null 2>&1" % action | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  |         rc = os.system(cmd) | 
					
						
							|  |  |  |         if rc: | 
					
						
							|  |  |  |             import time | 
					
						
							|  |  |  |             if self.basename == "konqueror": | 
					
						
							|  |  |  |                 os.system(self.name + " --silent &") | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 os.system(self.name + " -d &") | 
					
						
							|  |  |  |             time.sleep(PROCESS_CREATION_DELAY) | 
					
						
							|  |  |  |             rc = os.system(cmd) | 
					
						
							|  |  |  |         return not rc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open(self, url, new=1, autoraise=1): | 
					
						
							|  |  |  |         # XXX Currently I know no way to prevent KFM from | 
					
						
							|  |  |  |         # opening a new win. | 
					
						
							| 
									
										
										
										
											2002-10-11 22:04:22 +00:00
										 |  |  |         assert "'" not in url | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |         self._remote("openURL '%s'" % url) | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     open_new = open | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Grail: | 
					
						
							|  |  |  |     # There should be a way to maintain a connection to Grail, but the | 
					
						
							|  |  |  |     # Grail remote control protocol doesn't really allow that at this | 
					
						
							|  |  |  |     # point.  It probably neverwill! | 
					
						
							|  |  |  |     def _find_grail_rc(self): | 
					
						
							|  |  |  |         import glob | 
					
						
							|  |  |  |         import pwd | 
					
						
							|  |  |  |         import socket | 
					
						
							|  |  |  |         import tempfile | 
					
						
							|  |  |  |         tempdir = os.path.join(tempfile.gettempdir(), | 
					
						
							|  |  |  |                                ".grail-unix") | 
					
						
							| 
									
										
										
										
											2001-10-13 16:00:52 +00:00
										 |  |  |         user = pwd.getpwuid(os.getuid())[0] | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  |         filename = os.path.join(tempdir, user + "-*") | 
					
						
							|  |  |  |         maybes = glob.glob(filename) | 
					
						
							|  |  |  |         if not maybes: | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  |         s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | 
					
						
							|  |  |  |         for fn in maybes: | 
					
						
							|  |  |  |             # need to PING each one until we find one that's live | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 s.connect(fn) | 
					
						
							|  |  |  |             except socket.error: | 
					
						
							|  |  |  |                 # no good; attempt to clean it out, but don't fail: | 
					
						
							|  |  |  |                 try: | 
					
						
							|  |  |  |                     os.unlink(fn) | 
					
						
							|  |  |  |                 except IOError: | 
					
						
							|  |  |  |                     pass | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 return s | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _remote(self, action): | 
					
						
							|  |  |  |         s = self._find_grail_rc() | 
					
						
							|  |  |  |         if not s: | 
					
						
							|  |  |  |             return 0 | 
					
						
							|  |  |  |         s.send(action) | 
					
						
							|  |  |  |         s.close() | 
					
						
							|  |  |  |         return 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open(self, url, new=0, autoraise=1): | 
					
						
							|  |  |  |         if new: | 
					
						
							|  |  |  |             self._remote("LOADNEW " + url) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self._remote("LOAD " + url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open_new(self, url): | 
					
						
							|  |  |  |         self.open(url, 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WindowsDefault: | 
					
						
							|  |  |  |     def open(self, url, new=0, autoraise=1): | 
					
						
							|  |  |  |         os.startfile(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open_new(self, url): | 
					
						
							|  |  |  |         self.open(url) | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-09 20:06:00 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | # Platform support for Unix | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | # 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"): | 
					
						
							| 
									
										
										
										
											2002-11-25 17:25:04 +00:00
										 |  |  |     _tryorder = ["links", "lynx", "w3m"] | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # 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"): | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |             register("links", None, GenericBrowser("links '%s'")) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |         # The Lynx browser <http://lynx.browser.org/> | 
					
						
							|  |  |  |         if _iscommand("lynx"): | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |             register("lynx", None, GenericBrowser("lynx '%s'")) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |         # The w3m browser <http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/eng/> | 
					
						
							|  |  |  |         if _iscommand("w3m"): | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |             register("w3m", None, GenericBrowser("w3m '%s'")) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 02:01:40 +00:00
										 |  |  |     # X browsers have more in the way of options | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |     if os.environ.get("DISPLAY"): | 
					
						
							| 
									
										
										
										
											2004-07-10 22:07:02 +00:00
										 |  |  |         _tryorder = ["galeon", "skipstone", | 
					
						
							|  |  |  |                      "mozilla-firefox", "mozilla-firebird", "mozilla", "netscape", | 
					
						
							| 
									
										
										
										
											2002-11-25 17:25:04 +00:00
										 |  |  |                      "kfm", "grail"] + _tryorder | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |         # First, the Netscape series | 
					
						
							| 
									
										
										
										
											2004-07-10 22:07:02 +00:00
										 |  |  |         for browser in ("mozilla-firefox", "mozilla-firebird", | 
					
						
							|  |  |  |                         "mozilla", "netscape"): | 
					
						
							|  |  |  |             if _iscommand(browser): | 
					
						
							|  |  |  |                 register(browser, None, Netscape(browser)) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Next, Mosaic -- old but still in use. | 
					
						
							|  |  |  |         if _iscommand("mosaic"): | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |             register("mosaic", None, GenericBrowser( | 
					
						
							|  |  |  |                 "mosaic '%s' >/dev/null &")) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-10 22:49:29 +00:00
										 |  |  |         # Gnome's Galeon | 
					
						
							|  |  |  |         if _iscommand("galeon"): | 
					
						
							|  |  |  |             register("galeon", None, Galeon("galeon")) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 17:25:04 +00:00
										 |  |  |         # Skipstone, another Gtk/Mozilla based browser | 
					
						
							|  |  |  |         if _iscommand("skipstone"): | 
					
						
							|  |  |  |             register("skipstone", None, GenericBrowser( | 
					
						
							|  |  |  |                 "skipstone '%s' >/dev/null &")) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |         # Konqueror/kfm, the KDE browser. | 
					
						
							| 
									
										
										
										
											2001-03-26 15:06:15 +00:00
										 |  |  |         if _iscommand("kfm") or _iscommand("konqueror"): | 
					
						
							| 
									
										
										
										
											2001-04-12 22:07:27 +00:00
										 |  |  |             register("kfm", Konqueror, Konqueror()) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Grail, the Python browser. | 
					
						
							|  |  |  |         if _iscommand("grail"): | 
					
						
							|  |  |  |             register("grail", Grail, None) | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-19 03:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class InternetConfig: | 
					
						
							|  |  |  |     def open(self, url, new=0, autoraise=1): | 
					
						
							|  |  |  |         ic.launchurl(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def open_new(self, url): | 
					
						
							|  |  |  |         self.open(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # Platform support for Windows | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | if sys.platform[:3] == "win": | 
					
						
							| 
									
										
										
										
											2001-12-03 15:51:31 +00:00
										 |  |  |     _tryorder = ["netscape", "windows-default"] | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  |     register("windows-default", WindowsDefault) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | # Platform support for MacOS | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							|  |  |  |     import ic | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |     # internet-config is the only supported controller on MacOS, | 
					
						
							|  |  |  |     # so don't mess with the default! | 
					
						
							| 
									
										
										
										
											2001-12-03 15:51:31 +00:00
										 |  |  |     _tryorder = ["internet-config"] | 
					
						
							| 
									
										
										
										
											2000-07-09 16:45:56 +00:00
										 |  |  |     register("internet-config", InternetConfig) | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-25 14:35:58 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # Platform support for OS/2 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if sys.platform[:3] == "os2" and _iscommand("netscape.exe"): | 
					
						
							| 
									
										
										
										
											2001-12-03 15:51:31 +00:00
										 |  |  |     _tryorder = ["os2netscape"] | 
					
						
							| 
									
										
										
										
											2001-11-25 14:35:58 +00:00
										 |  |  |     register("os2netscape", None, | 
					
						
							|  |  |  |              GenericBrowser("start netscape.exe %s")) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  | # OK, now that we know what the default preference orders for each | 
					
						
							|  |  |  | # platform are, allow user to override them with the BROWSER variable. | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2002-06-01 14:18:47 +00:00
										 |  |  | if "BROWSER" in os.environ: | 
					
						
							| 
									
										
										
										
											2001-01-23 13:16:32 +00:00
										 |  |  |     # It's the user's responsibility to register handlers for any unknown | 
					
						
							|  |  |  |     # browser referenced by this value, before calling open(). | 
					
						
							| 
									
										
										
										
											2001-12-04 17:43:22 +00:00
										 |  |  |     _tryorder = os.environ["BROWSER"].split(os.pathsep) | 
					
						
							| 
									
										
										
										
											2001-07-18 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | for cmd in _tryorder: | 
					
						
							| 
									
										
										
										
											2002-06-01 14:18:47 +00:00
										 |  |  |     if not cmd.lower() in _browsers: | 
					
						
							| 
									
										
										
										
											2001-07-18 20:03:32 +00:00
										 |  |  |         if _iscommand(cmd.lower()): | 
					
						
							| 
									
										
										
										
											2002-01-07 15:29:01 +00:00
										 |  |  |             register(cmd.lower(), None, GenericBrowser( | 
					
						
							|  |  |  |                 "%s '%%s'" % cmd.lower())) | 
					
						
							| 
									
										
										
										
											2002-03-15 13:47:32 +00:00
										 |  |  | cmd = None # to make del work if _tryorder was empty | 
					
						
							| 
									
										
										
										
											2002-02-11 18:11:09 +00:00
										 |  |  | del cmd | 
					
						
							| 
									
										
										
										
											2001-07-18 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-01 14:18:47 +00:00
										 |  |  | _tryorder = filter(lambda x: x.lower() in _browsers | 
					
						
							| 
									
										
										
										
											2001-07-18 20:03:32 +00:00
										 |  |  |                    or x.find("%s") > -1, _tryorder) | 
					
						
							|  |  |  | # what to do if _tryorder is now empty? |