def query_cast(value, answers, ignorecase = False):
    """A cast function for query
    
    Answers should look something like it does in query
    """
    if ignorecase: value = value.lower()
    for item in answers:
        for a in item['values']:
            if ignorecase and (value == str(a).lower()):
                return item['values'][0]
            elif value == a:
                return item['values'][0]
    raise ValueError("Response '%s' not understood, please try again." % value)
A cast function for query
    
    Answers should look something like it does in query