Commits

David Ripton committed c8bec90

(hpaulj) Fix startup_hook in readline to work like CPython. Fixes issue950

Comments (0)

Files changed (2)

lib_pypy/pyrepl/reader.py

     for i in range(256):
         c = unichr(i)
         if not uc_map.has_key(c):
-            uc_map[c] = u'\\%03o'%i 
+            uc_map[c] = u'\\%03o'%i
     return uc_map
 
 # disp_str proved to be a bottleneck for large inputs, so it's been
 # rewritten in C; it's not required though.
 try:
     raise ImportError # currently it's borked by the unicode support
-    
+
     from _pyrepl_utils import disp_str, init_unctrl_map
-    
+
     init_unctrl_map(_make_unctrl_map())
 
     del init_unctrl_map
      (r'\C-x\C-u', 'upcase-region'),
      (r'\C-y', 'yank'),
      (r'\C-z', 'suspend'),
-     
+
      (r'\M-b', 'backward-word'),
      (r'\M-c', 'capitalize-word'),
      (r'\M-d', 'kill-word'),
 
     def process_prompt(self, prompt):
         """ Process the prompt.
-        
+
         This means calculate the length of the prompt. The character \x01
         and \x02 are used to bracket ANSI control sequences and need to be
         excluded from the length calculation.  So also a copy of the prompt
         while p >= 0 and b[p] <> '\n':
             p -= 1
         return p + 1
-    
+
     def eol(self, p=None):
         """Return the 0-based index of the line break following p most
         immediately.
         """This function is called to allow post command cleanup."""
         if getattr(cmd, "kills_digit_arg", 1):
             if self.arg is not None:
-                self.dirty = 1                
+                self.dirty = 1
             self.arg = None
 
     def prepare(self):
     def push_char(self, char):
         self.console.push_char(char)
         self.handle1(0)
-    
-    def readline(self, returns_unicode=False):
+
+    def readline(self, returns_unicode=False, startup_hook=None):
         """Read a line.  The implementation of this method also shows
         how to drive Reader if you want more control over the event
         loop."""
         self.prepare()
         try:
+            if startup_hook is not None:
+                startup_hook()
             self.refresh()
             while not self.finished:
                 self.handle1()

lib_pypy/pyrepl/readline.py

             reader = self.get_reader()
         except _error:
             return _old_raw_input(prompt)
-        if self.startup_hook is not None:
-            self.startup_hook()
         reader.ps1 = prompt
-        return reader.readline()
+        return reader.readline(reader, startup_hook=self.startup_hook)
 
     def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
         """Read an input on possibly multiple lines, asking for more
     global _old_raw_input
     if _old_raw_input is not None:
         return # don't run _setup twice
-    
+
     try:
         f_in = sys.stdin.fileno()
         f_out = sys.stdout.fileno()