Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)
Retrieves the user input with a formatted prompt. Return the value when
the value entered by the user matches all validations. The validations is a
list of tuple. The first element of the tuple is the regexp, the second is
the error message when the input does not match the regexp.

        def cinput(prompt, validations=[], secret=False):
    """ Retrieves the user input with a formatted prompt. Return the value when
    the value entered by the user matches all validations. The validations is a
    list of tuple. The first element of the tuple is the regexp, the second is
    the error message when the input does not match the regexp.
    """

    # The future return value.
    ret = None

    # Iterate until input matches all validations.
    while True:
        valid = True

        # Get the user input and put it into ret.
        colored_prompt = colored(prompt, attrs=['bold'])
        ret = getpass(prompt=colored_prompt) if secret else \
            input(colored_prompt)

        # Iterates over validations...
        for validation, possible_err in validations:
            if not match(validation, ret):
                # The input is not valid. Print an error message and set the
                # valid flag to False to avoid to exit the while True loop.
                cerr(possible_err)
                valid = False

        # Exit the loop if the valid flag is True.
        if valid:
            break

    return ret
        


src/b/a/baboon-0.1.4/baboon/baboon/commands.py   baboon(Download)
from baboon.baboon.initializor import MetadirController
from baboon.baboon.transport import RegisterTransport, AdminTransport
from baboon.baboon.fmt import cinput, confirm_cinput, cwarn, csuccess, cerr
 
from baboon.baboon.config import check_user, check_server, check_project
        validations = [('^\w+$', 'Username can only contains alphanumeric and '
                        'underscore characters')]
        username = cinput('Username: ', validations=validations)
 
    # Transform the username to a JID.

src/b/a/baboon-HEAD/baboon/baboon/commands.py   baboon(Download)
from baboon.baboon.initializor import MetadirController
from baboon.baboon.transport import RegisterTransport, AdminTransport
from baboon.baboon.fmt import cinput, confirm_cinput, cwarn, csuccess, cerr
from baboon.baboon.notifier import Notifier
 
        validations = [('^\w+$', 'Username can only contains alphanumeric and '
                        'underscore characters')]
        username = cinput('Username: ', validations=validations)
 
    # Transform the username to a JID.