optional sub attribute unauthorized

This commit is contained in:
gwen 2024-08-06 10:48:14 +02:00 committed by Emmanuel Garette
parent e57cf4dea8
commit 0c02807775

View file

@ -201,7 +201,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):
@ -275,7 +277,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,
@ -299,14 +301,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})'
@ -385,10 +393,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):
@ -404,9 +413,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:
@ -441,7 +450,11 @@ class Variable(Common):
) )
return return
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:
@ -449,14 +462,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