#NEWLINE# def answer_question( call_log_entry , recipient , input_data , logged_subevent = None ) : #NEWLINE# #INDENT# '\n    Returns a list of (responses, answer_is_valid), where responses is the\n    list of XFormsResponse objects from touchforms and answer_is_valid is\n    True if input_data passes validation and False if not.\n\n    Returning an empty list for responses will end up forcing a hangup\n    later on in the workflow.\n    ' #NEWLINE# if ( logged_subevent . xforms_session_id is None ) : #NEWLINE# #INDENT# return ( [ ] , None ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# current_q = current_question ( call_log_entry . xforms_session_id ) #NEWLINE# #UNINDENT# except TouchformsError as e : #NEWLINE# #INDENT# log_touchforms_error ( e , call_log_entry , logged_subevent ) #NEWLINE# return ( [ ] , None ) #NEWLINE# #UNINDENT# if ( current_q . status == 'http-error' ) : #NEWLINE# #INDENT# log_error ( MessagingEvent . ERROR_TOUCHFORMS_ERROR , call_log_entry , logged_subevent ) #NEWLINE# return ( [ ] , None ) #NEWLINE# #UNINDENT# if validate_answer ( input_data , current_q ) : #NEWLINE# #INDENT# answer_is_valid = True #NEWLINE# try : #NEWLINE# #INDENT# responses = _get_responses ( recipient . domain , recipient . _id , input_data , yield_responses = True , session_id = call_log_entry . xforms_session_id ) #NEWLINE# #UNINDENT# except TouchformsError as e : #NEWLINE# #INDENT# log_touchforms_error ( e , call_log_entry , logged_subevent ) #NEWLINE# return ( [ ] , None ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# answer_is_valid = False #NEWLINE# call_log_entry . current_question_retry_count += 1 #NEWLINE# responses = [ current_q ] #NEWLINE# #UNINDENT# return ( responses , answer_is_valid )