|
|
|
|
@ -25,7 +25,7 @@ class TemplateTransformer(ABC):
|
|
|
|
|
return runner_script, preload_script
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def extract_result_str_from_response(cls, response: str) -> str:
|
|
|
|
|
def extract_result_str_from_response(cls, response: str):
|
|
|
|
|
result = re.search(rf"{cls._result_tag}(.*){cls._result_tag}", response, re.DOTALL)
|
|
|
|
|
if not result:
|
|
|
|
|
raise ValueError("Failed to parse result")
|
|
|
|
|
@ -33,15 +33,20 @@ class TemplateTransformer(ABC):
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def transform_response(cls, response: str):
|
|
|
|
|
def transform_response(cls, response: str) -> Mapping[str, Any]:
|
|
|
|
|
"""
|
|
|
|
|
Transform response to dict
|
|
|
|
|
:param response: response
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
result = json.loads(cls.extract_result_str_from_response(response))
|
|
|
|
|
try:
|
|
|
|
|
result = json.loads(cls.extract_result_str_from_response(response))
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
|
raise ValueError("failed to parse response")
|
|
|
|
|
if not isinstance(result, dict):
|
|
|
|
|
raise ValueError("Result must be a dict")
|
|
|
|
|
raise ValueError("result must be a dict")
|
|
|
|
|
if not all(isinstance(k, str) for k in result):
|
|
|
|
|
raise ValueError("result keys must be strings")
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|