MCPcopy Index your code
hub / github.com/bugy/script-server / __init__

Method __init__

src/model/template_property.py:8–45  ·  view source on GitHub ↗
(self, template_config, parameters: ObservableList, value_wrappers: ObservableDict, empty=None)

Source from the content-addressed store, hash-verified

6
7class TemplateProperty:
8 def __init__(self, template_config, parameters: ObservableList, value_wrappers: ObservableDict, empty=None) -> None:
9 self._value_property = Property(None)
10 self._template_config = template_config
11 self._values = value_wrappers
12 self._empty = empty
13 self._parameters = parameters
14
15 pattern = re.compile('\${([^}]+)\}')
16
17 search_start = 0
18 script_template = ''
19 required_parameters = set()
20
21 templates = template_config if isinstance(template_config, list) else [template_config]
22
23 for template in templates:
24 if template:
25 while search_start < len(template):
26 match = pattern.search(template, search_start)
27 if not match:
28 script_template += template[search_start:]
29 break
30 param_start = match.start()
31 if param_start > search_start:
32 script_template += template[search_start:param_start]
33
34 param_name = match.group(1)
35 required_parameters.add(param_name)
36
37 search_start = match.end() + 1
38
39 self.required_parameters = tuple(required_parameters)
40
41 self._reload()
42
43 if self.required_parameters:
44 value_wrappers.subscribe(self._value_changed)
45 parameters.subscribe(self)
46
47 def _value_changed(self, parameter, old, new):
48 if parameter in self.required_parameters:

Callers

nothing calls this directly

Calls 4

_reloadMethod · 0.95
PropertyClass · 0.90
startMethod · 0.45
subscribeMethod · 0.45

Tested by

no test coverage detected