optional sub attribute unauthorized

This commit is contained in:
gwen 2024-08-06 10:48:14 +02:00
parent a2bfa2eed9
commit 92cac379e0

View file

@ -79,7 +79,9 @@ class TiramisuReflector:
if funcs_paths: if funcs_paths:
if self.rougailconfig["export_with_import"]: if self.rougailconfig["export_with_import"]:
self.text["header"].extend( self.text["header"].extend(
["from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription"] [
"from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription"
]
) )
for funcs_path in sorted(funcs_paths, key=sorted_func_name): for funcs_path in sorted(funcs_paths, key=sorted_func_name):
if not isfile(funcs_path): if not isfile(funcs_path):
@ -205,7 +207,9 @@ class Common:
self.populate_attrib() self.populate_attrib()
if self.informations: if self.informations:
for information in self.informations: for information in self.informations:
self.tiramisu.text['option'].append(f'{information}.set_option({self.option_name})') self.tiramisu.text["option"].append(
f"{information}.set_option({self.option_name})"
)
return self.option_name return self.option_name
def populate_attrib(self): def populate_attrib(self):
@ -279,7 +283,7 @@ class Common:
informations = self.objectspace.informations.get(self.elt.path) informations = self.objectspace.informations.get(self.elt.path)
if not informations: if not informations:
return return
keys['informations'] = informations keys["informations"] = informations
def populate_param( def populate_param(
self, self,
@ -301,14 +305,20 @@ class Common:
if param["variable"].path == self.elt.path: if param["variable"].path == self.elt.path:
return f'ParamSelfInformation("{param["information"]}", {default})' return f'ParamSelfInformation("{param["information"]}", {default})'
information_variable_path = param["variable"].path information_variable_path = param["variable"].path
information_variable = self.tiramisu.reflector_objects[information_variable_path] information_variable = self.tiramisu.reflector_objects[
information_variable_path
]
if information_variable_path not in self.calls: if information_variable_path not in self.calls:
option_name = information_variable.get(self.calls, self.elt.path) option_name = information_variable.get(self.calls, self.elt.path)
return f'ParamInformation("{param["information"]}", {default}, option={option_name})' return f'ParamInformation("{param["information"]}", {default}, option={option_name})'
else: else:
information = f'ParamInformation("{param["information"]}", {default})' information = (
f'ParamInformation("{param["information"]}", {default})'
)
information_name = self.tiramisu.get_information_name() information_name = self.tiramisu.get_information_name()
self.tiramisu.text["option"].append(f'{information_name} = {information}') self.tiramisu.text["option"].append(
f"{information_name} = {information}"
)
information_variable.informations.append(information_name) information_variable.informations.append(information_name)
return information_name return information_name
return f'ParamInformation("{param["information"]}", {default})' return f'ParamInformation("{param["information"]}", {default})'
@ -387,10 +397,11 @@ class Common:
ret = ret + ")" ret = ret + ")"
return ret return ret
def populate_calculation(self, def populate_calculation(
datas: Union[Calculation, str, list], self,
return_a_tuple: bool=False, datas: Union[Calculation, str, list],
) -> str: return_a_tuple: bool = False,
) -> str:
if isinstance(datas, str): if isinstance(datas, str):
return self.convert_str(datas) return self.convert_str(datas)
if isinstance(datas, Calculation): if isinstance(datas, Calculation):
@ -406,9 +417,9 @@ class Common:
else: else:
params.append(str(data)) params.append(str(data))
if return_a_tuple: if return_a_tuple:
ret = '(' ret = "("
else: else:
ret = '[' ret = "["
ret += ", ".join(params) ret += ", ".join(params)
if return_a_tuple: if return_a_tuple:
if len(params) <= 1: if len(params) <= 1:
@ -428,8 +439,10 @@ class Variable(Common):
tiramisu, tiramisu,
): ):
super().__init__(elt, tiramisu) super().__init__(elt, tiramisu)
if elt.type in self.tiramisu.objectspace.rougailconfig['custom_types']: if elt.type in self.tiramisu.objectspace.rougailconfig["custom_types"]:
self.object_type = self.tiramisu.objectspace.rougailconfig['custom_types'][elt.type].__name__ self.object_type = self.tiramisu.objectspace.rougailconfig["custom_types"][
elt.type
].__name__
else: else:
self.object_type = CONVERT_OPTION[elt.type]["opttype"] self.object_type = CONVERT_OPTION[elt.type]["opttype"]
@ -442,7 +455,11 @@ class Variable(Common):
self.calls, self.elt.path self.calls, self.elt.path
) )
if self.elt.type == "choice": if self.elt.type == "choice":
raise DictConsistencyError("Sub-attributes not allowed in a 'choices' attribute", 100, self.elt.xmlfiles) raise DictConsistencyError(
"Sub-attributes not allowed in a 'choices' attribute",
100,
self.elt.xmlfiles,
)
if self.elt.path in self.objectspace.multis: if self.elt.path in self.objectspace.multis:
keys["multi"] = self.objectspace.multis[self.elt.path] keys["multi"] = self.objectspace.multis[self.elt.path]
if hasattr(self.elt, "default") and self.elt.default is not None: if hasattr(self.elt, "default") and self.elt.default is not None:
@ -450,14 +467,22 @@ class Variable(Common):
keys["default"] = self.populate_calculation(self.elt.default) keys["default"] = self.populate_calculation(self.elt.default)
except VariableCalculationDependencyError: except VariableCalculationDependencyError:
pass pass
for attribute in ['frozen', 'hidden', "mandatory", "disabled"]: for attribute in ["frozen", "hidden", "mandatory", "disabled"]:
if hasattr(self.elt, attribute): if hasattr(self.elt, attribute): # FIXME FIXME and attribute == "optional":
raise DictConsistencyError(f"Sub-attributes not allowed in a '{attribute}' attribute", 100, self.elt.xmlfiles) raise DictConsistencyError(
f"Sub-attributes not allowed in a '{attribute}' attribute",
100,
self.elt.xmlfiles,
)
if self.elt.path in self.objectspace.default_multi: if self.elt.path in self.objectspace.default_multi:
keys["default_multi"] = self.populate_calculation(self.objectspace.default_multi[self.elt.path]) keys["default_multi"] = self.populate_calculation(
self.objectspace.default_multi[self.elt.path]
)
if self.elt.validators: if self.elt.validators:
keys["validators"] = self.populate_calculation(self.elt.validators) keys["validators"] = self.populate_calculation(self.elt.validators)
for key, value in CONVERT_OPTION.get(self.elt.type, {}).get("initkwargs", {}).items(): for key, value in (
CONVERT_OPTION.get(self.elt.type, {}).get("initkwargs", {}).items()
):
if isinstance(value, str): if isinstance(value, str):
value = self.convert_str(value) value = self.convert_str(value)
keys[key] = value keys[key] = value