name in family or variable must be valid
This commit is contained in:
@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from ..i18n import _
|
||||
from ..error import DictConsistencyError
|
||||
from ..utils import normalize_family
|
||||
from .variable import Walk
|
||||
|
||||
|
||||
@ -91,7 +90,6 @@ class FamilyAnnotator(Walk):
|
||||
family.description = family.name
|
||||
family.doc = family.description
|
||||
del family.description
|
||||
family.name = normalize_family(family.name)
|
||||
|
||||
def change_modes(self):
|
||||
"""change the mode of variables
|
||||
|
@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
from ..i18n import _
|
||||
from ..error import DictConsistencyError
|
||||
from ..objspace import convert_boolean
|
||||
from ..utils import normalize_family
|
||||
|
||||
|
||||
CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
|
||||
@ -171,7 +170,6 @@ class VariableAnnotator(Walk): # pylint: disable=R0903
|
||||
if not variable.value:
|
||||
del variable.value
|
||||
variable.doc = variable.description
|
||||
variable.name = normalize_family(variable.name)
|
||||
del variable.description
|
||||
if variable_type == 'follower':
|
||||
if variable.multi is True:
|
||||
|
@ -29,7 +29,7 @@ from typing import Optional
|
||||
|
||||
from .i18n import _
|
||||
from .xmlreflector import XMLReflector
|
||||
from .utils import normalize_family
|
||||
from .utils import valid_variable_family_name
|
||||
from .error import SpaceObjShallNotBeUpdated, DictConsistencyError
|
||||
from .path import Path
|
||||
|
||||
@ -197,7 +197,7 @@ class RougailObjSpace:
|
||||
if child.tag == 'family':
|
||||
if child.attrib['name'] in family_names:
|
||||
msg = _(f'Family "{child.attrib["name"]}" is set several times')
|
||||
raise DictConsistencyError(msg, 44, xmlfile)
|
||||
raise DictConsistencyError(msg, 44, [xmlfile])
|
||||
family_names.append(child.attrib['name'])
|
||||
try:
|
||||
# variable objects creation
|
||||
@ -296,6 +296,7 @@ class RougailObjSpace:
|
||||
"""A redefinable object could be created or updated
|
||||
"""
|
||||
existed_var = self.get_existed_obj(name,
|
||||
xmlfile,
|
||||
space,
|
||||
child,
|
||||
namespace,
|
||||
@ -337,6 +338,7 @@ class RougailObjSpace:
|
||||
|
||||
def get_existed_obj(self,
|
||||
name: str,
|
||||
xmlfile: str,
|
||||
space: str,
|
||||
child,
|
||||
namespace: str,
|
||||
@ -344,7 +346,7 @@ class RougailObjSpace:
|
||||
"""if an object exists, return it
|
||||
"""
|
||||
if child.tag in ['variable', 'family']:
|
||||
name = normalize_family(name)
|
||||
valid_variable_family_name(name, [xmlfile])
|
||||
if child.tag == 'variable': # pylint: disable=E1101
|
||||
if namespace != self.rougailconfig['variable_namespace']:
|
||||
name = space.path + '.' + name
|
||||
@ -468,18 +470,18 @@ class RougailObjSpace:
|
||||
"""
|
||||
if isinstance(variableobj, self.variable): # pylint: disable=E1101
|
||||
if 'name' in document.attrib:
|
||||
family_name = normalize_family(document.attrib['name'])
|
||||
family_name = document.attrib['name']
|
||||
else:
|
||||
family_name = namespace
|
||||
|
||||
self.paths.add_variable(namespace,
|
||||
normalize_family(variableobj.name),
|
||||
variableobj.name,
|
||||
space.path,
|
||||
document.attrib.get('dynamic') is not None,
|
||||
variableobj,
|
||||
)
|
||||
elif isinstance(variableobj, self.family): # pylint: disable=E1101
|
||||
family_name = normalize_family(variableobj.name)
|
||||
family_name = variableobj.name
|
||||
if namespace != self.rougailconfig['variable_namespace']:
|
||||
family_name = namespace + '.' + family_name
|
||||
self.paths.add_family(namespace,
|
||||
@ -502,8 +504,6 @@ class RougailObjSpace:
|
||||
if isinstance(variableobj, Redefinable):
|
||||
name = variableobj.name
|
||||
tag = FORCE_TAG.get(child.tag, child.tag)
|
||||
if child.tag in ['family', 'variable']:
|
||||
name = normalize_family(name)
|
||||
getattr(space, tag)[name] = variableobj
|
||||
elif isinstance(variableobj, UnRedefinable):
|
||||
getattr(space, child.tag).append(variableobj)
|
||||
|
@ -26,10 +26,26 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from typing import List
|
||||
from unicodedata import normalize, combining
|
||||
import re
|
||||
|
||||
from importlib.machinery import SourceFileLoader
|
||||
from importlib.util import spec_from_loader, module_from_spec
|
||||
|
||||
from .i18n import _
|
||||
from .error import DictConsistencyError
|
||||
|
||||
NAME_REGEXP = re.compile(r"^[a-z0-9_]*$")
|
||||
|
||||
|
||||
def valid_variable_family_name(name: str,
|
||||
xmlfiles: List[str],
|
||||
) -> None:
|
||||
match = NAME_REGEXP.search(name)
|
||||
if not match:
|
||||
msg = _(f'invalid variable or family name "{name}" must only contains '
|
||||
'lowercase ascii character, number or _')
|
||||
raise DictConsistencyError(msg, 76, xmlfiles)
|
||||
|
||||
|
||||
def normalize_family(family_name: str) -> str:
|
||||
"""replace space, accent, uppercase, ... by valid character
|
||||
|
Reference in New Issue
Block a user