Skip to content

Commit 5ab4bc0

Browse files
hugovkCAM-Gerlachvstinner
authored
gh-104804: Remove webbrowser.MacOSX class, deprecated in Python 3.11 (#104816)
Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
1 parent afa759f commit 5ab4bc0

File tree

6 files changed

+37
-79
lines changed

6 files changed

+37
-79
lines changed

Doc/library/webbrowser.rst

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ will be used if graphical browsers are not available or an X11 display isn't
2020
available. If text-mode browsers are used, the calling process will block until
2121
the user exits the browser.
2222

23-
If the environment variable :envvar:`BROWSER` exists, it is interpreted as the
23+
If the environment variable :envvar:`!BROWSER` exists, it is interpreted as the
2424
:data:`os.pathsep`-separated list of browsers to try ahead of the platform
2525
defaults. When the value of a list part contains the string ``%s``, then it is
2626
interpreted as a literal browser command line to be used with the argument URL
@@ -97,7 +97,7 @@ The following functions are defined:
9797

9898
Setting *preferred* to ``True`` makes this browser a preferred result for
9999
a :func:`get` call with no argument. Otherwise, this entry point is only
100-
useful if you plan to either set the :envvar:`BROWSER` variable or call
100+
useful if you plan to either set the :envvar:`!BROWSER` variable or call
101101
:func:`get` with a nonempty argument matching the name of a handler you
102102
declare.
103103

@@ -111,49 +111,49 @@ for the controller classes, all defined in this module.
111111
+------------------------+-----------------------------------------+-------+
112112
| Type Name | Class Name | Notes |
113113
+========================+=========================================+=======+
114-
| ``'mozilla'`` | :class:`Mozilla('mozilla')` | |
114+
| ``'mozilla'`` | ``Mozilla('mozilla')`` | |
115115
+------------------------+-----------------------------------------+-------+
116-
| ``'firefox'`` | :class:`Mozilla('mozilla')` | |
116+
| ``'firefox'`` | ``Mozilla('mozilla')`` | |
117117
+------------------------+-----------------------------------------+-------+
118-
| ``'epiphany'`` | :class:`Epiphany('epiphany')` | |
118+
| ``'epiphany'`` | ``Epiphany('epiphany')`` | |
119119
+------------------------+-----------------------------------------+-------+
120-
| ``'kfmclient'`` | :class:`Konqueror()` | \(1) |
120+
| ``'kfmclient'`` | ``Konqueror()`` | \(1) |
121121
+------------------------+-----------------------------------------+-------+
122-
| ``'konqueror'`` | :class:`Konqueror()` | \(1) |
122+
| ``'konqueror'`` | ``Konqueror()`` | \(1) |
123123
+------------------------+-----------------------------------------+-------+
124-
| ``'kfm'`` | :class:`Konqueror()` | \(1) |
124+
| ``'kfm'`` | ``Konqueror()`` | \(1) |
125125
+------------------------+-----------------------------------------+-------+
126-
| ``'opera'`` | :class:`Opera()` | |
126+
| ``'opera'`` | ``Opera()`` | |
127127
+------------------------+-----------------------------------------+-------+
128-
| ``'links'`` | :class:`GenericBrowser('links')` | |
128+
| ``'links'`` | ``GenericBrowser('links')`` | |
129129
+------------------------+-----------------------------------------+-------+
130-
| ``'elinks'`` | :class:`Elinks('elinks')` | |
130+
| ``'elinks'`` | ``Elinks('elinks')`` | |
131131
+------------------------+-----------------------------------------+-------+
132-
| ``'lynx'`` | :class:`GenericBrowser('lynx')` | |
132+
| ``'lynx'`` | ``GenericBrowser('lynx')`` | |
133133
+------------------------+-----------------------------------------+-------+
134-
| ``'w3m'`` | :class:`GenericBrowser('w3m')` | |
134+
| ``'w3m'`` | ``GenericBrowser('w3m')`` | |
135135
+------------------------+-----------------------------------------+-------+
136-
| ``'windows-default'`` | :class:`WindowsDefault` | \(2) |
136+
| ``'windows-default'`` | ``WindowsDefault`` | \(2) |
137137
+------------------------+-----------------------------------------+-------+
138-
| ``'macosx'`` | :class:`MacOSXOSAScript('default')` | \(3) |
138+
| ``'macosx'`` | ``MacOSXOSAScript('default')`` | \(3) |
139139
+------------------------+-----------------------------------------+-------+
140-
| ``'safari'`` | :class:`MacOSXOSAScript('safari')` | \(3) |
140+
| ``'safari'`` | ``MacOSXOSAScript('safari')`` | \(3) |
141141
+------------------------+-----------------------------------------+-------+
142-
| ``'google-chrome'`` | :class:`Chrome('google-chrome')` | |
142+
| ``'google-chrome'`` | ``Chrome('google-chrome')`` | |
143143
+------------------------+-----------------------------------------+-------+
144-
| ``'chrome'`` | :class:`Chrome('chrome')` | |
144+
| ``'chrome'`` | ``Chrome('chrome')`` | |
145145
+------------------------+-----------------------------------------+-------+
146-
| ``'chromium'`` | :class:`Chromium('chromium')` | |
146+
| ``'chromium'`` | ``Chromium('chromium')`` | |
147147
+------------------------+-----------------------------------------+-------+
148-
| ``'chromium-browser'`` | :class:`Chromium('chromium-browser')` | |
148+
| ``'chromium-browser'`` | ``Chromium('chromium-browser')`` | |
149149
+------------------------+-----------------------------------------+-------+
150150

151151
Notes:
152152

153153
(1)
154154
"Konqueror" is the file manager for the KDE desktop environment for Unix, and
155155
only makes sense to use if KDE is running. Some way of reliably detecting KDE
156-
would be nice; the :envvar:`KDEDIR` variable is not sufficient. Note also that
156+
would be nice; the :envvar:`!KDEDIR` variable is not sufficient. Note also that
157157
the name "kfm" is used even when using the :program:`konqueror` command with KDE
158158
2 --- the implementation selects the best strategy for running Konqueror.
159159

@@ -163,6 +163,11 @@ Notes:
163163
(3)
164164
Only on macOS platform.
165165

166+
.. versionadded:: 3.2
167+
A new :class:`!MacOSXOSAScript` class has been added
168+
and is used on Mac instead of the previous :class:`!MacOSX` class.
169+
This adds support for opening browsers not currently set as the OS default.
170+
166171
.. versionadded:: 3.3
167172
Support for Chrome/Chromium has been added.
168173

@@ -171,9 +176,6 @@ Notes:
171176
Removed browsers include Grail, Mosaic, Netscape, Galeon,
172177
Skipstone, Iceape, and Firefox versions 35 and below.
173178

174-
.. deprecated-removed:: 3.11 3.13
175-
:class:`MacOSX` is deprecated, use :class:`MacOSXOSAScript` instead.
176-
177179
Here are some simple examples::
178180

179181
url = 'https://docs.python.org/'
@@ -222,4 +224,4 @@ module-level convenience functions:
222224
.. rubric:: Footnotes
223225

224226
.. [1] Executables named here without a full path will be searched in the
225-
directories given in the :envvar:`PATH` environment variable.
227+
directories given in the :envvar:`!PATH` environment variable.

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ Doc/library/urllib.request.rst
229229
Doc/library/uuid.rst
230230
Doc/library/wave.rst
231231
Doc/library/weakref.rst
232-
Doc/library/webbrowser.rst
233232
Doc/library/winreg.rst
234233
Doc/library/winsound.rst
235234
Doc/library/wsgiref.rst

Doc/whatsnew/3.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Removed
115115
are now removed. The items in those namespaces can be imported directly
116116
from :mod:`typing`. (Contributed by Sebastian Rittau in :gh:`92871`.)
117117

118+
* Remove the untested and undocumented :mod:`webbrowser` :class:`!MacOSX` class,
119+
deprecated in Python 3.11.
120+
Use the :class:`!MacOSXOSAScript` class (introduced in Python 3.2) instead.
121+
(Contributed by Hugo van Kemenade in :gh:`104804`.)
122+
118123
* Remove support for using :class:`pathlib.Path` objects as context managers.
119124
This functionality was deprecated and made a no-op in Python 3.9.
120125

Lib/webbrowser.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -570,60 +570,10 @@ def open(self, url, new=0, autoraise=True):
570570
return True
571571

572572
#
573-
# Platform support for MacOS
573+
# Platform support for macOS
574574
#
575575

576576
if sys.platform == 'darwin':
577-
# Adapted from patch submitted to SourceForge by Steven J. Burr
578-
class MacOSX(BaseBrowser):
579-
"""Launcher class for Aqua browsers on Mac OS X
580-
581-
Optionally specify a browser name on instantiation. Note that this
582-
will not work for Aqua browsers if the user has moved the application
583-
package after installation.
584-
585-
If no browser is specified, the default browser, as specified in the
586-
Internet System Preferences panel, will be used.
587-
"""
588-
def __init__(self, name):
589-
warnings.warn(f'{self.__class__.__name__} is deprecated in 3.11'
590-
' use MacOSXOSAScript instead.', DeprecationWarning, stacklevel=2)
591-
self.name = name
592-
593-
def open(self, url, new=0, autoraise=True):
594-
sys.audit("webbrowser.open", url)
595-
assert "'" not in url
596-
# hack for local urls
597-
if not ':' in url:
598-
url = 'file:'+url
599-
600-
# new must be 0 or 1
601-
new = int(bool(new))
602-
if self.name == "default":
603-
# User called open, open_new or get without a browser parameter
604-
script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
605-
else:
606-
# User called get and chose a browser
607-
if self.name == "OmniWeb":
608-
toWindow = ""
609-
else:
610-
# Include toWindow parameter of OpenURL command for browsers
611-
# that support it. 0 == new window; -1 == existing
612-
toWindow = "toWindow %d" % (new - 1)
613-
cmd = 'OpenURL "%s"' % url.replace('"', '%22')
614-
script = '''tell application "%s"
615-
activate
616-
%s %s
617-
end tell''' % (self.name, cmd, toWindow)
618-
# Open pipe to AppleScript through osascript command
619-
osapipe = os.popen("osascript", "w")
620-
if osapipe is None:
621-
return False
622-
# Write script to osascript's stdin
623-
osapipe.write(script)
624-
rc = osapipe.close()
625-
return not rc
626-
627577
class MacOSXOSAScript(BaseBrowser):
628578
def __init__(self, name='default'):
629579
super().__init__(name)

Misc/NEWS.d/3.11.0a1.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,8 +1966,8 @@ A new function ``operator.call`` has been added, such that
19661966
.. nonce: ofe3ms
19671967
.. section: Library
19681968
1969-
:class:`webbrowser.MacOSX` is deprecated and will be removed in Python 3.13.
1970-
It is untested and undocumented and also not used by webbrowser itself.
1969+
:class:`!webbrowser.MacOSX` is deprecated and will be removed in Python 3.13.
1970+
It is untested and undocumented and also not used by :mod:`webbrowser` itself.
19711971
Patch by Dong-hee Na.
19721972

19731973
..
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove the untested and undocumented :mod:`webbrowser` :class:`!MacOSX` class, deprecated in Python 3.11.
2+
Patch by Hugo van Kemenade.

0 commit comments

Comments
 (0)