def _resolve_answer_value_source( self, value_source: dict ) -> Union[ValueSourceEscapedTypes, ValueSourceTypes]: list_item_id = self._resolve_list_item_id_for_value_source( value_source) answer_id = value_source["identifier"] answer_value = self._get_answer_value(answer_id=answer_id, list_item_id=list_item_id) if isinstance(answer_value, dict): answer_value = (answer_value.get(value_source["selector"]) if "selector" in value_source else None) if answer_value is not None and self.escape_answer_values: return escape_answer_value(answer_value) return answer_value
def get_answer(self, answer_store, answer_id): answer = answer_store.get_answer( answer_id, self.list_item_id) or self.schema.get_default_answer(answer_id) return escape_answer_value(answer.value) if answer else None
def get_escaped_answer_value(self, answer_id, list_item_id=None): if answer := self.get_answer(answer_id, list_item_id): return escape_answer_value(answer.value)
def test_escape_value(value_to_escape, escaped_value): assert escape_answer_value(value_to_escape) == escaped_value