1 from abc import abstractmethod
3 class ConfigLoadBaseException(Exception):
4 def __init__(self, msg, node, inner=None) -> None:
11 def __str__(self) -> str:
12 return super().__str__()
14 class ConfigLoadException(ConfigLoadBaseException):
15 def __init__(self, msg, node = None, inner=None) -> None:
16 super().__init__(msg, node, inner)
18 class ConfigTypeCheckError(ConfigLoadBaseException):
19 def __init__(self, msg, node, inner=None) -> None:
20 super().__init__(msg, node, inner)
22 class ConfigIOProvider:
23 def __init__(self) -> None:
27 def export(self, env, config_dict):
31 def save(self, env, config_dict):
39 class TypeProviderBase:
40 def __init__(self, type) -> None:
48 def serialise(self, val):
52 def deserialise(self, val):
56 def parse_input(self, input_str):
60 def to_input(self, val):
67 def typedef_matched(typedef):
71 def __str__(self) -> str:
75 def __init__(self) -> None:
79 def render(self, rctx):
83 def __init__(self) -> None:
87 def add_expandable(self, label, node, on_expand_cb):
91 def add_field(self, label, node):
94 class InteractiveRenderer(RenderContext):
95 def __init__(self) -> None:
99 def render_loop(self):
103 class LConfigBuiltin:
104 def __init__(self, f, is_contextual, rename=None, caller_type=[]):
105 self.name = f.__name__ if not rename else rename
107 self.__contextual = is_contextual
108 self.__caller_type = caller_type
110 def __call__(self, env, *args, **kwds):
111 if not self.__contextual:
112 return self.__f(env, *args, **kwds)
114 caller = env.callframe_at(0)
115 f_name = self.__f.__name__
118 raise ConfigLoadException(
119 f"contextual function '{f_name}' can not be called contextless",
123 if self.__caller_type and not any([isinstance(caller, x) for x in self.__caller_type]):
124 raise ConfigLoadException(
125 f"caller of '{f_name}' ({caller}) must have type of any {self.__caller_type}",
129 return self.__f(env, caller, *args, **kwds)
131 def contextual(name=None, caller_type=[]):
133 return LConfigBuiltin(func, True, name, caller_type)
136 def builtin(name=None):
138 return LConfigBuiltin(func, False, name)