Skip to content

Commit aa4f3ac

Browse files
committed
(hpaulj) Fix startup_hook in readline to work like CPython. Fixes issue950
1 parent a52a91e commit aa4f3ac

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

pyrepl/reader.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ def _make_unctrl_map():
3737
for i in range(256):
3838
c = unichr(i)
3939
if not uc_map.has_key(c):
40-
uc_map[c] = u'\\%03o'%i
40+
uc_map[c] = u'\\%03o'%i
4141
return uc_map
4242

4343
# disp_str proved to be a bottleneck for large inputs, so it's been
4444
# rewritten in C; it's not required though.
4545
try:
4646
raise ImportError # currently it's borked by the unicode support
47-
47+
4848
from _pyrepl_utils import disp_str, init_unctrl_map
49-
49+
5050
init_unctrl_map(_make_unctrl_map())
5151

5252
del init_unctrl_map
@@ -118,7 +118,7 @@ def make_default_syntax_table():
118118
(r'\C-x\C-u', 'upcase-region'),
119119
(r'\C-y', 'yank'),
120120
(r'\C-z', 'suspend'),
121-
121+
122122
(r'\M-b', 'backward-word'),
123123
(r'\M-c', 'capitalize-word'),
124124
(r'\M-d', 'kill-word'),
@@ -303,7 +303,7 @@ def calc_screen(self):
303303

304304
def process_prompt(self, prompt):
305305
""" Process the prompt.
306-
306+
307307
This means calculate the length of the prompt. The character \x01
308308
and \x02 are used to bracket ANSI control sequences and need to be
309309
excluded from the length calculation. So also a copy of the prompt
@@ -372,7 +372,7 @@ def bol(self, p=None):
372372
while p >= 0 and b[p] <> '\n':
373373
p -= 1
374374
return p + 1
375-
375+
376376
def eol(self, p=None):
377377
"""Return the 0-based index of the line break following p most
378378
immediately.
@@ -463,7 +463,7 @@ def after_command(self, cmd):
463463
"""This function is called to allow post command cleanup."""
464464
if getattr(cmd, "kills_digit_arg", 1):
465465
if self.arg is not None:
466-
self.dirty = 1
466+
self.dirty = 1
467467
self.arg = None
468468

469469
def prepare(self):
@@ -575,13 +575,15 @@ def handle1(self, block=1):
575575
def push_char(self, char):
576576
self.console.push_char(char)
577577
self.handle1(0)
578-
579-
def readline(self, returns_unicode=False):
578+
579+
def readline(self, returns_unicode=False, startup_hook=None):
580580
"""Read a line. The implementation of this method also shows
581581
how to drive Reader if you want more control over the event
582582
loop."""
583583
self.prepare()
584584
try:
585+
if startup_hook is not None:
586+
startup_hook()
585587
self.refresh()
586588
while not self.finished:
587589
self.handle1()

pyrepl/readline.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,8 @@ def raw_input(self, prompt=''):
193193
reader = self.get_reader()
194194
except _error:
195195
return _old_raw_input(prompt)
196-
if self.startup_hook is not None:
197-
self.startup_hook()
198196
reader.ps1 = prompt
199-
return reader.readline()
197+
return reader.readline(reader, startup_hook=self.startup_hook)
200198

201199
def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
202200
"""Read an input on possibly multiple lines, asking for more
@@ -390,7 +388,7 @@ def _setup():
390388
global _old_raw_input
391389
if _old_raw_input is not None:
392390
return # don't run _setup twice
393-
391+
394392
try:
395393
f_in = sys.stdin.fileno()
396394
f_out = sys.stdout.fileno()

0 commit comments

Comments
 (0)