summaryrefslogtreecommitdiff
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-21 13:31:12 +0200
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-21 13:31:12 +0200
commit903ffc5fc45b7540625d4c187cc6494631a466cf (patch)
tree828372acf3e92b8c6f571b078d4a1ffa6add5b22 /Lib/idlelib
parent17cd42327ebb12979ecd103abbb2307f8abd4707 (diff)
parentef2576bed55e5f35c76c4536a802cea228ef873f (diff)
downloadcpython-903ffc5fc45b7540625d4c187cc6494631a466cf.tar.gz
Merge from 3.2 for issue #3573, fix Misc/NEWS as Ned Deily guess.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/PyShell.py14
-rw-r--r--Lib/idlelib/configHandler.py3
-rw-r--r--Lib/idlelib/idlever.py2
-rw-r--r--Lib/idlelib/rpc.py7
-rw-r--r--Lib/idlelib/run.py37
5 files changed, 61 insertions, 2 deletions
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index 74a37db862..d7edce501f 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
@@ -1217,6 +1221,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/configHandler.py b/Lib/idlelib/configHandler.py
index 73b8db5b23..79315ef63b 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..301305ee90 100644
--- a/Lib/idlelib/rpc.py
+++ b/Lib/idlelib/rpc.py
@@ -196,8 +196,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 +261,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):
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 25338ffaa6..a161a93c4d 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 builtins
from idlelib import CallTips
from idlelib import AutoComplete
@@ -38,6 +39,21 @@ else:
return s
warnings.formatwarning = idle_formatwarning_subproc
+
+def handle_tk_events():
+ """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."""
+ tkinter = sys.modules.get('tkinter')
+ if tkinter and tkinter._default_root:
+ # tkinter has been imported, an Tcl interpreter was created and
+ # tk has been loaded.
+ root = tkinter._default_root
+ while root.tk.dooneevent(tkinter._tkinter.DONT_WAIT):
+ # Process pending events.
+ pass
+
+
# 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 +109,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)
@@ -245,6 +262,25 @@ class MyRPCServer(rpc.RPCServer):
thread.interrupt_main()
+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
+
+
class MyHandler(rpc.RPCHandler):
def handle(self):
@@ -254,6 +290,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 = displayhook
# page help() text to shell.
import pydoc # import must be done here to capture i/o binding
pydoc.pager = pydoc.plainpager