File: error_decl.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (48 lines) | stat: -rw-r--r-- 1,659 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import abc
from typing import Final

from moto.stepfunctions.parser.asl.component.common.string.string_expression import (
    StringExpression,
    StringIntrinsicFunction,
)
from moto.stepfunctions.parser.asl.component.eval_component import EvalComponent
from moto.stepfunctions.parser.asl.component.intrinsic.functionname.state_function_name_types import (
    StatesFunctionNameType,
)
from moto.stepfunctions.parser.asl.eval.environment import Environment

_STRING_RETURN_FUNCTIONS: Final[set[str]] = {
    typ.name()
    for typ in [
        StatesFunctionNameType.Format,
        StatesFunctionNameType.JsonToString,
        StatesFunctionNameType.ArrayGetItem,
        StatesFunctionNameType.Base64Decode,
        StatesFunctionNameType.Base64Encode,
        StatesFunctionNameType.Hash,
        StatesFunctionNameType.UUID,
    ]
}


class ErrorDecl(EvalComponent, abc.ABC): ...


class Error(ErrorDecl):
    string_expression: Final[StringExpression]

    def __init__(self, string_expression: StringExpression):
        self.string_expression = string_expression

    def _eval_body(self, env: Environment) -> None:
        self.string_expression.eval(env=env)


class ErrorPath(Error):
    def __init__(self, string_expression: StringExpression):
        super().__init__(string_expression=string_expression)
        if isinstance(string_expression, StringIntrinsicFunction):
            if string_expression.function.name.name not in _STRING_RETURN_FUNCTIONS:
                raise ValueError(
                    f"Unsupported Intrinsic Function for ErrorPath declaration: '{string_expression.intrinsic_function_derivation}'."
                )