Skip to content

bpo-43424: Deprecate webbrowser.MacOSXOSAScript._name attribute #30241

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

Merged
merged 4 commits into from
Dec 30, 2021
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
5 changes: 5 additions & 0 deletions Doc/library/webbrowser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ Browser controllers provide these methods which parallel three of the
module-level convenience functions:


.. attribute:: name

System-dependent name for the browser.


.. method:: controller.open(url, new=0, autoraise=True)

Display *url* using the browser handled by this controller. If *new* is 1, a new
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def test_environment(self):
webbrowser = import_helper.import_fresh_module('webbrowser')
try:
browser = webbrowser.get().name
except (webbrowser.Error, AttributeError) as err:
except webbrowser.Error as err:
self.skipTest(str(err))
with os_helper.EnvironmentVarGuard() as env:
env["BROWSER"] = browser
Expand All @@ -316,7 +316,7 @@ def test_environment_preferred(self):
try:
webbrowser.get()
least_preferred_browser = webbrowser.get(webbrowser._tryorder[-1]).name
except (webbrowser.Error, AttributeError, IndexError) as err:
except (webbrowser.Error, IndexError) as err:
self.skipTest(str(err))

with os_helper.EnvironmentVarGuard() as env:
Expand Down
24 changes: 19 additions & 5 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,19 +666,33 @@ def open(self, url, new=0, autoraise=True):
return not rc

class MacOSXOSAScript(BaseBrowser):
def __init__(self, name):
self._name = name
def __init__(self, name='default'):
super().__init__(name)

@property
def _name(self):
warnings.warn(f'{self.__class__.__name__}._name is deprecated in 3.11'
f' use {self.__class__.__name__}.name instead.',
DeprecationWarning, stacklevel=2)
return self.name

@_name.setter
def _name(self, val):
warnings.warn(f'{self.__class__.__name__}._name is deprecated in 3.11'
f' use {self.__class__.__name__}.name instead.',
DeprecationWarning, stacklevel=2)
self.name = val

def open(self, url, new=0, autoraise=True):
if self._name == 'default':
if self.name == 'default':
script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
else:
script = '''
script = f'''
tell application "%s"
activate
open location "%s"
end
'''%(self._name, url.replace('"', '%22'))
'''%(self.name, url.replace('"', '%22'))

osapipe = os.popen("osascript", "w")
if osapipe is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate :attr:`webbrowser.MacOSXOSAScript._name` and use ``name`` instead.