[Python-checkins] gh-104804: Remove webbrowser.MacOSX class, deprecated in Python 3.11 (#104816)

hugovk webhook-mailer at python.org
Fri May 26 09:54:23 EDT 2023


https://github.com/python/cpython/commit/5ab4bc05c459f25c9d1dcb9b20f10bbd7e6eae5e
commit: 5ab4bc05c459f25c9d1dcb9b20f10bbd7e6eae5e
branch: main
author: Hugo van Kemenade <hugovk at users.noreply.github.com>
committer: hugovk <hugovk at users.noreply.github.com>
date: 2023-05-26T16:54:15+03:00
summary:

gh-104804: Remove webbrowser.MacOSX class, deprecated in Python 3.11 (#104816)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach at Gerlach.CAM>
Co-authored-by: Victor Stinner <vstinner at python.org>

files:
A Misc/NEWS.d/next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst
M Doc/library/webbrowser.rst
M Doc/tools/.nitignore
M Doc/whatsnew/3.13.rst
M Lib/webbrowser.py
M Misc/NEWS.d/3.11.0a1.rst

diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst
index 61db80420936..2f0b5feb8cbc 100644
--- a/Doc/library/webbrowser.rst
+++ b/Doc/library/webbrowser.rst
@@ -20,7 +20,7 @@ will be used if graphical browsers are not available or an X11 display isn't
 available.  If text-mode browsers are used, the calling process will block until
 the user exits the browser.
 
-If the environment variable :envvar:`BROWSER` exists, it is interpreted as the
+If the environment variable :envvar:`!BROWSER` exists, it is interpreted as the
 :data:`os.pathsep`-separated list of browsers to try ahead of the platform
 defaults.  When the value of a list part contains the string ``%s``, then it is
 interpreted as a literal browser command line to be used with the argument URL
@@ -97,7 +97,7 @@ The following functions are defined:
 
    Setting *preferred* to ``True`` makes this browser a preferred result for
    a :func:`get` call with no argument.  Otherwise, this entry point is only
-   useful if you plan to either set the :envvar:`BROWSER` variable or call
+   useful if you plan to either set the :envvar:`!BROWSER` variable or call
    :func:`get` with a nonempty argument matching the name of a handler you
    declare.
 
@@ -111,41 +111,41 @@ for the controller classes, all defined in this module.
 +------------------------+-----------------------------------------+-------+
 | Type Name              | Class Name                              | Notes |
 +========================+=========================================+=======+
-| ``'mozilla'``          | :class:`Mozilla('mozilla')`             |       |
+| ``'mozilla'``          | ``Mozilla('mozilla')``                  |       |
 +------------------------+-----------------------------------------+-------+
-| ``'firefox'``          | :class:`Mozilla('mozilla')`             |       |
+| ``'firefox'``          | ``Mozilla('mozilla')``                  |       |
 +------------------------+-----------------------------------------+-------+
-| ``'epiphany'``         | :class:`Epiphany('epiphany')`           |       |
+| ``'epiphany'``         | ``Epiphany('epiphany')``                |       |
 +------------------------+-----------------------------------------+-------+
-| ``'kfmclient'``        | :class:`Konqueror()`                    | \(1)  |
+| ``'kfmclient'``        | ``Konqueror()``                         | \(1)  |
 +------------------------+-----------------------------------------+-------+
-| ``'konqueror'``        | :class:`Konqueror()`                    | \(1)  |
+| ``'konqueror'``        | ``Konqueror()``                         | \(1)  |
 +------------------------+-----------------------------------------+-------+
-| ``'kfm'``              | :class:`Konqueror()`                    | \(1)  |
+| ``'kfm'``              | ``Konqueror()``                         | \(1)  |
 +------------------------+-----------------------------------------+-------+
-| ``'opera'``            | :class:`Opera()`                        |       |
+| ``'opera'``            | ``Opera()``                             |       |
 +------------------------+-----------------------------------------+-------+
-| ``'links'``            | :class:`GenericBrowser('links')`        |       |
+| ``'links'``            | ``GenericBrowser('links')``             |       |
 +------------------------+-----------------------------------------+-------+
-| ``'elinks'``           | :class:`Elinks('elinks')`               |       |
+| ``'elinks'``           | ``Elinks('elinks')``                    |       |
 +------------------------+-----------------------------------------+-------+
-| ``'lynx'``             | :class:`GenericBrowser('lynx')`         |       |
+| ``'lynx'``             | ``GenericBrowser('lynx')``              |       |
 +------------------------+-----------------------------------------+-------+
-| ``'w3m'``              | :class:`GenericBrowser('w3m')`          |       |
+| ``'w3m'``              | ``GenericBrowser('w3m')``               |       |
 +------------------------+-----------------------------------------+-------+
-| ``'windows-default'``  | :class:`WindowsDefault`                 | \(2)  |
+| ``'windows-default'``  | ``WindowsDefault``                      | \(2)  |
 +------------------------+-----------------------------------------+-------+
-| ``'macosx'``           | :class:`MacOSXOSAScript('default')`     | \(3)  |
+| ``'macosx'``           | ``MacOSXOSAScript('default')``          | \(3)  |
 +------------------------+-----------------------------------------+-------+
-| ``'safari'``           | :class:`MacOSXOSAScript('safari')`      | \(3)  |
+| ``'safari'``           | ``MacOSXOSAScript('safari')``           | \(3)  |
 +------------------------+-----------------------------------------+-------+
-| ``'google-chrome'``    | :class:`Chrome('google-chrome')`        |       |
+| ``'google-chrome'``    | ``Chrome('google-chrome')``             |       |
 +------------------------+-----------------------------------------+-------+
-| ``'chrome'``           | :class:`Chrome('chrome')`               |       |
+| ``'chrome'``           | ``Chrome('chrome')``                    |       |
 +------------------------+-----------------------------------------+-------+
-| ``'chromium'``         | :class:`Chromium('chromium')`           |       |
+| ``'chromium'``         | ``Chromium('chromium')``                |       |
 +------------------------+-----------------------------------------+-------+
-| ``'chromium-browser'`` | :class:`Chromium('chromium-browser')`   |       |
+| ``'chromium-browser'`` | ``Chromium('chromium-browser')``        |       |
 +------------------------+-----------------------------------------+-------+
 
 Notes:
@@ -153,7 +153,7 @@ Notes:
 (1)
    "Konqueror" is the file manager for the KDE desktop environment for Unix, and
    only makes sense to use if KDE is running.  Some way of reliably detecting KDE
-   would be nice; the :envvar:`KDEDIR` variable is not sufficient.  Note also that
+   would be nice; the :envvar:`!KDEDIR` variable is not sufficient.  Note also that
    the name "kfm" is used even when using the :program:`konqueror` command with KDE
    2 --- the implementation selects the best strategy for running Konqueror.
 
@@ -163,6 +163,11 @@ Notes:
 (3)
    Only on macOS platform.
 
+.. versionadded:: 3.2
+   A new :class:`!MacOSXOSAScript` class has been added
+   and is used on Mac instead of the previous :class:`!MacOSX` class.
+   This adds support for opening browsers not currently set as the OS default.
+
 .. versionadded:: 3.3
    Support for Chrome/Chromium has been added.
 
@@ -171,9 +176,6 @@ Notes:
    Removed browsers include Grail, Mosaic, Netscape, Galeon,
    Skipstone, Iceape, and Firefox versions 35 and below.
 
-.. deprecated-removed:: 3.11 3.13
-   :class:`MacOSX` is deprecated, use :class:`MacOSXOSAScript` instead.
-
 Here are some simple examples::
 
    url = 'https://docs.python.org/'
@@ -222,4 +224,4 @@ module-level convenience functions:
 .. rubric:: Footnotes
 
 .. [1] Executables named here without a full path will be searched in the
-       directories given in the :envvar:`PATH` environment variable.
+       directories given in the :envvar:`!PATH` environment variable.
diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index fb2969028f08..261702649156 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -229,7 +229,6 @@ Doc/library/urllib.request.rst
 Doc/library/uuid.rst
 Doc/library/wave.rst
 Doc/library/weakref.rst
-Doc/library/webbrowser.rst
 Doc/library/winreg.rst
 Doc/library/winsound.rst
 Doc/library/wsgiref.rst
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index 28c98554fdbf..6e8f02b0aba9 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -115,6 +115,11 @@ Removed
   are now removed. The items in those namespaces can be imported directly
   from :mod:`typing`. (Contributed by Sebastian Rittau in :gh:`92871`.)
 
+* Remove the untested and undocumented :mod:`webbrowser` :class:`!MacOSX` class,
+  deprecated in Python 3.11.
+  Use the :class:`!MacOSXOSAScript` class (introduced in Python 3.2) instead.
+  (Contributed by Hugo van Kemenade in :gh:`104804`.)
+
 * Remove support for using :class:`pathlib.Path` objects as context managers.
   This functionality was deprecated and made a no-op in Python 3.9.
 
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index b86d131f030d..c1bd667a56e5 100755
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -570,60 +570,10 @@ def open(self, url, new=0, autoraise=True):
                 return True
 
 #
-# Platform support for MacOS
+# Platform support for macOS
 #
 
 if sys.platform == 'darwin':
-    # Adapted from patch submitted to SourceForge by Steven J. Burr
-    class MacOSX(BaseBrowser):
-        """Launcher class for Aqua browsers on Mac OS X
-
-        Optionally specify a browser name on instantiation.  Note that this
-        will not work for Aqua browsers if the user has moved the application
-        package after installation.
-
-        If no browser is specified, the default browser, as specified in the
-        Internet System Preferences panel, will be used.
-        """
-        def __init__(self, name):
-            warnings.warn(f'{self.__class__.__name__} is deprecated in 3.11'
-                          ' use MacOSXOSAScript instead.', DeprecationWarning, stacklevel=2)
-            self.name = name
-
-        def open(self, url, new=0, autoraise=True):
-            sys.audit("webbrowser.open", url)
-            assert "'" not in url
-            # hack for local urls
-            if not ':' in url:
-                url = 'file:'+url
-
-            # new must be 0 or 1
-            new = int(bool(new))
-            if self.name == "default":
-                # User called open, open_new or get without a browser parameter
-                script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
-            else:
-                # User called get and chose a browser
-                if self.name == "OmniWeb":
-                    toWindow = ""
-                else:
-                    # Include toWindow parameter of OpenURL command for browsers
-                    # that support it.  0 == new window; -1 == existing
-                    toWindow = "toWindow %d" % (new - 1)
-                cmd = 'OpenURL "%s"' % url.replace('"', '%22')
-                script = '''tell application "%s"
-                                activate
-                                %s %s
-                            end tell''' % (self.name, cmd, toWindow)
-            # Open pipe to AppleScript through osascript command
-            osapipe = os.popen("osascript", "w")
-            if osapipe is None:
-                return False
-            # Write script to osascript's stdin
-            osapipe.write(script)
-            rc = osapipe.close()
-            return not rc
-
     class MacOSXOSAScript(BaseBrowser):
         def __init__(self, name='default'):
             super().__init__(name)
diff --git a/Misc/NEWS.d/3.11.0a1.rst b/Misc/NEWS.d/3.11.0a1.rst
index 284717a8764b..ea96206b710a 100644
--- a/Misc/NEWS.d/3.11.0a1.rst
+++ b/Misc/NEWS.d/3.11.0a1.rst
@@ -1966,8 +1966,8 @@ A new function ``operator.call`` has been added, such that
 .. nonce: ofe3ms
 .. section: Library
 
-:class:`webbrowser.MacOSX` is deprecated and will be removed in Python 3.13.
-It is untested and undocumented and also not used by webbrowser itself.
+:class:`!webbrowser.MacOSX` is deprecated and will be removed in Python 3.13.
+It is untested and undocumented and also not used by :mod:`webbrowser` itself.
 Patch by Dong-hee Na.
 
 ..
diff --git a/Misc/NEWS.d/next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst b/Misc/NEWS.d/next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst
new file mode 100644
index 000000000000..78409cf7cbc9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst
@@ -0,0 +1,2 @@
+Remove the untested and undocumented :mod:`webbrowser` :class:`!MacOSX` class, deprecated in Python 3.11.
+Patch by Hugo van Kemenade.



More information about the Python-checkins mailing list