diff --git a/IPython/Extensions/ibrowse.py b/IPython/Extensions/ibrowse.py index da8f9e5..fdbe110 100644 --- a/IPython/Extensions/ibrowse.py +++ b/IPython/Extensions/ibrowse.py @@ -149,7 +149,7 @@ class _BrowserLevel(object): # position of cursor and screen, etc.) of one browser level # An ``ibrowse`` object keeps multiple ``_BrowserLevel`` objects in # a stack. - def __init__(self, browser, input,mainsizey, *attrs): + def __init__(self, browser, input, mainsizey, *attrs): self.browser = browser self.input = input self.header = [x for x in ipipe.xrepr(input, "header") if not isinstance(x[0], int)] @@ -925,23 +925,27 @@ class ibrowse(ipipe.Display): Enter the object ``item``. If ``attrs`` is specified, it will be used as a fixed list of attributes to display. """ - oldlevels = len(self.levels) - self._calcheaderlines(oldlevels+1) - try: - level = _BrowserLevel( - self, - item, - self.scrsizey-1-self._headerlines-2, - *attrs - ) - except (KeyboardInterrupt, SystemExit): - raise - except Exception, exc: - self._calcheaderlines(oldlevels) + if self.levels and item is self.levels[-1].input: curses.beep() - self.report(exc) + self.report(CommandError("Recursion on input object")) else: - self.levels.append(level) + oldlevels = len(self.levels) + self._calcheaderlines(oldlevels+1) + try: + level = _BrowserLevel( + self, + item, + self.scrsizey-1-self._headerlines-2, + *attrs + ) + except (KeyboardInterrupt, SystemExit): + raise + except Exception, exc: + self._calcheaderlines(oldlevels) + curses.beep() + self.report(exc) + else: + self.levels.append(level) def startkeyboardinput(self, mode): """ diff --git a/IPython/Extensions/ipipe.py b/IPython/Extensions/ipipe.py index 6dc92bf..eb82580 100644 --- a/IPython/Extensions/ipipe.py +++ b/IPython/Extensions/ipipe.py @@ -943,7 +943,13 @@ def xiter(item): elif _isstr(item): if not item: raise ValueError("can't enter empty string") - return iter(item.splitlines()) + lines = item.splitlines() + if len(lines) == 1: + def iterone(item): + yield item + return iterone(item) + else: + return iter(lines) return iter(item) else: return iter(func()) # iter() just to be safe diff --git a/doc/ChangeLog b/doc/ChangeLog index 606cb6f..8d87ca7 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,13 @@ +2007-01-23 Walter Doerwald + + * IPython/Extensions/ipipe.py (xiter): Make sure that iterating + a string containing a single line yields the string itself as the + only item. + + * IPython/Extensions/ibrowse.py (ibrowse): Avoid entering an + object if it's the same as the one on the last level (This avoids + infinite recursion for one line strings). + 2007-01-17 Fernando Perez * IPython/ultraTB.py (AutoFormattedTB.__call__): properly flush