From d6fd1d8ae260543b4107e0581fab1ec0ea18052d 2010-01-01 04:32:18 From: Fernando Perez Date: 2010-01-01 04:32:18 Subject: [PATCH] Fix quitting: now, typing bare 'exit' or 'quit' unconditionally quits. We still ask for confirmation by default with C-d (EOF), since that can happen accidentally quite easily (though users can always disble that safety if desired). --- diff --git a/IPython/core/hooks.py b/IPython/core/hooks.py index 60e7687..79eb5ba 100644 --- a/IPython/core/hooks.py +++ b/IPython/core/hooks.py @@ -137,8 +137,7 @@ class CommandChainDispatcher: for prio,cmd in self.chain: #print "prio",prio,"cmd",cmd #dbg try: - ret = cmd(*args, **kw) - return ret + return cmd(*args, **kw) except TryNext, exc: if exc.args or exc.kwargs: args = exc.args diff --git a/IPython/core/iplib.py b/IPython/core/iplib.py index 2e8f190..823a2f1 100644 --- a/IPython/core/iplib.py +++ b/IPython/core/iplib.py @@ -2461,7 +2461,7 @@ class InteractiveShell(Component, Magic): #------------------------------------------------------------------------- def ask_exit(self): - """ Call for exiting. Can be overiden and used as a callback. """ + """ Ask the shell to exit. Can be overiden and used as a callback. """ self.exit_now = True def exit(self): diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 1f64083..879047d 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2533,20 +2533,7 @@ Defaulting color scheme to 'NoColor'""" self.shell.pprint = 1 - self.shell.pprint print 'Pretty printing has been turned', \ ['OFF','ON'][self.shell.pprint] - - def magic_exit(self, parameter_s=''): - """Exit IPython, confirming if configured to do so. - - You can configure whether IPython asks for confirmation upon exit by - setting the confirm_exit flag in the ipythonrc file.""" - - self.shell.exit() - - def magic_quit(self, parameter_s=''): - """Exit IPython, confirming if configured to do so (like %exit)""" - - self.shell.exit() - + def magic_Exit(self, parameter_s=''): """Exit IPython without confirmation.""" diff --git a/IPython/core/prompts.py b/IPython/core/prompts.py index 228edb7..c382a9e 100644 --- a/IPython/core/prompts.py +++ b/IPython/core/prompts.py @@ -533,6 +533,20 @@ class CachedOutput: except KeyError: pass if arg is not None: + + # and now call a possibly user-defined print mechanism + try: + manipulated_val = self.display(arg) + except TypeError: + # If the user's display hook didn't return a string we can + # print, we're done. Happens commonly if they return None + return + + # user display hooks can change the variable to be stored in + # output history + if manipulated_val is not None: + arg = manipulated_val + cout_write = Term.cout.write # fast lookup # first handle the cache and counters @@ -552,15 +566,6 @@ class CachedOutput: else: print "self.do_full_cache = False" - # and now call a possibly user-defined print mechanism - manipulated_val = self.display(arg) - - # user display hooks can change the variable to be stored in - # output history - - if manipulated_val is not None: - arg = manipulated_val - # avoid recursive reference when displaying _oh/Out if arg is not self.user_ns['_oh']: self.update(arg) diff --git a/IPython/core/quitter.py b/IPython/core/quitter.py old mode 100644 new mode 100755 index f7151f1..850ace2 --- a/IPython/core/quitter.py +++ b/IPython/core/quitter.py @@ -1,10 +1,10 @@ -#!/usr/bin/env python -# encoding: utf-8 +# coding: utf-8 """ A simple class for quitting IPython. -Authors: - +Authors +------- +* Fernando Perez * Brian Granger """ @@ -19,6 +19,7 @@ Authors: # Imports #----------------------------------------------------------------------------- +import sys class Quitter(object): """Simple class to handle exit, similar to Python 2.5's. @@ -30,9 +31,10 @@ class Quitter(object): self.shell = shell self.name = name - def __repr__(self): + def __str__(self): return 'Type %s() to exit.' % self.name - __str__ = __repr__ def __call__(self): - self.shell.exit() \ No newline at end of file + self.shell.ask_exit() + + __repr__ = __call__ diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 9e39be4..d72e08f 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -11,6 +11,7 @@ from cStringIO import StringIO import nose.tools as nt +from IPython.core.iplib import get_ipython from IPython.utils.platutils import find_cmd, get_long_path_name from IPython.testing import decorators as dec from IPython.testing import tools as tt