minchin/text.py
def query_yes_quit(question, default="quit"):
    '''Ask a yes/quit question via raw_input() and return their answer.

    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "quit" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "quit".

    Modified from
    http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
    '''
    valid = {"yes": Answers.YES,   "y": Answers.YES,  "ye": Answers.YES,
             "quit": Answers.QUIT, "q": Answers.QUIT}
    if default is None:
        prompt = " [y/q] "
    elif default == "yes":
        prompt = " [Y/q] "
    elif default == "quit":
        prompt = " [y/Q] "
    else:
        raise ValueError("invalid default answer: '%s'" % default)

    while True:
        sys.stdout.write(question + prompt)
        choice = input().lower()
        if default is not None and choice == '':
            return valid[default]
        elif choice in valid:
            return valid[choice]
        else:
            sys.stdout.write("Please respond with 'yes' or 'quit' "
                             "(or 'y' or 'q').\n")
def query_yes_quit(question, default="quit"):
    '''Ask a yes/quit question via raw_input() and return their answer.

    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "quit" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "quit".

    Modified from
    http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
    '''
    valid = {"yes": Answers.YES,   "y": Answers.YES,  "ye": Answers.YES,
             "quit": Answers.QUIT, "q": Answers.QUIT}
    if default is None:
        prompt = " [y/q] "
    elif default == "yes":
        prompt = " [Y/q] "
    elif default == "quit":
        prompt = " [y/Q] "
    else:
        raise ValueError("invalid default answer: '%s'" % default)

    while True:
        sys.stdout.write(question + prompt)
        choice = input().lower()
        if default is not None and choice == '':
            return valid[default]
        elif choice in valid:
            return valid[choice]
        else:
            sys.stdout.write("Please respond with 'yes' or 'quit' "
                             "(or 'y' or 'q').\n")
def query_yes_quit ( question , default = "quit" ) : valid = { "yes" : Answers . YES , "y" : Answers . YES , "ye" : Answers . YES , "quit" : Answers . QUIT , "q" : Answers . QUIT } if default is None : prompt = " [y/q] " elif default == "yes" : prompt = " [Y/q] " elif default == "quit" : prompt = " [y/Q] " else : raise ValueError ( "invalid default answer: '%s'" % default ) while True : sys . stdout . write ( question + prompt ) choice = input ( ) . lower ( ) if default is not None and choice == '' : return valid [ default ] elif choice in valid : return valid [ choice ] else : sys . stdout . write ( "Please respond with 'yes' or 'quit' " "(or 'y' or 'q').\n" )
Ask a yes/quit question via raw_input() and return their answer.

    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "quit" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "quit".

    Modified from
    http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
Ask a yes / quit question via raw_input () and return their answer .