From arigo at codespeak.net Sat Jun 19 16:34:11 2010 From: arigo at codespeak.net (arigo at codespeak.net) Date: Sat, 19 Jun 2010 16:34:11 +0200 (CEST) Subject: [pyrepl-checkins] r75471 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20100619143411.31E01282BD4@codespeak.net> 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' From antocuni at codespeak.net Mon Jun 21 14:33:35 2010 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Mon, 21 Jun 2010 14:33:35 +0200 (CEST) Subject: [pyrepl-checkins] r75481 - pyrepl/trunk/pyrepl/pyrepl Message-ID: <20100621123335.47656282BAD@codespeak.net> Author: antocuni Date: Mon Jun 21 14:33:32 2010 New Revision: 75481 Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py Log: don't propagate exceptions raised inside the completer. This mimic the behavior of cpython's readline, and it's very unpleasant to see your interpreter crashing just because you hit and there is an error in the completer Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py ============================================================================== --- pyrepl/trunk/pyrepl/pyrepl/readline.py (original) +++ pyrepl/trunk/pyrepl/pyrepl/readline.py Mon Jun 21 14:33:32 2010 @@ -68,7 +68,10 @@ pass # but feed unicode anyway if we have no choice state = 0 while True: - next = function(stem, state) + try: + next = function(stem, state) + except: + break if not isinstance(next, str): break result.append(next)