diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-09-24 22:01:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-24 22:01:45 (GMT) |
commit | a7a7da4acfb0cb33b7d67eea695f2612f38f477f (patch) | |
tree | fc5b6666dd2b7a529a9ae55dfbc70f56a35b12ef /Lib | |
parent | 2a50772b63d7bc4ef97d16e9bcc53455c301b0ea (diff) | |
download | cpython-a7a7da4acfb0cb33b7d67eea695f2612f38f477f.zip cpython-a7a7da4acfb0cb33b7d67eea695f2612f38f477f.tar.gz cpython-a7a7da4acfb0cb33b7d67eea695f2612f38f477f.tar.bz2 |
gh-97527: IDLE: protect macosx Tk() call when no GUI (GH-97530)
Only call tkinter.tk and its follow-up code in _init_tk_type when requires('gui')
does not raise. This function can be called as an unintended side-effect of
calling other idlelib code as part of tests on macOS without a GUI enabled.
(cherry picked from commit 9704f8da333a51da32318f16106d45abb20fab76)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/idlelib/macosx.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/Lib/idlelib/macosx.py b/Lib/idlelib/macosx.py index 470de5d..1085d68 100644 --- a/Lib/idlelib/macosx.py +++ b/Lib/idlelib/macosx.py @@ -4,6 +4,7 @@ A number of functions that enhance IDLE on macOS. from os.path import expanduser import plistlib from sys import platform # Used in _init_tk_type, changed by test. +from test.support import requires, ResourceDenied import tkinter @@ -14,23 +15,26 @@ import tkinter _tk_type = None def _init_tk_type(): - """ - Initializes OS X Tk variant values for - isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz(). + """ Initialize _tk_type for isXyzTk functions. """ global _tk_type if platform == 'darwin': - root = tkinter.Tk() - ws = root.tk.call('tk', 'windowingsystem') - if 'x11' in ws: - _tk_type = "xquartz" - elif 'aqua' not in ws: - _tk_type = "other" - elif 'AppKit' in root.tk.call('winfo', 'server', '.'): - _tk_type = "cocoa" + try: + requires('gui') + except ResourceDenied: # Possible when testing. + _tk_type = "cocoa" # Newest and most common. else: - _tk_type = "carbon" - root.destroy() + root = tkinter.Tk() + ws = root.tk.call('tk', 'windowingsystem') + if 'x11' in ws: + _tk_type = "xquartz" + elif 'aqua' not in ws: + _tk_type = "other" + elif 'AppKit' in root.tk.call('winfo', 'server', '.'): + _tk_type = "cocoa" + else: + _tk_type = "carbon" + root.destroy() else: _tk_type = "other" |