diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2024-02-08 13:25:51 +0100 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2024-02-08 13:25:51 +0100 |
commit | b860b2f7ed1cd2f1ca66a95f3c063c4fc0f35a41 (patch) | |
tree | d21fe72e82cc5413665b9906838bf96b8f21a8a8 | |
parent | 4d79c91d02ea5e3a9df23e6d95be9646c39e5cc3 (diff) | |
download | rules-b860b2f7ed1cd2f1ca66a95f3c063c4fc0f35a41.tar.gz |
feat(filter_plugins): normalize special character to ascii characters
-rw-r--r-- | ansible.cfg | 1 | ||||
-rw-r--r-- | filter_plugins/core.py | 19 |
2 files changed, 19 insertions, 1 deletions
diff --git a/ansible.cfg b/ansible.cfg index 1207e7b..1329e06 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -5,7 +5,6 @@ interpreter_python = auto_silent jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n roles_path = roles/ -filter_plugins = plugins/filters/ library = /usr/share/ansible/:plugins/modules/ default_fact_path = /etc/ansible/facts.d/:facts.d/ diff --git a/filter_plugins/core.py b/filter_plugins/core.py new file mode 100644 index 0000000..74d6a72 --- /dev/null +++ b/filter_plugins/core.py @@ -0,0 +1,19 @@ +import unicodedata +from typing import Callable + + +def normalize_unicode_to_ansii(data: str) -> str: + """Returns an UTF-8 normalized string without unicode characters.""" + return ( + unicodedata.normalize("NFD", data) + .encode("ascii", errors="ignore") + .decode("utf-8") + ) + + +class FilterModule(object): + + def filters(self) -> dict[str, Callable]: + return { + "normalize_unicode_to_ansii": normalize_unicode_to_ansii + } |