[3.13] gh-131878: Fix input of unicode characters with two or more code points in new pyrepl on Windows (gh-131901) (gh-133468)

(cherry picked from commit 0c5151bc81)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
This commit is contained in:
Łukasz Langa 2025-05-05 23:08:09 +02:00 committed by GitHub
parent 76f52c434c
commit 891232f338
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 27 deletions

View file

@ -69,18 +69,14 @@ def insert(self, event: Event) -> None:
trace('added event {event}', event=event)
self.events.append(event)
def push(self, char: int | bytes | str) -> None:
def push(self, char: int | bytes) -> None:
"""
Processes a character by updating the buffer and handling special key mappings.
"""
assert isinstance(char, (int, bytes))
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,)))
self.buf.append(ord_char)
char = ord_char.to_bytes()
self.buf.append(ord_char)
if char in self.keymap:
if self.keymap is self.compiled_keymap: