Title: webbrowser broken on Mac OS X when using the BROWSER variable
Type: Stage: test needed
Components: Library (Lib), macOS Versions: Python 3.6, Python 3.5, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: _kud, doughellmann, ehuss, eitan.adler, ned.deily, orsenthil, ronaldoussoren, sconseil
Priority: normal Keywords: patch

Created on 2015-08-29 10:01 by sconseil, last changed 2019-12-30 19:18 by eitan.adler.

File name Uploaded Description Edit
webbrowser.patch sconseil, 2015-08-29 10:17
Messages (6)
msg249316 - (view) Author: Simon Conseil (sconseil) * Date: 2015-08-29 10:01

There is an issue in the webbrowser module for Mac OS when the BROWSER environment variable is set:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Jedi is not installed, falling back to readline
Python shell history: /Users/simon/.pythonhistory
>>> import webbrowser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 669, in <module>
    cmd = _synthesize(cmdline, -1)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 94, in _synthesize
    if controller and name.lower() == controller.basename:
AttributeError: 'MacOSXOSAScript' object has no attribute 'basename'

If I unset BROWSER then it works fine. The issue is that the MacOSXOSAScript class overrides BaseBrowser's init without redifining the basename attribute. So a simple fix is to remove the __init__ from MacOSXOSAScript (and I guess the same applies to the MacOSX class). The same issue applies to python 3.4
msg249317 - (view) Author: Simon Conseil (sconseil) * Date: 2015-08-29 10:17
New version of the patch to rename the _name attribute to name as in other BaseBrowser subclasses.
msg257198 - (view) Author: Erwann Mest (_kud) Date: 2015-12-29 16:20

I've got like 3 apps which are broken.

msg257962 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-11 14:52
The patch is correct and will fix the issue. It will require test coverage to be complete so that we don't land upon similar issues in future.
msg258120 - (view) Author: Simon Conseil (sconseil) * Date: 2016-01-12 22:43
I have looked at the webbrowser tests and it seems not so easy: currently the MacOS browser classes are not tested, and they don't the GenericBrowser base class. Instead they use custom code with os.popen, so it would require some work either replace os.popen with subprocess.Popen, or to mock the os.popen calls. I'm not sure I will the time to dig into this.
msg258122 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-12 23:43
Simon, sure. It is just for someone, either commiters or other interested folks to add the tests on top of your patch. Agree with you that more change is required to add the required tests.
Date User Action Args
2019-12-30 19:18:33eitan.adlersetnosy: + eitan.adler
2017-07-22 00:58:35ehusssetnosy: + ehuss
2016-06-18 17:57:53doughellmannsetnosy: + doughellmann
2016-01-12 23:43:27orsenthilsetmessages: + msg258122
2016-01-12 22:43:04sconseilsetmessages: + msg258120
2016-01-11 14:52:30orsenthilsetversions: + Python 3.5, Python 3.6, - Python 3.4
nosy: + orsenthil

messages: + msg257962

stage: test needed
2015-12-29 16:20:53_kudsetnosy: + _kud
messages: + msg257198
2015-08-29 10:17:52sconseilsetfiles: - webbrowser.patch
2015-08-29 10:17:33sconseilsetfiles: + webbrowser.patch

messages: + msg249317
2015-08-29 10:01:40sconseilcreate