From 82e8057e9d6c8ba508ef1f8c9c728c2ba91c5075 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 16 Jan 2021 20:10:13 +0100 Subject: [PATCH] object in constrainte --- src/rougail/annotator/constrainte.py | 15 ++++----------- src/rougail/path.py | 6 ++++-- src/rougail/tiramisureflector.py | 6 +++--- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/rougail/annotator/constrainte.py b/src/rougail/annotator/constrainte.py index a497c057d..82550473b 100644 --- a/src/rougail/annotator/constrainte.py +++ b/src/rougail/annotator/constrainte.py @@ -141,14 +141,7 @@ class ConstrainteAnnotator: param_option_indexes.append(idx) else: # let's replace params by the path - param.text, suffix = self.objectspace.paths.get_variable_path(param.text, - check.namespace, - ) - if suffix: - xmlfiles = self.objectspace.display_xmlfiles(param.xmlfiles) - msg = _(f'the param "{param.text}" in check cannot be a dynamic ' - f'variable in {xmlfiles}') - raise DictConsistencyError(msg, 23) + param.text = self.objectspace.paths.get_variable_obj(param.text) param_option_indexes.sort(reverse=True) for idx in param_option_indexes: check.param.pop(idx) @@ -223,7 +216,7 @@ class ConstrainteAnnotator: msg = _(f'optional parameter in valid_enum for variable "{variable.name}" ' f'is not allowed in {xmlfiles}') raise DictConsistencyError(msg, 14) - param_variable = self.objectspace.paths.get_variable_obj(param.text) + param_variable = param.text if not param_variable.multi: xmlfiles = self.objectspace.display_xmlfiles(param.xmlfiles) msg = _(f'only multi "variable" parameter is allowed for valid_enum ' @@ -608,10 +601,10 @@ class ConstrainteAnnotator: raise DictConsistencyError(msg, 27) if param.type == 'variable': try: - text, suffix = self.objectspace.paths.get_variable_path(param.text, + path, suffix = self.objectspace.paths.get_variable_path(param.text, fill.namespace, ) - param.text = text + param.text = self.objectspace.paths.get_variable_obj(path) if suffix: param.suffix = suffix except DictConsistencyError as err: diff --git a/src/rougail/path.py b/src/rougail/path.py index ceb937273..8d953d35f 100644 --- a/src/rougail/path.py +++ b/src/rougail/path.py @@ -25,6 +25,8 @@ class Path: full_name = '.'.join([namespace, name]) self.full_paths_families[name] = full_name else: + if '.' not in name: + raise DictConsistencyError(_(f'Variable "{name}" in namespace "{namespace}" must have dot'), 39) full_name = name if full_name in self.families and \ self.families[full_name]['variableobj'] != variableobj: # pragma: no cover @@ -140,13 +142,13 @@ class Path: def get_variable_path(self, name: str, current_namespace: str, - allow_source: str=False, + allow_variable_namespace: str=False, ) -> str: # pylint: disable=C0111 dico, suffix = self._get_variable(name, with_suffix=True, ) namespace = dico['variableobj'].namespace - if not allow_source and namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace: + if not allow_variable_namespace and namespace not in [Config['variable_namespace'], 'services'] and current_namespace != namespace: raise DictConsistencyError(_(f'A variable located in the "{namespace}" namespace shall not be used in the "{current_namespace}" namespace'), 41) return dico['variableobj'].path, suffix diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index 27e919a05..24c7235e0 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -324,7 +324,7 @@ class Variable(Common): self.attrib['validators'].append(self.calculation_value(child, ['ParamSelfOption()'])) elif tag == 'choice': if child.type == 'calculation': - value = self.storage.get(child.name).get() + value = self.storage.get(child.name.path).get() choices = f"Calculation(func.calc_value, Params((ParamOption({value}))))" else: choices.append(child.name) @@ -400,9 +400,9 @@ class Variable(Common): def build_param(self, param, ): - option_name = self.storage.get(param['option']).get() + option_name = self.storage.get(param['option'].path).get() if 'suffix' in param: - family = '.'.join(param['option'].split('.')[:-1]) + family = '.'.join(param['option'].path.split('.')[:-1]) family_option = self.storage.get_name(family) return f"ParamDynOption({option_name}, '{param['suffix']}', {family_option}, notraisepropertyerror={param['notraisepropertyerror']}, todict={param['todict']})" return f"ParamOption({option_name}, notraisepropertyerror={param['notraisepropertyerror']}, todict={param['todict']})"