Show More
@@ -5,7 +5,7 b' General purpose utilities.' | |||||
5 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
|
5 | This is a grab-bag of stuff I find useful in most programs I write. Some of | |
6 | these things are also convenient when working at the command line. |
|
6 | these things are also convenient when working at the command line. | |
7 |
|
7 | |||
8 |
$Id: genutils.py 13 |
|
8 | $Id: genutils.py 1349 2006-06-04 00:57:43Z fperez $""" | |
9 |
|
9 | |||
10 | #***************************************************************************** |
|
10 | #***************************************************************************** | |
11 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
|
11 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | |
@@ -992,28 +992,27 b' def ask_yes_no(prompt,default=None):' | |||||
992 |
|
992 | |||
993 | If default is given (one of 'y','n'), it is used if the user input is |
|
993 | If default is given (one of 'y','n'), it is used if the user input is | |
994 | empty. Otherwise the question is repeated until an answer is given. |
|
994 | empty. Otherwise the question is repeated until an answer is given. | |
995 | If EOF occurs 20 times consecutively, the default answer is assumed, |
|
995 | ||
996 | or if there is no default, an exception is raised to prevent infinite |
|
996 | An EOF is treated as the default answer. If there is no default, an | |
997 | loops. |
|
997 | exception is raised to prevent infinite loops. | |
998 |
|
998 | |||
999 | Valid answers are: y/yes/n/no (match is not case sensitive).""" |
|
999 | Valid answers are: y/yes/n/no (match is not case sensitive).""" | |
1000 |
|
1000 | |||
1001 | answers = {'y':True,'n':False,'yes':True,'no':False} |
|
1001 | answers = {'y':True,'n':False,'yes':True,'no':False} | |
1002 | ans = None |
|
1002 | ans = None | |
1003 | eofs, max_eofs = 0, 20 |
|
|||
1004 | while ans not in answers.keys(): |
|
1003 | while ans not in answers.keys(): | |
1005 | try: |
|
1004 | try: | |
1006 | ans = raw_input(prompt+' ').lower() |
|
1005 | ans = raw_input(prompt+' ').lower() | |
1007 | if not ans: # response was an empty string |
|
1006 | if not ans: # response was an empty string | |
1008 | ans = default |
|
1007 | ans = default | |
1009 | eofs = 0 |
|
1008 | except KeyboardInterrupt: | |
1010 | except (EOFError,KeyboardInterrupt): |
|
1009 | pass | |
1011 | eofs = eofs + 1 |
|
1010 | except EOFError: | |
1012 | if eofs >= max_eofs: |
|
1011 | if default in answers.keys(): | |
1013 |
|
|
1012 | ans = default | |
1014 |
|
|
1013 | ||
1015 |
|
|
1014 | else: | |
1016 |
|
|
1015 | raise | |
1017 |
|
1016 | |||
1018 | return answers[ans] |
|
1017 | return answers[ans] | |
1019 |
|
1018 |
@@ -1,5 +1,8 b'' | |||||
1 | 2006-06-03 Fernando Perez <Fernando.Perez@colorado.edu> |
|
1 | 2006-06-03 Fernando Perez <Fernando.Perez@colorado.edu> | |
2 |
|
2 | |||
|
3 | * IPython/genutils.py (ask_yes_no): treat EOF as a default answer | |||
|
4 | instead of looping 20 times. | |||
|
5 | ||||
3 | * IPython/ipmaker.py (make_IPython): honor -ipythondir flag |
|
6 | * IPython/ipmaker.py (make_IPython): honor -ipythondir flag | |
4 | correctly at initialization time. Bug reported by Krishna Mohan |
|
7 | correctly at initialization time. Bug reported by Krishna Mohan | |
5 | Gundu <gkmohan-AT-gmail.com> on the user list. |
|
8 | Gundu <gkmohan-AT-gmail.com> on the user list. |
General Comments 0
You need to be logged in to leave comments.
Login now