Script syntax check
(script: dict | str, pre_deep: str = "", return_record: dict = {})
| 127 | @staticmethod |
| 128 | @check |
| 129 | def syntax_check(script: dict | str, pre_deep: str = "", return_record: dict = {}) -> None: |
| 130 | """ |
| 131 | Script syntax check |
| 132 | """ |
| 133 | if isinstance(script, str): |
| 134 | script = json.loads(script) |
| 135 | current_deep = 0 |
| 136 | pre_return = None |
| 137 | while script and isinstance(script, dict): |
| 138 | current_deep += 1 |
| 139 | loop_temp: dict = script.get("loop") |
| 140 | if loop_temp: |
| 141 | cnt = loop_temp.get("cnt") |
| 142 | while_condition = loop_temp.get("while") |
| 143 | if not cnt and not while_condition: |
| 144 | msg = "(Deep %s) loop must set the param of cnt or while" % (pre_deep + str(current_deep)) |
| 145 | raise ScriptSyntaxError(ParamTypeError(msg), "", pre_deep + str(current_deep)) |
| 146 | if while_condition: |
| 147 | ScriptProcess.__condition_check(temp_condition=while_condition, |
| 148 | name="while", |
| 149 | return_record=return_record, |
| 150 | pre_deep=pre_deep, |
| 151 | current_deep=current_deep) |
| 152 | loop_script = loop_temp.get("script") |
| 153 | if not loop_script: |
| 154 | msg = "(Deep %s) loop must set the param of script" % (pre_deep + str(current_deep)) |
| 155 | raise ScriptSyntaxError(ParamTypeError(msg), "", pre_deep + str(current_deep)) |
| 156 | ScriptProcess.syntax_check(script=loop_script, |
| 157 | pre_deep=pre_deep + str(current_deep) + "->", |
| 158 | return_record=return_record) |
| 159 | check_condition = script.get("check") |
| 160 | if check_condition: |
| 161 | ScriptProcess.__condition_check(temp_condition=check_condition, |
| 162 | name="check", |
| 163 | return_record=return_record, |
| 164 | pre_deep=pre_deep, |
| 165 | current_deep=current_deep) |
| 166 | if_condition = script.get("if") |
| 167 | if if_condition: |
| 168 | if not script.get("method"): |
| 169 | msg = "(Deep %s) The 'if' condition must be with a Action Method" % (pre_deep + str(current_deep)) |
| 170 | raise ScriptSyntaxError(ParamTypeError(msg), "", pre_deep + str(current_deep)) |
| 171 | ScriptProcess.__condition_check(temp_condition=if_condition, |
| 172 | name="if", |
| 173 | return_record=return_record, |
| 174 | pre_deep=pre_deep, |
| 175 | current_deep=current_deep) |
| 176 | temp_args = {"driver": None} |
| 177 | method = script.get("method") |
| 178 | if not method: |
| 179 | script = script.get("next") |
| 180 | continue |
| 181 | if not isinstance(method, str): |
| 182 | msg = "(Deep %s) The value of method must be type of str" % (pre_deep + str(current_deep)) |
| 183 | raise ScriptSyntaxError(ParamTypeError(msg), "", pre_deep + str(current_deep)) |
| 184 | if method not in ScriptProcess.ACTIONS.keys(): |
| 185 | msg = "(Deep %s) Could not found the Action Method" % (pre_deep + str(current_deep)) |
| 186 | raise ScriptSyntaxError(ParamTypeError(msg), method, pre_deep + str(current_deep)) |
no test coverage detected