Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7c8fde

Browse files
committed
merge heads
2 parents 2f9bf35 + 8247b18 commit e7c8fde

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,16 @@ def resetoutput(self):
12211221
self.set_line_and_column()
12221222

12231223
def write(self, s, tags=()):
1224+
if isinstance(s, str) and len(s) and max(s) > '\uffff':
1225+
# Tk doesn't support outputting non-BMP characters
1226+
# Let's assume what printed string is not very long,
1227+
# find first non-BMP character and construct informative
1228+
# UnicodeEncodeError exception.
1229+
for start, char in enumerate(s):
1230+
if char > '\uffff':
1231+
break
1232+
raise UnicodeEncodeError("UCS-2", char, start, start+1,
1233+
'Non-BMP character not supported in Tk')
12241234
try:
12251235
self.text.mark_gravity("iomark", "right")
12261236
OutputWindow.write(self, s, tags, "iomark")

Lib/idlelib/rpc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ def localcall(self, seq, request):
196196
return ("ERROR", "Unsupported message type: %s" % how)
197197
except SystemExit:
198198
raise
199+
except KeyboardInterrupt:
200+
raise
199201
except socket.error:
200202
raise
203+
except Exception as ex:
204+
return ("CALLEXC", ex)
201205
except:
202206
msg = "*** Internal Error: rpc.py:SocketIO.localcall()\n\n"\
203207
" Object: %s \n Method: %s \n Args: %s\n"
@@ -257,6 +261,9 @@ def decoderesponse(self, response):
257261
if how == "ERROR":
258262
self.debug("decoderesponse: Internal ERROR:", what)
259263
raise RuntimeError(what)
264+
if how == "CALLEXC":
265+
self.debug("decoderesponse: Call Exception:", what)
266+
raise what
260267
raise SystemError(how, what)
261268

262269
def decode_interrupthook(self):

Lib/idlelib/run.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import _thread as thread
77
import threading
88
import queue
9+
import builtins
910

1011
from idlelib import CallTips
1112
from idlelib import AutoComplete
@@ -261,6 +262,25 @@ def handle_error(self, request, client_address):
261262
thread.interrupt_main()
262263

263264

265+
def displayhook(value):
266+
"""Override standard display hook to use non-locale encoding"""
267+
if value is None:
268+
return
269+
# Set '_' to None to avoid recursion
270+
builtins._ = None
271+
text = repr(value)
272+
try:
273+
sys.stdout.write(text)
274+
except UnicodeEncodeError:
275+
# let's use ascii while utf8-bmp codec doesn't present
276+
encoding = 'ascii'
277+
bytes = text.encode(encoding, 'backslashreplace')
278+
text = bytes.decode(encoding, 'strict')
279+
sys.stdout.write(text)
280+
sys.stdout.write("\n")
281+
builtins._ = value
282+
283+
264284
class MyHandler(rpc.RPCHandler):
265285

266286
def handle(self):
@@ -270,6 +290,7 @@ def handle(self):
270290
sys.stdin = self.console = self.get_remote_proxy("stdin")
271291
sys.stdout = self.get_remote_proxy("stdout")
272292
sys.stderr = self.get_remote_proxy("stderr")
293+
sys.displayhook = displayhook
273294
# page help() text to shell.
274295
import pydoc # import must be done here to capture i/o binding
275296
pydoc.pager = pydoc.plainpager

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #14200: Idle shell crash on printing non-BMP unicode character.
28+
2729
- Issue #12818: format address no longer needlessly \ escapes ()s in names when
2830
the name ends up being quoted.
2931

0 commit comments

Comments
 (0)