diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-03-31 14:20:19 +0300 |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-03-31 14:20:19 +0300 |
commit | 078c0a88179c48b087091a11e7bb6f023b9496b4 (patch) | |
tree | 46b904126568d5a9a8d410a354dc6c8ccbc5e9cd /Lib/idlelib | |
parent | e15542d8d9828bd31c4a73ca81a38e3565b45683 (diff) | |
parent | 962be600758d55749ae840dc54107348ab806ceb (diff) | |
download | cpython-078c0a88179c48b087091a11e7bb6f023b9496b4.tar.gz |
Merge from 3.2
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/NEWS.txt | 4 | ||||
-rw-r--r-- | Lib/idlelib/PyShell.py | 16 | ||||
-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/rpc.py | 26 | ||||
-rw-r--r-- | Lib/idlelib/run.py | 14 |
7 files changed, 71 insertions, 3 deletions
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index a6b06b40e0..d50abd44d2 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -1,6 +1,8 @@ -What's New in IDLE 3.2.3? +What's New in IDLE 3.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 has to use the built-in default key bindings. diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 74a37db862..c524d61e4e 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -468,6 +468,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 @@ -995,6 +999,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() @@ -1217,6 +1223,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") OutputWindow.write(self, s, tags, "iomark") diff --git a/Lib/idlelib/__main__.py b/Lib/idlelib/__main__.py new file mode 100644 index 0000000000..0666f2fd1b --- /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 da927260ee..4049004873 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 250ecf064e..76b8bb8c40 100644 --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1 +1 @@ -IDLE_VERSION = "3.2.3rc2" +IDLE_VERSION = "3.3.0a1" diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py index def43945ae..77cb3ac0a3 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): @@ -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 25338ffaa6..7124c72a63 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -6,6 +6,7 @@ import traceback import _thread as thread import threading import queue +import tkinter from idlelib import CallTips from idlelib import AutoComplete @@ -38,6 +39,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: @@ -93,6 +105,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) @@ -254,6 +267,7 @@ class MyHandler(rpc.RPCHandler): sys.stdin = self.console = self.get_remote_proxy("stdin") sys.stdout = self.get_remote_proxy("stdout") sys.stderr = self.get_remote_proxy("stderr") + 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 |