mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-130804: Fix support of typing unicode chars in pyrepl (#130805)
This commit is contained in:
parent
6ab5c4aa05
commit
7c98b0674d
3 changed files with 17 additions and 3 deletions
|
@ -69,13 +69,19 @@ class BaseEventQueue:
|
||||||
trace('added event {event}', event=event)
|
trace('added event {event}', event=event)
|
||||||
self.events.append(event)
|
self.events.append(event)
|
||||||
|
|
||||||
def push(self, char: int | bytes) -> None:
|
def push(self, char: int | bytes | str) -> None:
|
||||||
"""
|
"""
|
||||||
Processes a character by updating the buffer and handling special key mappings.
|
Processes a character by updating the buffer and handling special key mappings.
|
||||||
"""
|
"""
|
||||||
ord_char = char if isinstance(char, int) else ord(char)
|
ord_char = char if isinstance(char, int) else ord(char)
|
||||||
|
if ord_char > 255:
|
||||||
|
assert isinstance(char, str)
|
||||||
|
char = bytes(char.encode(self.encoding, "replace"))
|
||||||
|
self.buf.extend(char)
|
||||||
|
else:
|
||||||
char = bytes(bytearray((ord_char,)))
|
char = bytes(bytearray((ord_char,)))
|
||||||
self.buf.append(ord_char)
|
self.buf.append(ord_char)
|
||||||
|
|
||||||
if char in self.keymap:
|
if char in self.keymap:
|
||||||
if self.keymap is self.compiled_keymap:
|
if self.keymap is self.compiled_keymap:
|
||||||
# sanity check, buffer is empty when a special key comes
|
# sanity check, buffer is empty when a special key comes
|
||||||
|
|
|
@ -123,6 +123,13 @@ class EventQueueTestBase:
|
||||||
self.assertEqual(eq.events[2].evt, "key")
|
self.assertEqual(eq.events[2].evt, "key")
|
||||||
self.assertEqual(eq.events[2].data, "Z")
|
self.assertEqual(eq.events[2].data, "Z")
|
||||||
|
|
||||||
|
def test_push_unicode_character(self):
|
||||||
|
eq = self.make_eventqueue()
|
||||||
|
eq.keymap = {}
|
||||||
|
eq.push("ч")
|
||||||
|
self.assertEqual(eq.events[0].evt, "key")
|
||||||
|
self.assertEqual(eq.events[0].data, "ч")
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(support.MS_WINDOWS, "No Unix event queue on Windows")
|
@unittest.skipIf(support.MS_WINDOWS, "No Unix event queue on Windows")
|
||||||
class TestUnixEventQueue(EventQueueTestBase, unittest.TestCase):
|
class TestUnixEventQueue(EventQueueTestBase, unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix support of unicode characters on Windows in the new REPL.
|
Loading…
Add table
Add a link
Reference in a new issue