Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76f52c4

Browse files
[3.13]gh-130804: Fix support of typing unicode chars in pyrepl (GH-130805) (GH-133462)
(cherry picked from commit7c98b06)Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
1 parente4d6848 commit76f52c4

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

‎Lib/_pyrepl/base_eventqueue.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,19 @@ def insert(self, event: Event) -> None:
6969
trace('added event {event}',event=event)
7070
self.events.append(event)
7171

72-
defpush(self,char:int|bytes)->None:
72+
defpush(self,char:int|bytes|str)->None:
7373
"""
7474
Processes a character by updating the buffer and handling special key mappings.
7575
"""
7676
ord_char=charifisinstance(char,int)elseord(char)
77-
char=bytes(bytearray((ord_char,)))
78-
self.buf.append(ord_char)
77+
iford_char>255:
78+
assertisinstance(char,str)
79+
char=bytes(char.encode(self.encoding,"replace"))
80+
self.buf.extend(char)
81+
else:
82+
char=bytes(bytearray((ord_char,)))
83+
self.buf.append(ord_char)
84+
7985
ifcharinself.keymap:
8086
ifself.keymapisself.compiled_keymap:
8187
# sanity check, buffer is empty when a special key comes

‎Lib/test/test_pyrepl/test_eventqueue.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ def test_push_unrecognized_escape_sequence(self):
123123
self.assertEqual(eq.events[2].evt,"key")
124124
self.assertEqual(eq.events[2].data,"Z")
125125

126+
deftest_push_unicode_character(self):
127+
eq=self.make_eventqueue()
128+
eq.keymap= {}
129+
eq.push("ч")
130+
self.assertEqual(eq.events[0].evt,"key")
131+
self.assertEqual(eq.events[0].data,"ч")
132+
126133

127134
@unittest.skipIf(support.MS_WINDOWS,"No Unix event queue on Windows")
128135
classTestUnixEventQueue(EventQueueTestBase,unittest.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix support of unicode characters on Windows in the new REPL.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp