[pyrepl-checkins] r53592 - pyrepl/trunk/pyrepl/pyrepl

arigo at codespeak.net arigo at codespeak.net
Tue Apr 8 19:13:22 CEST 2008


Author: arigo
Date: Tue Apr  8 19:13:21 2008
New Revision: 53592

Modified:
   pyrepl/trunk/pyrepl/pyrepl/readline.py
Log:
Try hard to prevent raw_input() from returning a multiline string.


Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/readline.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/readline.py	Tue Apr  8 19:13:21 2008
@@ -104,6 +104,22 @@
         self.commands['maybe_accept'] = maybe_accept
         self.commands['maybe-accept'] = maybe_accept
 
+    def after_command(self, cmd):
+        super(ReadlineAlikeReader, self).after_command(cmd)
+        if self.more_lines is None:
+            # Force single-line input if we are in raw_input() mode.
+            # Although there is no direct way to add a \n in this mode,
+            # multiline buffers can still show up using various
+            # commands, e.g. navigating the history.
+            try:
+                index = self.buffer.index("\n")
+            except ValueError:
+                pass
+            else:
+                self.buffer = self.buffer[:index]
+                if self.pos > len(self.buffer):
+                    self.pos = len(self.buffer)
+
 class maybe_accept(commands.Command):
     def do(self):
         r = self.reader


More information about the pyrepl-checkins mailing list