def validate_answer(answer, question):
    """
    Return True if answer is a valid response to question, False if not.
    (question is expected to be the XFormsResponse object for the question)
    """
    if question.event.datatype == "select":
        try:
            assert answer is not None
            answer = int(answer)
            assert answer >= 1 and answer <= len(question.event.choices)
            return True
        except (ValueError, AssertionError):
            return False
    else:
        try:
            assert answer is not None
            if isinstance(answer, basestring):
                assert len(answer.strip()) > 0
            return True
        except __HOLE__:
            return False
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/ivr/api.py/validate_answer