r75471 - pyrepl/trunk/pyrepl/pyrepl

[email protected] Sat, 19 Jun 2010 16:34:11 +0200 (CEST)
Newsgroups gmane.comp.python.pyrepl.checkins
Message-ID <[email protected]>
Author: arigo
Date: Sat Jun 19 16:34:09 2010
New Revision: 75471

Modified:
   pyrepl/trunk/pyrepl/pyrepl/curses.py
   pyrepl/trunk/pyrepl/pyrepl/readline.py
   pyrepl/trunk/pyrepl/pyrepl/simple_interact.py
   pyrepl/trunk/pyrepl/pyrepl/unix_console.py
Log:
Accept UnixConsole.__init__() raising curses.error, and in the
readline emulation mode fall back silently to the built-in
raw_input().


Modified: pyrepl/trunk/pyrepl/pyrepl/curses.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/curses.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/curses.py	Sat Jun 19 16:34:09 2010
@@ -16,3 +16,4 @@
 setupterm = _curses.setupterm
 tigetstr = _curses.tigetstr
 tparm = _curses.tparm
+error = _curses.error

Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/readline.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/readline.py	Sat Jun 19 16:34:09 2010
@@ -7,7 +7,7 @@
 from pyrepl import commands
 from pyrepl.historical_reader import HistoricalReader
 from pyrepl.completing_reader import CompletingReader
-from pyrepl.unix_console import UnixConsole
+from pyrepl.unix_console import UnixConsole, _error
 
 
 ENCODING = 'latin1'     # XXX hard-coded
@@ -161,7 +161,10 @@
         return self.reader
 
     def raw_input(self, prompt=''):
-        reader = self.get_reader()
+        try:
+            reader = self.get_reader()
+        except _error:
+            return _old_raw_input(prompt)
         if self.startup_hook is not None:
             self.startup_hook()
         reader.ps1 = prompt
@@ -327,6 +330,7 @@
 # ____________________________________________________________
 
 def _setup():
+    global _old_raw_input
     try:
         f_in = sys.stdin.fileno()
         f_out = sys.stdout.fileno()
@@ -339,10 +343,12 @@
     _wrapper.f_out = f_out
 
     if hasattr(sys, '__raw_input__'):    # PyPy
+        _old_raw_input = sys.__raw_input__
         sys.__raw_input__ = _wrapper.raw_input
     else:
         # this is not really what readline.c does.  Better than nothing I guess
         import __builtin__
+        _old_raw_input = __builtin__.raw_input
         __builtin__.raw_input = _wrapper.raw_input
 
 _setup()

Modified: pyrepl/trunk/pyrepl/pyrepl/simple_interact.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/simple_interact.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/simple_interact.py	Sat Jun 19 16:34:09 2010
@@ -4,13 +4,12 @@
 """
 
 import sys
-from pyrepl.readline import multiline_input, _get_reader
+from pyrepl.readline import multiline_input, _error, _get_reader
 
 def check():     # returns False if there is a problem initializing the state
-    import termios
     try:
         _get_reader()
-    except termios.error:
+    except _error:
         return False
     return True
 

Modified: pyrepl/trunk/pyrepl/pyrepl/unix_console.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/unix_console.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/unix_console.py	Sat Jun 19 16:34:09 2010
@@ -25,6 +25,8 @@
 from pyrepl.console import Console, Event
 from pyrepl import unix_eventqueue
 
+_error = (termios.error, curses.error)
+
 # there are arguments for changing this to "refresh"
 SIGWINCH_EVENT = 'repaint'