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 self.rougailconfig["export_with_import"]:
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):
if not isfile(funcs_path):
@ -205,7 +207,9 @@ class Common:
self.populate_attrib()
if 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
def populate_attrib(self):
@ -279,7 +283,7 @@ class Common:
informations = self.objectspace.informations.get(self.elt.path)
if not informations:
return
keys['informations'] = informations
keys["informations"] = informations
def populate_param(
self,
@ -301,14 +305,20 @@ class Common:
if param["variable"].path == self.elt.path:
return f'ParamSelfInformation("{param["information"]}", {default})'
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:
option_name = information_variable.get(self.calls, self.elt.path)
return f'ParamInformation("{param["information"]}", {default}, option={option_name})'
else:
information = f'ParamInformation("{param["information"]}", {default})'
information = (
f'ParamInformation("{param["information"]}", {default})'
)
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)
return information_name
return f'ParamInformation("{param["information"]}", {default})'
@ -387,10 +397,11 @@ class Common:
ret = ret + ")"
return ret
def populate_calculation(self,
datas: Union[Calculation, str, list],
return_a_tuple: bool=False,
) -> str:
def populate_calculation(
self,
datas: Union[Calculation, str, list],
return_a_tuple: bool = False,
) -> str:
if isinstance(datas, str):
return self.convert_str(datas)
if isinstance(datas, Calculation):
@ -406,9 +417,9 @@ class Common:
else:
params.append(str(data))
if return_a_tuple:
ret = '('
ret = "("
else:
ret = '['
ret = "["
ret += ", ".join(params)
if return_a_tuple:
if len(params) <= 1:
@ -428,8 +439,10 @@ class Variable(Common):
tiramisu,
):
super().__init__(elt, tiramisu)
if elt.type in self.tiramisu.objectspace.rougailconfig['custom_types']:
self.object_type = self.tiramisu.objectspace.rougailconfig['custom_types'][elt.type].__name__
if elt.type in self.tiramisu.objectspace.rougailconfig["custom_types"]:
self.object_type = self.tiramisu.objectspace.rougailconfig["custom_types"][
elt.type
].__name__
else:
self.object_type = CONVERT_OPTION[elt.type]["opttype"]
@ -442,7 +455,11 @@ class Variable(Common):
self.calls, self.elt.path
)
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:
keys["multi"] = self.objectspace.multis[self.elt.path]
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)
except VariableCalculationDependencyError:
pass
for attribute in ['frozen', 'hidden', "mandatory", "disabled"]:
if hasattr(self.elt, attribute):
raise DictConsistencyError(f"Sub-attributes not allowed in a '{attribute}' attribute", 100, self.elt.xmlfiles)
for attribute in ["frozen", "hidden", "mandatory", "disabled"]:
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,
)
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:
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):
value = self.convert_str(value)
keys[key] = value