]> granicus.if.org Git - python/commitdiff
For for issue #7192: with this patch webbrowser.get("firefox")
authorRonald Oussoren <ronaldoussoren@mac.com>
Sun, 2 May 2010 09:48:21 +0000 (09:48 +0000)
committerRonald Oussoren <ronaldoussoren@mac.com>
Sun, 2 May 2010 09:48:21 +0000 (09:48 +0000)
works on OSX

Lib/webbrowser.py
Misc/NEWS

index 01922f41723e9cc13e23aed8ceddc1fa960c380f..45e0b54ac26611ba1f4f4fe4e73ecbdda175e982 100644 (file)
@@ -599,9 +599,35 @@ if sys.platform == 'darwin':
             rc = osapipe.close()
             return not rc
 
+    class MacOSXOSAScript(BaseBrowser):
+        def __init__(self, name):
+            self._name = name
+
+        def open(self, url, new=0, autoraise=True):
+            if self._name == 'default':
+                script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
+            else:
+                script = '''
+                   tell application "%s"
+                       activate
+                       open location "%s"
+                   end
+                   '''%(self._name, url.replace('"', '%22'))
+
+            osapipe = os.popen("osascript", "w")
+            if osapipe is None:
+                return False
+
+            osapipe.write(script)
+            rc = osapipe.close()
+            return not rc
+
+
     # Don't clear _tryorder or _browsers since OS X can use above Unix support
     # (but we prefer using the OS X specific stuff)
-    register("MacOSX", None, MacOSX('default'), -1)
+    register("MacOSX", None, MacOSXOSAScript('default'), -1)
+    register("safari", None, MacOSXOSAScript('safari'), -1)
+    register("firefox", None, MacOSXOSAScript('firefox'), -1)
 
 
 #
index 355654b3ef03020c1916ddc09d892e52822c0134..c75f95c90b866c0f0ca21a42563ede88c1ff6865 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #7192: webbrowser.get("firefox") now wors on Mac OS X, as does
+  webbrowser.get("safari").
+
 - Issue #8577: distutils.sysconfig.get_python_inc() now makes a difference 
   between the build dir and the source dir when looking for "python.h" or
   "Include".