From 5c3ab2ae17f97e47bb0b76393662c746a9f8ef70 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 4 Mar 2020 15:37:08 +0100 Subject: [PATCH] family name could containe an integer --- src/rougail/annotator.py | 2 +- src/rougail/loader.py | 2 ++ src/rougail/utils.py | 19 +++++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/rougail/annotator.py b/src/rougail/annotator.py index 653f9d254..e3c9f18aa 100644 --- a/src/rougail/annotator.py +++ b/src/rougail/annotator.py @@ -168,7 +168,7 @@ class ServiceAnnotator: else: type_ = 'string' dtd_key_type = true_key + '_type' - + if hasattr(elt, dtd_key_type): type_ = KEY_TYPE[getattr(elt, dtd_key_type)] multi = isinstance(value, list) diff --git a/src/rougail/loader.py b/src/rougail/loader.py index 6bcfc4e53..b6637b2f5 100644 --- a/src/rougail/loader.py +++ b/src/rougail/loader.py @@ -30,6 +30,8 @@ FUNC_TO_DICT = ['valid_not_equal'] class ConvertDynOptionDescription(DynOptionDescription): def convert_suffix_to_path(self, suffix): + if not isinstance(suffix, str): + suffix = str(suffix) return normalize_family(suffix, check_name=False) diff --git a/src/rougail/utils.py b/src/rougail/utils.py index 6d68fee1a..fd90d31cc 100644 --- a/src/rougail/utils.py +++ b/src/rougail/utils.py @@ -10,15 +10,14 @@ def normalize_family(family_name: str, allow_dot: bool=False) -> str: """replace space, accent, uppercase, ... by valid character """ - f = family_name - f = f.replace('-', '_') + family_name = family_name.replace('-', '_') if not allow_dot: - f = f.replace('.', '_') - f = f.replace(' ', '_') - nfkd_form = unicodedata.normalize('NFKD', f) - f = ''.join([c for c in nfkd_form if not unicodedata.combining(c)]) - f = f.lower() - if check_name and f == 'containers': - raise ValueError(_('"{0}" is a forbidden family name'.format(f))) - return f + family_name = family_name.replace('.', '_') + family_name = family_name.replace(' ', '_') + nfkd_form = unicodedata.normalize('NFKD', family_name) + family_name = ''.join([c for c in nfkd_form if not unicodedata.combining(c)]) + family_name = family_name.lower() + if check_name and family_name == 'containers': + raise ValueError(_(f'"{family_name}" is a forbidden family name')) + return family_name