Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions Doc/library/webbrowser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -111,49 +111,49 @@ 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:

(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.

Expand All @@ -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.

Expand All @@ -171,9 +176,6 @@ Notes:
Removed browsers include Grail, Mosaic, Netscape, Galeon,
hugovk marked this conversation as resolved.
Show resolved Hide resolved
Skipstone, Iceape, and Firefox versions 35 and below.

hugovk marked this conversation as resolved.
Show resolved Hide resolved
.. deprecated-removed:: 3.11 3.13
:class:`MacOSX` is deprecated, use :class:`MacOSXOSAScript` instead.

Here are some simple examples::

url = 'https://docs.python.org/'
Expand Down Expand Up @@ -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.
1 change: 0 additions & 1 deletion Doc/tools/.nitignore
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,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
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
52 changes: 1 addition & 51 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Misc/NEWS.d/3.11.0a1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

..
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove the untested and undocumented :mod:`webbrowser` :class:`!MacOSX` class, deprecated in Python 3.11.
Patch by Hugo van Kemenade.