Skip to content

Commit 8f67583

Browse files
fix #283 - more careful about checking for control characters
1 parent 5de8bb8 commit 8f67583

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def process_event(self, e):
5353
assert self.has_focus
5454
if isinstance(e, events.PasteEvent):
5555
for ee in e.events:
56-
self.add_normal_character(ee if len(ee) == 1 else ee[-1]) #strip control seq
56+
self.add_normal_character(ee)
5757
elif e in rl_char_sequences:
5858
self.cursor_offset_in_line, self.current_line = rl_char_sequences[e](self.cursor_offset_in_line, self.current_line)
5959
elif isinstance(e, events.SigIntEvent):
@@ -79,6 +79,8 @@ def process_event(self, e):
7979
self.repl.send_to_stdin(self.current_line)
8080

8181
def add_normal_character(self, e):
82+
if len(e) > 1 or is_nop(e):
83+
return
8284
logging.debug('adding normal char %r to current line', e)
8385
c = e if py3 else e.encode('utf8')
8486
self.current_line = (self.current_line[:self.cursor_offset_in_line] +
@@ -350,7 +352,7 @@ def process_event(self, e):
350352
elif e in ["\x1b"]: #ESC
351353
pass
352354
else:
353-
self.add_normal_character(e if len(e) == 1 else e[-1]) #strip control seq
355+
self.add_normal_character(e)
354356
self.update_completion()
355357

356358
def on_enter(self, insert_into_history=True):
@@ -424,8 +426,7 @@ def process_simple_event(self, e):
424426
elif isinstance(e, events.Event):
425427
pass # ignore events
426428
else:
427-
if len(e) == 1:
428-
self.add_normal_character(e if len(e) == 1 else e[-1]) #strip control seq
429+
self.add_normal_character(e)
429430

430431
def send_current_block_to_external_editor(self, filename=None):
431432
text = self.send_to_external_editor(self.get_current_block())
@@ -453,8 +454,7 @@ def send_session_to_external_editor(self, filename=None):
453454

454455
## Handler Helpers
455456
def add_normal_character(self, char):
456-
assert len(char) == 1, repr(char)
457-
if is_nop(char):
457+
if len(char) > 1 or is_nop(char):
458458
return
459459
self._current_line = (self._current_line[:self.cursor_offset_in_line] +
460460
char +
@@ -942,7 +942,7 @@ def getstdout(self):
942942
return s
943943

944944
def is_nop(char):
945-
return unicodedata.category(char) == 'Cc'
945+
return unicodedata.category(unicode(char)) == 'Cc'
946946

947947
def compress_paste_event(paste_event):
948948
"""If all events in a paste event are identical and not simple characters, returns one of them

0 commit comments

Comments
 (0)