diff options
author | Vratko Polak <vrpolak@cisco.com> | 2024-05-29 15:20:02 +0200 |
---|---|---|
committer | Vratko Polak <vrpolak@cisco.com> | 2024-05-31 14:06:29 +0000 |
commit | b9dff484de0725bca3f65739519d952e3be55cbe (patch) | |
tree | 6ecda55b599c8227f025c316b6054374106202e0 /resources/libraries/python/enum_util.py | |
parent | 3d20e3980839f01466c5750c2372fba55c47768e (diff) |
feat(ipsec): Add suites for more algs
+ Add suite with UDP encap.
+ Add suite with anti replay enabled.
+ Add new enums where needed by the new suites.
+ Apply trimming in enum_util to support "3DES".
+ All 10ktnl suites written and tested.
+ New robot tags added.
+ Fix one comment from the parent.
Change-Id: I2581814dbb327891d8658dd009c4e52ffd318e3b
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'resources/libraries/python/enum_util.py')
-rw-r--r-- | resources/libraries/python/enum_util.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/resources/libraries/python/enum_util.py b/resources/libraries/python/enum_util.py index 41dfd8a459..f721936ee4 100644 --- a/resources/libraries/python/enum_util.py +++ b/resources/libraries/python/enum_util.py @@ -31,13 +31,15 @@ def get_enum_instance( to convert string into the corresponding Enum instance. Aliases are also recognized. - As an added benefit, support various Robot-like niceties, - like lower case, or dash or space instead of underscore. - As a common shortcut, value is returned it it already is an instance. Another convenience: None or empty string is processed as "NONE". + As an added benefit, support various Robot-like niceties, + like lower case, or dash or space instead of underscore. + Also strip the identifiers, this is mostly due to "3DES". + Enum instance cannot start with a number, so "_3DES" + strip is needed. + If the class is a subclass of IntEnum, int values and (string) values convertable to int are also accepted as input. @@ -59,9 +61,10 @@ def get_enum_instance( return value if not value: value = "NONE" - normalized_name = str(value).upper().replace("-", "_").replace(" ", "_") + normalized_name = str(value).upper().replace("-", " ").replace("_", " ") members = enum_class.__members__ # Includes aliases, useful for NONE. - if normalized_name not in members: - msg = f"Enum class {enum_class} does not have value {normalized_name!r}" - raise ValueError(msg) - return members[normalized_name] + for member_name in members: + if normalized_name.strip() == member_name.replace("_", " ").strip(): + return members[member_name] + msg = f"Enum class {enum_class} does not have value {normalized_name!r}" + raise ValueError(msg) |