Skip to content

Commit 9f82b97

Browse files
committed
gh-125231 register firefox channels as Mozilla controller
1 parent 12a20da commit 9f82b97

4 files changed

Lines changed: 46 additions & 10 deletions

File tree

Doc/library/webbrowser.rst

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,15 @@ for the controller classes, all defined in this module.
152152
+------------------------+-----------------------------------------+-------+
153153
| ``'firefox'`` | ``Mozilla('mozilla')`` | |
154154
+------------------------+-----------------------------------------+-------+
155+
| ``'firefox-*'`` | ``Mozilla('mozilla')`` | \(1) |
156+
+------------------------+-----------------------------------------+-------+
155157
| ``'epiphany'`` | ``Epiphany('epiphany')`` | |
156158
+------------------------+-----------------------------------------+-------+
157-
| ``'kfmclient'`` | ``Konqueror()`` | \(1) |
159+
| ``'kfmclient'`` | ``Konqueror()`` | \(2) |
158160
+------------------------+-----------------------------------------+-------+
159-
| ``'konqueror'`` | ``Konqueror()`` | \(1) |
161+
| ``'konqueror'`` | ``Konqueror()`` | \(2) |
160162
+------------------------+-----------------------------------------+-------+
161-
| ``'kfm'`` | ``Konqueror()`` | \(1) |
163+
| ``'kfm'`` | ``Konqueror()`` | \(2) |
162164
+------------------------+-----------------------------------------+-------+
163165
| ``'opera'`` | ``Opera()`` | |
164166
+------------------------+-----------------------------------------+-------+
@@ -170,11 +172,11 @@ for the controller classes, all defined in this module.
170172
+------------------------+-----------------------------------------+-------+
171173
| ``'w3m'`` | ``GenericBrowser('w3m')`` | |
172174
+------------------------+-----------------------------------------+-------+
173-
| ``'windows-default'`` | ``WindowsDefault`` | \(2) |
175+
| ``'windows-default'`` | ``WindowsDefault`` | \(3) |
174176
+------------------------+-----------------------------------------+-------+
175-
| ``'macosx'`` | ``MacOSXOSAScript('default')`` | \(3) |
177+
| ``'macosx'`` | ``MacOSXOSAScript('default')`` | \(4) |
176178
+------------------------+-----------------------------------------+-------+
177-
| ``'safari'`` | ``MacOSXOSAScript('safari')`` | \(3) |
179+
| ``'safari'`` | ``MacOSXOSAScript('safari')`` | \(4) |
178180
+------------------------+-----------------------------------------+-------+
179181
| ``'google-chrome'`` | ``Chrome('google-chrome')`` | |
180182
+------------------------+-----------------------------------------+-------+
@@ -184,25 +186,30 @@ for the controller classes, all defined in this module.
184186
+------------------------+-----------------------------------------+-------+
185187
| ``'chromium-browser'`` | ``Chromium('chromium-browser')`` | |
186188
+------------------------+-----------------------------------------+-------+
187-
| ``'iosbrowser'`` | ``IOSBrowser`` | \(4) |
189+
| ``'iosbrowser'`` | ``IOSBrowser`` | \(5) |
188190
+------------------------+-----------------------------------------+-------+
189191

192+
190193
Notes:
191194

192195
(1)
196+
firefox-* are Firefox channels, such as firefox-dev, firefox-aurora,
197+
firefox-beta, firefox-nightly, etc.
198+
199+
(2)
193200
"Konqueror" is the file manager for the KDE desktop environment for Unix, and
194201
only makes sense to use if KDE is running. Some way of reliably detecting KDE
195202
would be nice; the :envvar:`!KDEDIR` variable is not sufficient. Note also that
196203
the name "kfm" is used even when using the :program:`konqueror` command with KDE
197204
2 --- the implementation selects the best strategy for running Konqueror.
198205

199-
(2)
206+
(3)
200207
Only on Windows platforms.
201208

202-
(3)
209+
(4)
203210
Only on macOS.
204211

205-
(4)
212+
(5)
206213
Only on iOS.
207214

208215
.. versionadded:: 3.2
@@ -221,6 +228,11 @@ Notes:
221228
.. versionchanged:: 3.13
222229
Support for iOS has been added.
223230

231+
.. versionchanged:: 3.15
232+
Support for firefox-* has been added, which includes Firefox
233+
channels such as firefox-dev, firefox-aurora, firefox-beta,
234+
firefox-nightly, etc.
235+
224236
Here are some simple examples::
225237

226238
url = 'https://docs.python.org/'

Lib/test/test_webbrowser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,22 @@ def test_environment_preferred(self):
526526
webbrowser = import_helper.import_fresh_module('webbrowser')
527527
self.assertEqual(webbrowser.get().name, sys.executable)
528528

529+
@unittest.skipIf(
530+
is_apple_mobile,
531+
"Apple mobile doesn't allow modifying browser with environment"
532+
)
533+
def test_environment_firefox_channels_mocked_return_mozilla(self):
534+
"""Test with mocked shutil.which that firefox channels yield Mozilla controller."""
535+
firefox_channels = ["firefox-aurora", "firefox-nightly", "firefox-beta"]
536+
for channel in firefox_channels:
537+
with self.subTest(channel=channel):
538+
with mock.patch("shutil.which") as mock_which:
539+
mock_which.side_effect = lambda exe: exe == channel
540+
with os_helper.EnvironmentVarGuard() as env:
541+
env["BROWSER"] = channel
542+
webbrowser = import_helper.import_fresh_module('webbrowser')
543+
controller = webbrowser.get()
544+
self.assertIsInstance(controller, webbrowser.Mozilla)
529545

530546
@force_not_colorized_test_class
531547
class CliTest(unittest.TestCase):

Lib/webbrowser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ def register_standard_browsers():
583583
_tryorder.insert(0, cmdline.lower())
584584
continue
585585

586+
if cmdline.startswith("firefox-") and shutil.which(cmdline):
587+
register(cmdline, None, Mozilla(cmdline), preferred=True)
588+
continue
589+
586590
if cmdline != '':
587591
cmd = _synthesize(cmdline, preferred=True)
588592
if cmd[1] is None:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``register_standard_browsers`` in :mod:`webbrowser` registers firefox
2+
channels (e.g. firefox-dev, firefox-aurora, firefox-beta, firefox-nightly,
3+
etc.) as Mozilla controllers when BROWSER environment variable is set to
4+
``"firefox-*"``.

0 commit comments

Comments
 (0)