diff options
Diffstat (limited to 'Lib/idlelib')
| -rw-r--r-- | Lib/idlelib/AutoComplete.py | 3 | ||||
| -rw-r--r-- | Lib/idlelib/ColorDelegator.py | 13 | ||||
| -rw-r--r-- | Lib/idlelib/EditorWindow.py | 19 | ||||
| -rw-r--r-- | Lib/idlelib/HyperParser.py | 2 | ||||
| -rw-r--r-- | Lib/idlelib/IOBinding.py | 12 | ||||
| -rw-r--r-- | Lib/idlelib/MultiCall.py | 5 | ||||
| -rw-r--r-- | Lib/idlelib/NEWS.txt | 36 | ||||
| -rw-r--r-- | Lib/idlelib/PathBrowser.py | 7 | ||||
| -rw-r--r-- | Lib/idlelib/PyShell.py | 43 | ||||
| -rw-r--r-- | Lib/idlelib/ScriptBinding.py | 12 | ||||
| -rw-r--r-- | Lib/idlelib/__main__.py | 9 | ||||
| -rw-r--r-- | Lib/idlelib/configHandler.py | 3 | ||||
| -rw-r--r-- | Lib/idlelib/idlever.py | 2 | ||||
| -rw-r--r-- | Lib/idlelib/macosxSupport.py | 16 | ||||
| -rw-r--r-- | Lib/idlelib/rpc.py | 28 | ||||
| -rw-r--r-- | Lib/idlelib/run.py | 18 |
16 files changed, 174 insertions, 54 deletions
diff --git a/Lib/idlelib/AutoComplete.py b/Lib/idlelib/AutoComplete.py index e4c1aff..929d358 100644 --- a/Lib/idlelib/AutoComplete.py +++ b/Lib/idlelib/AutoComplete.py @@ -9,9 +9,6 @@ import string from idlelib.configHandler import idleConf -# This string includes all chars that may be in a file name (without a path -# separator) -FILENAME_CHARS = string.ascii_letters + string.digits + os.curdir + "._~#$:-" # This string includes all chars that may be in an identifier ID_CHARS = string.ascii_letters + string.digits + "_" diff --git a/Lib/idlelib/ColorDelegator.py b/Lib/idlelib/ColorDelegator.py index e188192..e4ccb42 100644 --- a/Lib/idlelib/ColorDelegator.py +++ b/Lib/idlelib/ColorDelegator.py @@ -21,10 +21,11 @@ def make_pat(): # 1st 'file' colorized normal, 2nd as builtin, 3rd as string builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b" comment = any("COMMENT", [r"#[^\n]*"]) - sqstring = r"(\b[rRbB])?'[^'\\\n]*(\\.[^'\\\n]*)*'?" - dqstring = r'(\b[rRbB])?"[^"\\\n]*(\\.[^"\\\n]*)*"?' - sq3string = r"(\b[rRbB])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" - dq3string = r'(\b[rRbB])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' + stringprefix = r"(\br|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR|rb|rB|Rb|RB)?" + sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?" + dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?' + sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" + dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' string = any("STRING", [sq3string, dq3string, sqstring, dqstring]) return kw + "|" + builtin + "|" + comment + "|" + string +\ "|" + any("SYNC", [r"\n"]) @@ -149,9 +150,9 @@ class ColorDelegator(Delegator): self.stop_colorizing = False self.colorizing = True if DEBUG: print("colorizing...") - t0 = time.clock() + t0 = time.perf_counter() self.recolorize_main() - t1 = time.clock() + t1 = time.perf_counter() if DEBUG: print("%.3f seconds" % (t1-t0)) finally: self.colorizing = False diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index 16f63c5..3397415 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1,8 +1,9 @@ -import sys +import imp +import importlib import os import re import string -import imp +import sys from tkinter import * import tkinter.simpledialog as tkSimpleDialog import tkinter.messagebox as tkMessageBox @@ -27,8 +28,7 @@ def _sphinx_version(): "Format sys.version_info to produce the Sphinx version string used to install the chm docs" major, minor, micro, level, serial = sys.version_info release = '%s%s' % (major, minor) - if micro: - release += '%s' % (micro,) + release += '%s' % (micro,) if level == 'candidate': release += 'rc%s' % (serial,) elif level != 'final': @@ -120,7 +120,7 @@ class EditorWindow(object): def __init__(self, flist=None, filename=None, key=None, root=None): if EditorWindow.help_url is None: - dochome = os.path.join(sys.prefix, 'Doc', 'index.html') + dochome = os.path.join(sys.base_prefix, 'Doc', 'index.html') if sys.platform.count('linux'): # look for html docs in a couple of standard places pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] @@ -131,13 +131,13 @@ class EditorWindow(object): dochome = os.path.join(basepath, pyver, 'Doc', 'index.html') elif sys.platform[:3] == 'win': - chmfile = os.path.join(sys.prefix, 'Doc', + chmfile = os.path.join(sys.base_prefix, 'Doc', 'Python%s.chm' % _sphinx_version()) if os.path.isfile(chmfile): dochome = chmfile elif macosxSupport.runningAsOSXApp(): # documentation is stored inside the python framework - dochome = os.path.join(sys.prefix, + dochome = os.path.join(sys.base_prefix, 'Resources/English.lproj/Documentation/index.html') dochome = os.path.normpath(dochome) if os.path.isfile(dochome): @@ -1041,7 +1041,10 @@ class EditorWindow(object): def load_extension(self, name): try: - mod = __import__(name, globals(), locals(), []) + try: + mod = importlib.import_module('.' + name, package=__package__) + except ImportError: + mod = importlib.import_module(name) except ImportError: print("\nFailed to import extension: ", name) raise diff --git a/Lib/idlelib/HyperParser.py b/Lib/idlelib/HyperParser.py index 4414de7..4af4b08 100644 --- a/Lib/idlelib/HyperParser.py +++ b/Lib/idlelib/HyperParser.py @@ -234,7 +234,7 @@ class HyperParser: # We can't continue after other types of brackets if rawtext[pos] in "'\"": # Scan a string prefix - while pos > 0 and rawtext[pos - 1] in "rRbB": + while pos > 0 and rawtext[pos - 1] in "rRbBuU": pos -= 1 last_identifier_pos = pos break diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py index c4f14ef..9fe0701 100644 --- a/Lib/idlelib/IOBinding.py +++ b/Lib/idlelib/IOBinding.py @@ -1,6 +1,6 @@ import os import types -import pipes +import shlex import sys import codecs import tempfile @@ -459,7 +459,7 @@ class IOBinding: else: #no printing for this platform printPlatform = False if printPlatform: #we can try to print for this platform - command = command % pipes.quote(filename) + command = command % shlex.quote(filename) pipe = os.popen(command, "r") # things can get ugly on NT if there is no printer available. output = pipe.read().strip() @@ -486,6 +486,8 @@ class IOBinding: ("All files", "*"), ] + defaultextension = '.py' if sys.platform == 'darwin' else '' + def askopenfile(self): dir, base = self.defaultfilename("open") if not self.opendialog: @@ -509,8 +511,10 @@ class IOBinding: def asksavefile(self): dir, base = self.defaultfilename("save") if not self.savedialog: - self.savedialog = tkFileDialog.SaveAs(master=self.text, - filetypes=self.filetypes) + self.savedialog = tkFileDialog.SaveAs( + master=self.text, + filetypes=self.filetypes, + defaultextension=self.defaultextension) filename = self.savedialog.show(initialdir=dir, initialfile=base) return filename diff --git a/Lib/idlelib/MultiCall.py b/Lib/idlelib/MultiCall.py index 47f402d..64729ea 100644 --- a/Lib/idlelib/MultiCall.py +++ b/Lib/idlelib/MultiCall.py @@ -170,8 +170,9 @@ class _ComplexBinder: break ishandlerrunning[:] = [] # Call all functions in doafterhandler and remove them from list - while doafterhandler: - doafterhandler.pop()() + for f in doafterhandler: + f() + doafterhandler[:] = [] if r: return r return handler diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 87c099f..748a97b 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -1,4 +1,21 @@ -What's New in IDLE 3.2.4? +What's New in IDLE 3.3.2? +========================= + +- Issue #17390: Display Python version on Idle title bar. + Initial patch by Edmond Burnett. + + +What's New in IDLE 3.3.1? +========================= + +- Issue #16226: Fix IDLE Path Browser crash. + (Patch by Roger Serwy) + +- Issue #15853: Prevent IDLE crash on OS X when opening Preferences menu + with certain versions of Tk 8.5. Initial patch by Kevin Walzer. + + +What's New in IDLE 3.3.0? ========================= - Issue #17625: Close the replace dialog after it is used. @@ -7,6 +24,9 @@ What's New in IDLE 3.2.4? - Issue #15318: Prevent writing to sys.stdin. +- Issue #4832: Modify IDLE to save files with .py extension by + default on Windows and OS X (Tk 8.5) as it already does with X11 Tk. + - Issue #13532, #15319: Check that arguments to sys.stdout.write are strings. - Issue # 12510: Attempt to get certain tool tips no longer crashes IDLE. @@ -20,15 +40,10 @@ What's New in IDLE 3.2.4? - Issue #14937: Perform auto-completion of filenames in strings even for non-ASCII filenames. Likewise for identifiers. -- Issue #14018: Update checks for unstable system Tcl/Tk versions on OS X - to include versions shipped with OS X 10.7 and 10.8 in addition to 10.6. - -- Issue #15853: Prevent IDLE crash on OS X when opening Preferences menu - with certain versions of Tk 8.5. Initial patch by Kevin Walzer. +- Issue #8515: Set __file__ when run file in IDLE. + Initial patch by Bruce Frederiksen. - -What's New in IDLE 3.2.3? -========================= +- IDLE can be launched as `python -m idlelib` - Issue #14409: IDLE now properly executes commands in the Shell window when it cannot read the normal config files on startup and @@ -38,6 +53,9 @@ What's New in IDLE 3.2.3? - Issue #3573: IDLE hangs when passing invalid command line args (directory(ies) instead of file(s)). +- Issue #14018: Update checks for unstable system Tcl/Tk versions on OS X + to include versions shipped with OS X 10.7 and 10.8 in addition to 10.6. + What's New in IDLE 3.2.1? ========================= diff --git a/Lib/idlelib/PathBrowser.py b/Lib/idlelib/PathBrowser.py index d88a48e..55bf1aa 100644 --- a/Lib/idlelib/PathBrowser.py +++ b/Lib/idlelib/PathBrowser.py @@ -1,6 +1,7 @@ import os import sys import imp +import importlib.machinery from idlelib.TreeWidget import TreeItem from idlelib.ClassBrowser import ClassBrowser, ModuleBrowserTreeItem @@ -70,9 +71,11 @@ class DirBrowserTreeItem(TreeItem): def listmodules(self, allnames): modules = {} - suffixes = imp.get_suffixes() + suffixes = importlib.machinery.EXTENSION_SUFFIXES[:] + suffixes += importlib.machinery.SOURCE_SUFFIXES[:] + suffixes += importlib.machinery.BYTECODE_SUFFIXES[:] sorted = [] - for suff, mode, flag in suffixes: + for suff in suffixes: i = -len(suff) for name in allnames[:]: normed_name = os.path.normcase(name) diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 865472e..c381f23 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -16,6 +16,7 @@ import io import linecache from code import InteractiveInterpreter +from platform import python_version try: from tkinter import * @@ -110,12 +111,13 @@ class PyShellEditorWindow(EditorWindow): self.breakpointPath = os.path.join(idleConf.GetUserCfgDir(), 'breakpoints.lst') # whenever a file is changed, restore breakpoints - if self.io.filename: self.restore_file_breaks() def filename_changed_hook(old_hook=self.io.filename_change_hook, self=self): self.restore_file_breaks() old_hook() self.io.set_filename_change_hook(filename_changed_hook) + if self.io.filename: + self.restore_file_breaks() rmenu_specs = [ ("Cut", "<<cut>>", "rmenu_check_cut"), @@ -232,6 +234,9 @@ class PyShellEditorWindow(EditorWindow): def restore_file_breaks(self): self.text.update() # this enables setting "BREAK" tags to be visible + if self.io is None: + # can happen if IDLE closes due to the .update() call + return filename = self.io.filename if filename is None: return @@ -453,6 +458,7 @@ class ModifiedInterpreter(InteractiveInterpreter): self.display_no_subprocess_error() return None self.transfer_path(with_cwd=with_cwd) + console.stop_readline() # annotate restart in shell window and mark it console.text.delete("iomark", "end-1c") if was_executing: @@ -481,6 +487,10 @@ class ModifiedInterpreter(InteractiveInterpreter): def kill_subprocess(self): try: + self.rpcclt.listening_sock.close() + except AttributeError: # no socket + pass + try: self.rpcclt.close() except AttributeError: # no socket pass @@ -795,7 +805,7 @@ class ModifiedInterpreter(InteractiveInterpreter): class PyShell(OutputWindow): - shell_title = "Python Shell" + shell_title = "Python " + python_version() + " Shell" # Override classes ColorDelegator = ModifiedColorDelegator @@ -887,6 +897,7 @@ class PyShell(OutputWindow): canceled = False endoffile = False closing = False + _stop_readline_flag = False def set_warning_stream(self, stream): global warning_stream @@ -962,8 +973,7 @@ class PyShell(OutputWindow): parent=self.text) if response is False: return "cancel" - if self.reading: - self.top.quit() + self.stop_readline() self.canceled = True self.closing = True # Wait for poll_subprocess() rescheduling to stop @@ -1009,6 +1019,8 @@ class PyShell(OutputWindow): return False else: nosub = "==== No Subprocess ====" + sys.displayhook = rpc.displayhook + self.write("Python %s on %s\n%s\n%s" % (sys.version, sys.platform, self.COPYRIGHT, nosub)) self.showprompt() @@ -1016,6 +1028,12 @@ class PyShell(OutputWindow): tkinter._default_root = None # 03Jan04 KBK What's this? return True + def stop_readline(self): + if not self.reading: # no nested mainloop to exit. + return + self._stop_readline_flag = True + self.top.quit() + def readline(self): save = self.reading try: @@ -1023,6 +1041,9 @@ class PyShell(OutputWindow): self.top.mainloop() # nested mainloop() finally: self.reading = save + if self._stop_readline_flag: + self._stop_readline_flag = False + return "" line = self.text.get("iomark", "end-1c") if len(line) == 0: # may be EOF if we quit our mainloop with Ctrl-C line = "\n" @@ -1231,6 +1252,16 @@ class PyShell(OutputWindow): self.set_line_and_column() def write(self, s, tags=()): + if isinstance(s, str) and len(s) and max(s) > '\uffff': + # Tk doesn't support outputting non-BMP characters + # Let's assume what printed string is not very long, + # find first non-BMP character and construct informative + # UnicodeEncodeError exception. + for start, char in enumerate(s): + if char > '\uffff': + break + raise UnicodeEncodeError("UCS-2", char, start, start+1, + 'Non-BMP character not supported in Tk') try: self.text.mark_gravity("iomark", "right") count = OutputWindow.write(self, s, tags, "iomark") @@ -1392,7 +1423,7 @@ def main(): global flist, root, use_subprocess use_subprocess = True - enable_shell = True + enable_shell = False enable_edit = False debug = False cmd = None @@ -1413,7 +1444,6 @@ def main(): enable_shell = True if o == '-e': enable_edit = True - enable_shell = False if o == '-h': sys.stdout.write(usage_msg) sys.exit() @@ -1464,6 +1494,7 @@ def main(): edit_start = idleConf.GetOption('main', 'General', 'editor-on-startup', type='bool') enable_edit = enable_edit or edit_start + enable_shell = enable_shell or not enable_edit # start editor and/or shell windows: root = Tk(className="Idle") diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py index 18ce965..528adf6 100644 --- a/Lib/idlelib/ScriptBinding.py +++ b/Lib/idlelib/ScriptBinding.py @@ -150,16 +150,16 @@ class ScriptBinding: dirname = os.path.dirname(filename) # XXX Too often this discards arguments the user just set... interp.runcommand("""if 1: - _filename = %r + __file__ = {filename!r} import sys as _sys from os.path import basename as _basename if (not _sys.argv or - _basename(_sys.argv[0]) != _basename(_filename)): - _sys.argv = [_filename] + _basename(_sys.argv[0]) != _basename(__file__)): + _sys.argv = [__file__] import os as _os - _os.chdir(%r) - del _filename, _sys, _basename, _os - \n""" % (filename, dirname)) + _os.chdir({dirname!r}) + del _sys, _basename, _os + \n""".format(filename=filename, dirname=dirname)) interp.prepend_syspath(filename) # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still # go to __stderr__. With subprocess, they go to the shell. diff --git a/Lib/idlelib/__main__.py b/Lib/idlelib/__main__.py new file mode 100644 index 0000000..0666f2f --- /dev/null +++ b/Lib/idlelib/__main__.py @@ -0,0 +1,9 @@ +""" +IDLE main entry point + +Run IDLE as python -m idlelib +""" + + +import idlelib.PyShell +idlelib.PyShell.main() diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index 7fa481d..5bf2668 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -145,7 +145,8 @@ class IdleUserConfParser(IdleConfParser): except IOError: os.unlink(fname) cfgFile = open(fname, 'w') - self.write(cfgFile) + with cfgFile: + self.write(cfgFile) else: self.RemoveFile() diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py index 671b2b8..8d8317d 100644 --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1 +1 @@ -IDLE_VERSION = "3.2.4" +IDLE_VERSION = "3.3.0" diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosxSupport.py index 9690442..67069fa 100644 --- a/Lib/idlelib/macosxSupport.py +++ b/Lib/idlelib/macosxSupport.py @@ -12,12 +12,22 @@ _appbundle = None def runningAsOSXApp(): """ Returns True if Python is running from within an app on OSX. - If so, assume that Python was built with Aqua Tcl/Tk rather than - X11 Tcl/Tk. + If so, the various OS X customizations will be triggered later (menu + fixup, et al). (Originally, this test was supposed to condition + behavior on whether IDLE was running under Aqua Tk rather than + under X11 Tk but that does not work since a framework build + could be linked with X11. For several releases, this test actually + differentiates between whether IDLE is running from a framework or + not. As a future enhancement, it should be considered whether there + should be a difference based on framework and any needed X11 adaptions + should be made dependent on a new function that actually tests for X11.) """ global _appbundle if _appbundle is None: - _appbundle = (sys.platform == 'darwin' and '.app' in sys.executable) + _appbundle = sys.platform == 'darwin' + if _appbundle: + import sysconfig + _appbundle = bool(sysconfig.get_config_var('PYTHONFRAMEWORK')) return _appbundle _carbonaquatk = None diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py index 29e687e..6093ce2 100644 --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -40,6 +40,7 @@ import traceback import copyreg import types import marshal +import builtins def unpickle_code(ms): @@ -144,7 +145,7 @@ class SocketIO(object): def exithook(self): "override for specific exit action" - os._exit() + os._exit(0) def debug(self, *args): if not self.debugging: @@ -196,8 +197,12 @@ class SocketIO(object): return ("ERROR", "Unsupported message type: %s" % how) except SystemExit: raise + except KeyboardInterrupt: + raise except socket.error: raise + except Exception as ex: + return ("CALLEXC", ex) except: msg = "*** Internal Error: rpc.py:SocketIO.localcall()\n\n"\ " Object: %s \n Method: %s \n Args: %s\n" @@ -257,6 +262,9 @@ class SocketIO(object): if how == "ERROR": self.debug("decoderesponse: Internal ERROR:", what) raise RuntimeError(what) + if how == "CALLEXC": + self.debug("decoderesponse: Call Exception:", what) + raise what raise SystemError(how, what) def decode_interrupthook(self): @@ -596,3 +604,21 @@ class MethodProxy(object): # XXX KBK 09Sep03 We need a proper unit test for this module. Previously # existing test code was removed at Rev 1.27 (r34098). + +def displayhook(value): + """Override standard display hook to use non-locale encoding""" + if value is None: + return + # Set '_' to None to avoid recursion + builtins._ = None + text = repr(value) + try: + sys.stdout.write(text) + except UnicodeEncodeError: + # let's use ascii while utf8-bmp codec doesn't present + encoding = 'ascii' + bytes = text.encode(encoding, 'backslashreplace') + text = bytes.decode(encoding, 'strict') + sys.stdout.write(text) + sys.stdout.write("\n") + builtins._ = value diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 7d0941e..d105912 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -7,6 +7,7 @@ import traceback import _thread as thread import threading import queue +import tkinter from idlelib import CallTips from idlelib import AutoComplete @@ -41,6 +42,17 @@ else: return s warnings.formatwarning = idle_formatwarning_subproc + +tcl = tkinter.Tcl() + + +def handle_tk_events(tcl=tcl): + """Process any tk events that are ready to be dispatched if tkinter + has been imported, a tcl interpreter has been created and tk has been + loaded.""" + tcl.eval("update") + + # Thread shared globals: Establish a queue between a subthread (which handles # the socket) and the main thread (which runs user code), plus global # completion, exit and interruptable (the main thread) flags: @@ -96,6 +108,7 @@ def main(del_exitfunc=False): try: seq, request = rpc.request_queue.get(block=True, timeout=0.05) except queue.Empty: + handle_tk_events() continue method, args, kwargs = request ret = method(*args, **kwargs) @@ -170,7 +183,9 @@ def print_exception(): print_exc(type(cause), cause, cause.__traceback__) print("\nThe above exception was the direct cause " "of the following exception:\n", file=efile) - elif context is not None and context not in seen: + elif (context is not None and + not exc.__suppress_context__ and + context not in seen): print_exc(type(context), context, context.__traceback__) print("\nDuring handling of the above exception, " "another exception occurred:\n", file=efile) @@ -278,6 +293,7 @@ class MyHandler(rpc.RPCHandler): sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr", IOBinding.encoding) + sys.displayhook = rpc.displayhook # page help() text to shell. import pydoc # import must be done here to capture i/o binding pydoc.pager = pydoc.plainpager |
