MCPcopy Create free account
hub / github.com/deskree-inc/blok / replace_string

Method replace_string

runtimes/python3/core/util/mapper.py:17–32  ·  view source on GitHub ↗
(self, str_data: str, ctx: Context, data: ParamsDictionary)

Source from the content-addressed store, hash-verified

15 self.replace_object_strings(value, ctx, data)
16
17 def replace_string(self, str_data: str, ctx: Context, data: ParamsDictionary) -> str:
18 str_ = str_data
19 regex = re.compile(r'\${(.*?)}')
20 matches = regex.findall(str_)
21
22 if matches:
23 for match in matches:
24 try:
25 key = match
26 value = data.get(key) or self.run_js(key, ctx, data)
27 str_ = str_.replace(f"${{{match}}}", str(value))
28 except Exception as e:
29 print("Mapper Error 1", e)
30
31 result = self.js_mapper(str_, ctx, data)
32 return str(result)
33
34 def run_js(self, str_: str, ctx: Context, data: ParamsDictionary = {}, func: FunctionContext = {}, vars: VarsContext = {}) -> ParamsDictionary:
35 return eval(f"lambda ctx, data, func, vars: {str_}")(ctx, data, func, vars)

Callers 3

blueprintMapperMethod · 0.80
test_replace_stringMethod · 0.80

Calls 3

run_jsMethod · 0.95
js_mapperMethod · 0.95
getMethod · 0.45

Tested by 1

test_replace_stringMethod · 0.64