From 9d6603ff3f249f6e5e201c35dc62f1f5418a3861 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 23 May 2023 22:20:30 +0300 Subject: [PATCH 1/6] Remove webbrowser.MacOSX class, deprecated in Python 3.11 --- Doc/library/webbrowser.rst | 3 -- Doc/whatsnew/3.13.rst | 3 ++ Lib/webbrowser.py | 52 +------------------ Misc/NEWS.d/3.11.0a1.rst | 2 +- ...-05-23-21-25-54.gh-issue-104804.78fiE6.rst | 2 + 5 files changed, 7 insertions(+), 55 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst index 61db8042093627..da1ab6a84bd712 100644 --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -171,9 +171,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/' diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index e0c3c2a3592ec7..cb0aa97d003d67 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -115,6 +115,9 @@ Removed are now removed. The items in those namespaces can be imported directly from :mod:`typing`. (Contributed by Sebastian Rittau in :gh:`92871`.) +* Remove :class:`!webbrowser.MacOSX` class, deprecated in Python 3.11. + (Contributed by Hugo van Kemenade in :gh:`104804`.) + Porting to Python 3.13 ====================== diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py index b86d131f030d80..c1bd667a56e579 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 10e123e325c863..2552d1e053422a 100644 --- a/Misc/NEWS.d/3.11.0a1.rst +++ b/Misc/NEWS.d/3.11.0a1.rst @@ -1966,7 +1966,7 @@ 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. +: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. 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 00000000000000..53a316682164e8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst @@ -0,0 +1,2 @@ +Remove :class:`!webbrowser.MacOSX` class, deprecated in Python 3.11. +Patch by Hugo van Kemenade. From 58edef7bba2a95f70b0e135a01c8c6dd748e01cd Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 23 May 2023 22:23:06 +0300 Subject: [PATCH 2/6] Fix Sphinx warnings --- Doc/library/webbrowser.rst | 44 +++++++++++++++++++------------------- Doc/tools/.nitignore | 1 - 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst index da1ab6a84bd712..addec0220c643f 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. @@ -219,4 +219,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 7a711031d74e9a..179eed306385d2 100644 --- a/Doc/tools/.nitignore +++ b/Doc/tools/.nitignore @@ -236,7 +236,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 From 863db434b369c98e0f365c31c9193e365a7b4bdc Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 24 May 2023 00:03:50 -0600 Subject: [PATCH 3/6] Update docs Co-authored-by: C.A.M. Gerlach --- Doc/whatsnew/3.13.rst | 4 +++- Misc/NEWS.d/3.11.0a1.rst | 2 +- .../Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index cb0aa97d003d67..88b8c4e0b6f4c7 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -115,7 +115,9 @@ Removed are now removed. The items in those namespaces can be imported directly from :mod:`typing`. (Contributed by Sebastian Rittau in :gh:`92871`.) -* Remove :class:`!webbrowser.MacOSX` class, deprecated in Python 3.11. +* 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`.) Porting to Python 3.13 diff --git a/Misc/NEWS.d/3.11.0a1.rst b/Misc/NEWS.d/3.11.0a1.rst index 2552d1e053422a..dc12e9a920e8fc 100644 --- a/Misc/NEWS.d/3.11.0a1.rst +++ b/Misc/NEWS.d/3.11.0a1.rst @@ -1967,7 +1967,7 @@ A new function ``operator.call`` has been added, such that .. 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. +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 index 53a316682164e8..b1ff0b2ccefb8e 100644 --- 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 @@ -1,2 +1,2 @@ -Remove :class:`!webbrowser.MacOSX` class, deprecated in Python 3.11. +Remove the :module:`webbrowser` :class:`!webbrowser` class, deprecated in Python 3.11. Patch by Hugo van Kemenade. From 83253758aa1653815c6507b313c655b7138926b9 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 24 May 2023 09:08:59 +0300 Subject: [PATCH 4/6] Add MacOSXOSAScript as 'versionadded:: 3.2' --- Doc/library/webbrowser.rst | 5 +++++ .../Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst index addec0220c643f..2f0b5feb8cbc75 100644 --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -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. 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 index b1ff0b2ccefb8e..cced6050859e89 100644 --- 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 @@ -1,2 +1,2 @@ -Remove the :module:`webbrowser` :class:`!webbrowser` class, deprecated in Python 3.11. +Remove the :mod:`webbrowser` :class:`!webbrowser` class, deprecated in Python 3.11. Patch by Hugo van Kemenade. From ffb2e449d4b17a48acab8aa090891748efcb76b1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 24 May 2023 09:12:04 +0300 Subject: [PATCH 5/6] Fix typo --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 0199d467ef5983..8e7567b3763fb3 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -115,7 +115,7 @@ 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, +* 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`.) From 4333217d7fc1c64b80dbde25542de0e015b1f020 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 25 May 2023 19:10:21 +0300 Subject: [PATCH 6/6] Fix typo Co-authored-by: Victor Stinner --- .../next/Library/2023-05-23-21-25-54.gh-issue-104804.78fiE6.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index cced6050859e89..78409cf7cbc9dd 100644 --- 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 @@ -1,2 +1,2 @@ -Remove the :mod:`webbrowser` :class:`!webbrowser` class, deprecated in Python 3.11. +Remove the untested and undocumented :mod:`webbrowser` :class:`!MacOSX` class, deprecated in Python 3.11. Patch by Hugo van Kemenade.