(desc,
                     key=None,
                     note=None,
                     default=None,
                     validate=None,
                     yes_or_no=False,
                     password=False)
Ask a question, return the answer.
        @desc description, e.g. "What is the port of ccnet?"

        @key a name to represent the target of the question, e.g. "port for
        ccnet server"

        @note additional information for the question, e.g. "Must be a valid
        port number"

        @default the default value of the question. If the default value is
        not None, when the user enter nothing and press [ENTER], the default
        value would be returned

        @validate a function that takes the user input as the only parameter
        and validate it. It should return a validated value, or throws an
        "InvalidAnswer" exception if the input is not valid.

        @yes_or_no If true, the user must answer "yes" or "no", and a boolean
        value would be returned

        @password If true, the user input would not be echoed to the
        console
Ask a question, return the answer.
        @desc description, e.g. "What is the port of ccnet?"
Ask a question return the answer . @desc description e . g . What is the port of ccnet?
def ask_question(desc,
                     key=None,
                     note=None,
                     default=None,
                     validate=None,
                     yes_or_no=False,
                     password=False):
        '''Ask a question, return the answer.
        @desc description, e.g. "What is the port of ccnet?"

        @key a name to represent the target of the question, e.g. "port for
        ccnet server"

        @note additional information for the question, e.g. "Must be a valid
        port number"

        @default the default value of the question. If the default value is
        not None, when the user enter nothing and press [ENTER], the default
        value would be returned

        @validate a function that takes the user input as the only parameter
        and validate it. It should return a validated value, or throws an
        "InvalidAnswer" exception if the input is not valid.

        @yes_or_no If true, the user must answer "yes" or "no", and a boolean
        value would be returned

        @password If true, the user input would not be echoed to the
        console

        '''
        assert key or yes_or_no
        # Format description
        print()
        if note:
            desc += '\n' + note

        desc += '\n'
        if yes_or_no:
            desc += '[ yes or no ]'
        else:
            if default:
                desc += '[ default "%s" ]' % default
            else:
                desc += '[ %s ]' % key

        desc += ' '
        while True:
            # prompt for user input
            if password:
                answer = getpass.getpass(desc).strip()
            else:
                answer = input(desc).strip()

            # No user input: use default
            if not answer:
                if default:
                    answer = default
                else:
                    continue

            # Have user input: validate answer
            if yes_or_no:
                if answer not in ['yes', 'no']:
                    print(Utils.highlight('\nPlease answer yes or no\n'))
                    continue
                else:
                    return answer == 'yes'
            else:
                if validate:
                    try:
                        return validate(answer)
                    except InvalidAnswer as e:
                        print(Utils.highlight('\n%s\n' % e))
                        continue
                else:
                    return answer
def ask_question ( desc , key = None , note = None , default = None , validate = None , yes_or_no = False , password = False ) : assert key or yes_or_no # Format description print ( ) if note : desc += '\n' + note desc += '\n' if yes_or_no : desc += '[ yes or no ]' else : if default : desc += '[ default "%s" ]' % default else : desc += '[ %s ]' % key desc += ' ' while True : # prompt for user input if password : answer = getpass . getpass ( desc ) . strip ( ) else : answer = input ( desc ) . strip ( ) # No user input: use default if not answer : if default : answer = default else : continue # Have user input: validate answer if yes_or_no : if answer not in [ 'yes' , 'no' ] : print ( Utils . highlight ( '\nPlease answer yes or no\n' ) ) continue else : return answer == 'yes' else : if validate : try : return validate ( answer ) except InvalidAnswer as e : print ( Utils . highlight ( '\n%s\n' % e ) ) continue else : return answer