Skip to content

Commit f4db0e7

Browse files
bpo-13153: Use OS native encoding for converting between Python and Tcl.
On Windows use UTF-16 (or UTF-32 for 32-bit Tcl_UniChar) with the "surrogatepass" error handler for converting to/from Tcl Unicode objects. On Linux use UTF-8 with the "surrogateescape" error handler for converting to/from Tcl String objects. Converting strings from Tcl to Python and back now never fails (except MemoryError).
1 parent b3e7045 commit f4db0e7

File tree

4 files changed

+209
-182
lines changed

4 files changed

+209
-182
lines changed

Lib/idlelib/pyshell.py

-10
Original file line numberDiff line numberDiff line change
@@ -1298,16 +1298,6 @@ def resetoutput(self):
12981298
self.set_line_and_column()
12991299

13001300
def write(self, s, tags=()):
1301-
if isinstance(s, str) and len(s) and max(s) > '\uffff':
1302-
# Tk doesn't support outputting non-BMP characters
1303-
# Let's assume what printed string is not very long,
1304-
# find first non-BMP character and construct informative
1305-
# UnicodeEncodeError exception.
1306-
for start, char in enumerate(s):
1307-
if char > '\uffff':
1308-
break
1309-
raise UnicodeEncodeError("UCS-2", char, start, start+1,
1310-
'Non-BMP character not supported in Tk')
13111301
try:
13121302
self.text.mark_gravity("iomark", "right")
13131303
count = OutputWindow.write(self, s, tags, "iomark")

Lib/test/test_tcl.py

+5
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,12 @@ def passValue(value):
429429
self.assertEqual(passValue(False), False if self.wantobjects else '0')
430430
self.assertEqual(passValue('string'), 'string')
431431
self.assertEqual(passValue('string\u20ac'), 'string\u20ac')
432+
self.assertEqual(passValue('string\U0001f4bb'), 'string\U0001f4bb')
432433
self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
433434
self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
434435
self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
436+
self.assertEqual(passValue('str\x00ing\U0001f4bb'),
437+
'str\x00ing\U0001f4bb')
435438
self.assertEqual(passValue(b'str\x00ing'),
436439
b'str\x00ing' if self.wantobjects else 'str\x00ing')
437440
self.assertEqual(passValue(b'str\xc0\x80ing'),
@@ -490,6 +493,7 @@ def float_eq(actual, expected):
490493
check('string')
491494
check('string\xbd')
492495
check('string\u20ac')
496+
check('string\U0001f4bb')
493497
check('')
494498
check(b'string', 'string')
495499
check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
@@ -531,6 +535,7 @@ def test_splitlist(self):
531535
('a\n b\t\r c\n ', ('a', 'b', 'c')),
532536
(b'a\n b\t\r c\n ', ('a', 'b', 'c')),
533537
('a \u20ac', ('a', '\u20ac')),
538+
('a \U0001f4bb', ('a', '\U0001f4bb')),
534539
(b'a \xe2\x82\xac', ('a', '\u20ac')),
535540
(b'a\xc0\x80b c\xc0\x80d', ('a\x00b', 'c\x00d')),
536541
('a {b c}', ('a', 'b c')),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OS native encoding is now used for converting between Python strings and
2+
Tcl objects. This allows to display, copy and paste to clipboard emoji and
3+
other non-BMP characters. Converting strings from Tcl to Python and back
4+
now never fails (except MemoryError).

0 commit comments

Comments
 (0)