[Python-checkins] CVS: python/dist/src/Lib webbrowser.py,1.17,1.18

Fred L. Drake fdrake@users.sourceforge.net
Thu, 12 Apr 2001 15:07:29 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv28285

Modified Files:
	webbrowser.py 
Log Message:
_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.


Index: webbrowser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/webbrowser.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** webbrowser.py	2001/03/31 01:50:52	1.17
--- webbrowser.py	2001/04/12 22:07:27	1.18
***************
*** 28,32 ****
          else:
              # User gave us a browser name.
!             command = _browsers[browser.lower()]
              if command[1] is None:
                  return command[0]()
--- 28,35 ----
          else:
              # User gave us a browser name.
!             try:
!                 command = _browsers[browser.lower()]
!             except KeyError:
!                 command = _synthesize(browser)
              if command[1] is None:
                  return command[0]()
***************
*** 43,46 ****
--- 46,80 ----
      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,
***************
*** 75,82 ****
      class GenericBrowser:
          def __init__(self, cmd):
!             self.command = cmd
  
          def open(self, url, new=0, autoraise=1):
!             os.system(self.command % url)
  
          def open_new(self, url):        # Deprecated.  May be removed in 2.1.
--- 109,118 ----
      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):
!             command = "%s %s" % (self.name, self.args)
!             os.system(command % url)
  
          def open_new(self, url):        # Deprecated.  May be removed in 2.1.
***************
*** 103,106 ****
--- 139,143 ----
                  def __init__(self, name):
                      self.name = name
+                     self.basename = os.path.basename(name)
  
                  def _remote(self, action, autoraise):
***************
*** 145,148 ****
--- 182,191 ----
  
                  """
+                 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
***************
*** 150,157 ****
                      if rc:
                          import time
!                         if _iscommand("konqueror"):
!                             os.system("konqueror --silent &")
                          else:
!                             os.system("kfm -d &")
                          time.sleep(PROCESS_CREATION_DELAY)
                          rc = os.system(cmd)
--- 193,200 ----
                      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)
***************
*** 166,170 ****
                  open_new = open
  
!             register("kfm", Konqueror, None)
  
          # Grail, the Python browser.
--- 209,213 ----
                  open_new = open
  
!             register("kfm", Konqueror, Konqueror())
  
          # Grail, the Python browser.