|
19 | 19 | environment. |
20 | 20 | """ |
21 | 21 |
|
22 | | -import re |
23 | 22 | from pathlib import Path |
24 | 23 | from typing import TYPE_CHECKING, Any, Dict, List, Tuple |
25 | 24 |
|
|
51 | 50 | YamlAgentsDocument, |
52 | 51 | ) |
53 | 52 |
|
54 | | - |
55 | | -class _FlinkAgentsYamlLoader(yaml.SafeLoader): |
56 | | - """SafeLoader that recognizes only ``true``/``false`` as booleans. |
57 | | -
|
58 | | - PyYAML follows YAML 1.1 by default, where ``on``/``off``/``yes``/``no`` |
59 | | - also coerce to booleans. ``on:`` is the natural way to declare an |
60 | | - action's event listeners in this API, so we strip those legacy |
61 | | - keywords from the bool resolver. |
62 | | - """ |
63 | | - |
64 | | - |
65 | | -_FlinkAgentsYamlLoader.yaml_implicit_resolvers = { |
66 | | - key: [(tag, regexp) for tag, regexp in resolvers if tag != "tag:yaml.org,2002:bool"] |
67 | | - for key, resolvers in yaml.SafeLoader.yaml_implicit_resolvers.items() |
68 | | -} |
69 | | -_FlinkAgentsYamlLoader.add_implicit_resolver( |
70 | | - "tag:yaml.org,2002:bool", |
71 | | - re.compile(r"^(?:true|True|TRUE|false|False|FALSE)$"), |
72 | | - list("tTfF"), |
73 | | -) |
74 | | - |
75 | 53 | # Default Java parameter types for an action. Action methods in |
76 | 54 | # flink-agents always have signature (Event, RunnerContext). |
77 | 55 | _JAVA_ACTION_PARAMETER_TYPES: list[str] = [ |
@@ -145,7 +123,7 @@ def resolve_function( |
145 | 123 |
|
146 | 124 | def _load_document(path: Path | str) -> YamlAgentsDocument: |
147 | 125 | text = Path(path).read_text() |
148 | | - raw = yaml.load(text, Loader=_FlinkAgentsYamlLoader) |
| 126 | + raw = yaml.load(text, Loader=yaml.SafeLoader) |
149 | 127 | if raw is None: |
150 | 128 | msg = f"YAML file {path} is empty" |
151 | 129 | raise ValueError(msg) |
@@ -192,7 +170,7 @@ def _resolve_action_function(action: ActionSpec) -> Function: |
192 | 170 |
|
193 | 171 | def _add_action_to_agent(agent: Agent, action: ActionSpec) -> None: |
194 | 172 | func = _resolve_action_function(action) |
195 | | - events = [resolve_event_type(e) for e in action.on] |
| 173 | + events = [resolve_event_type(e) for e in action.listen_to] |
196 | 174 | config = action.config or {} |
197 | 175 | agent.add_action(action.name, events, func, **config) |
198 | 176 |
|
|
0 commit comments