From 6096cb39b48b434c34746aed87971807be772e92 2006-06-04 00:57:43 From: fperez Date: 2006-06-04 00:57:43 Subject: [PATCH] fix ask_yes_no so it does not loop 20 times upon EOF. --- diff --git a/IPython/genutils.py b/IPython/genutils.py index 01a908a..7e348e4 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -5,7 +5,7 @@ General purpose utilities. This is a grab-bag of stuff I find useful in most programs I write. Some of these things are also convenient when working at the command line. -$Id: genutils.py 1322 2006-05-24 07:51:39Z fperez $""" +$Id: genutils.py 1349 2006-06-04 00:57:43Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -992,28 +992,27 @@ def ask_yes_no(prompt,default=None): If default is given (one of 'y','n'), it is used if the user input is empty. Otherwise the question is repeated until an answer is given. - If EOF occurs 20 times consecutively, the default answer is assumed, - or if there is no default, an exception is raised to prevent infinite - loops. + + An EOF is treated as the default answer. If there is no default, an + exception is raised to prevent infinite loops. Valid answers are: y/yes/n/no (match is not case sensitive).""" answers = {'y':True,'n':False,'yes':True,'no':False} ans = None - eofs, max_eofs = 0, 20 while ans not in answers.keys(): try: ans = raw_input(prompt+' ').lower() if not ans: # response was an empty string ans = default - eofs = 0 - except (EOFError,KeyboardInterrupt): - eofs = eofs + 1 - if eofs >= max_eofs: - if default in answers.keys(): - ans = default - else: - raise + except KeyboardInterrupt: + pass + except EOFError: + if default in answers.keys(): + ans = default + print + else: + raise return answers[ans] diff --git a/doc/ChangeLog b/doc/ChangeLog index 2320998..f9a7fa1 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,8 @@ 2006-06-03 Fernando Perez + * IPython/genutils.py (ask_yes_no): treat EOF as a default answer + instead of looping 20 times. + * IPython/ipmaker.py (make_IPython): honor -ipythondir flag correctly at initialization time. Bug reported by Krishna Mohan Gundu on the user list.