<gh_stars>1-10
# prompt.py - Helper to prompt the user for text and confirmations 
# coding: utf-8
# 
# Copyright 2010 Guardis SPRL, Liège, Belgium.
# Authors: <NAME> <<EMAIL>>
#
# This software cannot be used and/or distributed without prior 
# authorization from Guardis.

from __future__ import print_function

## {{{ http://code.activestate.com/recipes/541096/ (r1)
from builtins import input
def confirm(prompt=None, resp=False):
    """prompts for yes or no response from the user. Returns True for yes and
    False for no.

    'resp' should be set to the default value assumed by the caller when
    user simply types ENTER.

    >>> confirm(prompt='Create Directory?', resp=True)
    Create Directory? [y]|n: 
    True
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y: 
    False
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y: y
    True

    """
    
    if prompt is None:
        prompt = 'Confirm'

    if resp:
        prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n')
    else:
        prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y')
        
    while True:
        ans = input(prompt)
        if not ans:
            return resp
        if ans not in ['y', 'Y', 'n', 'N']:
            print('please enter y or n.')
            continue
        if ans == 'y' or ans == 'Y':
            return True
        if ans == 'n' or ans == 'N':
            return False
## end of http://code.activestate.com/recipes/541096/ }}}

def raw_input_default(prompt, default=None):
    """prompts the user for a string, proposing a default value in brackets."""
    
    if default:
        prompt = "%s [%s]: " % (prompt, default)
    res = input(prompt)
    if not res and default:
        return default
    return res
# prompt.py - Helper to prompt the user for text and confirmations 
# coding: utf-8
# 
# Copyright 2010 Guardis SPRL, Liège, Belgium.
# Authors: <NAME> <<EMAIL>>
#
# This software cannot be used and/or distributed without prior 
# authorization from Guardis.

from __future__ import print_function

## {{{ http://code.activestate.com/recipes/541096/ (r1)
from builtins import input
def confirm(prompt=None, resp=False):
    """prompts for yes or no response from the user. Returns True for yes and
    False for no.

    'resp' should be set to the default value assumed by the caller when
    user simply types ENTER.

    >>> confirm(prompt='Create Directory?', resp=True)
    Create Directory? [y]|n: 
    True
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y: 
    False
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y: y
    True

    """
    
    if prompt is None:
        prompt = 'Confirm'

    if resp:
        prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n')
    else:
        prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y')
        
    while True:
        ans = input(prompt)
        if not ans:
            return resp
        if ans not in ['y', 'Y', 'n', 'N']:
            print('please enter y or n.')
            continue
        if ans == 'y' or ans == 'Y':
            return True
        if ans == 'n' or ans == 'N':
            return False
## end of http://code.activestate.com/recipes/541096/ }}}

def raw_input_default(prompt, default=None):
    """prompts the user for a string, proposing a default value in brackets."""
    
    if default:
        prompt = "%s [%s]: " % (prompt, default)
    res = input(prompt)
    if not res and default:
        return default
    return res
# prompt.py - Helper to prompt the user for text and confirmations # coding: utf-8 # # Copyright 2010 Guardis SPRL, Liège, Belgium. # Authors: <NAME> <<EMAIL>> # # This software cannot be used and/or distributed without prior # authorization from Guardis. ## {{{ http://code.activestate.com/recipes/541096/ (r1) prompts for yes or no response from the user. Returns True for yes and     False for no.      'resp' should be set to the default value assumed by the caller when     user simply types ENTER.      >>> confirm(prompt='Create Directory?', resp=True)     Create Directory? [y]|n:      True     >>> confirm(prompt='Create Directory?', resp=False)     Create Directory? [n]|y:      False     >>> confirm(prompt='Create Directory?', resp=False)     Create Directory? [n]|y: y     True ## end of http://code.activestate.com/recipes/541096/ }}} prompts the user for a string, proposing a default value in brackets.