bpo-43424: Deprecate `webbrowser.MacOSXOSAScript._name` attribute (GH-30241)

This commit is contained in:
Nikita Sobolev 2021-12-30 04:30:13 +03:00 committed by GitHub
parent 8e11237c5d
commit d12bec6993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 7 deletions

View File

@ -197,6 +197,11 @@ Browser controllers provide these methods which parallel three of the
module-level convenience functions: module-level convenience functions:
.. attribute:: name
System-dependent name for the browser.
.. method:: controller.open(url, new=0, autoraise=True) .. method:: controller.open(url, new=0, autoraise=True)
Display *url* using the browser handled by this controller. If *new* is 1, a new Display *url* using the browser handled by this controller. If *new* is 1, a new

View File

@ -304,7 +304,7 @@ class ImportTest(unittest.TestCase):
webbrowser = import_helper.import_fresh_module('webbrowser') webbrowser = import_helper.import_fresh_module('webbrowser')
try: try:
browser = webbrowser.get().name browser = webbrowser.get().name
except (webbrowser.Error, AttributeError) as err: except webbrowser.Error as err:
self.skipTest(str(err)) self.skipTest(str(err))
with os_helper.EnvironmentVarGuard() as env: with os_helper.EnvironmentVarGuard() as env:
env["BROWSER"] = browser env["BROWSER"] = browser
@ -316,7 +316,7 @@ class ImportTest(unittest.TestCase):
try: try:
webbrowser.get() webbrowser.get()
least_preferred_browser = webbrowser.get(webbrowser._tryorder[-1]).name 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)) self.skipTest(str(err))
with os_helper.EnvironmentVarGuard() as env: with os_helper.EnvironmentVarGuard() as env:

View File

@ -666,19 +666,33 @@ if sys.platform == 'darwin':
return not rc return not rc
class MacOSXOSAScript(BaseBrowser): class MacOSXOSAScript(BaseBrowser):
def __init__(self, name): def __init__(self, name='default'):
self._name = name 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): 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 script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
else: else:
script = ''' script = f'''
tell application "%s" tell application "%s"
activate activate
open location "%s" open location "%s"
end end
'''%(self._name, url.replace('"', '%22')) '''%(self.name, url.replace('"', '%22'))
osapipe = os.popen("osascript", "w") osapipe = os.popen("osascript", "w")
if osapipe is None: if osapipe is None:

View File

@ -0,0 +1 @@
Deprecate :attr:`webbrowser.MacOSXOSAScript._name` and use ``name`` instead.