def _handle_structured_sms(domain, args, contact_id, session_id, first_question, verified_number, xpath_answer=None): form_complete = False current_question = first_question internal_error_msg = get_message(MSG_TOUCHFORMS_DOWN, verified_number) used_named_args = xpath_answer is not None answer_num = 0 while not form_complete: if current_question.is_error: error_msg = current_question.text_prompt or internal_error_msg raise StructuredSMSException(response_text=error_msg, xformsresponse=current_question) xpath = current_question.event._dict["binding"] if used_named_args and xpath in xpath_answer: valid, answer, error_msg = validate_answer(current_question.event, xpath_answer[xpath], verified_number) if not valid: raise StructuredSMSException(response_text=error_msg, xformsresponse=current_question) elif not used_named_args and answer_num < len(args): answer = args[answer_num].strip() valid, answer, error_msg = validate_answer(current_question.event, answer, verified_number) if not valid: raise StructuredSMSException(response_text=error_msg, xformsresponse=current_question) else: # We're out of arguments, so try to leave each remaining question # blank and continue answer = "" if current_question.event._dict.get("required", False): error_msg = get_message(MSG_FIELD_REQUIRED, verified_number) raise StructuredSMSException(response_text=error_msg, xformsresponse=current_question) responses = _get_responses(domain, contact_id, answer, yield_responses=True, session_id=session_id, update_timestamp=False) current_question = responses[-1] form_complete = is_form_complete(current_question) answer_num += 1