generate the scripts(dict) from list
(scripts: list | dict | str)
| 409 | @staticmethod |
| 410 | @check |
| 411 | def generate(scripts: list | dict | str) -> dict: |
| 412 | """ |
| 413 | generate the scripts(dict) from list |
| 414 | """ |
| 415 | if isinstance(scripts, dict): |
| 416 | return scripts |
| 417 | if isinstance(scripts, str): |
| 418 | return json.loads(scripts) |
| 419 | res = {} |
| 420 | temp = res |
| 421 | for i in range(len(scripts)): |
| 422 | for k in scripts[i].keys(): |
| 423 | if k == "loop": |
| 424 | loop_temp = scripts[i]["loop"] |
| 425 | if "script" in loop_temp: |
| 426 | loop_temp["script"] = ScriptProcess.generate(loop_temp["script"]) |
| 427 | if k in {"if", "check", "while"}: |
| 428 | judge_temp = scripts[i][k] |
| 429 | if "fail_script" in judge_temp: |
| 430 | judge_temp["fail_script"] = ScriptProcess.generate(judge_temp["fail_script"]) |
| 431 | temp.update(scripts[i]) |
| 432 | if i != len(scripts) - 1: |
| 433 | while temp.get("next"): |
| 434 | temp = temp.get("next") |
| 435 | temp["next"] = {} |
| 436 | temp = temp["next"] |
| 437 | return res |
| 438 | |
| 439 | @staticmethod |
| 440 | def generate_json(scripts: dict | list) -> str: |
no test coverage detected