mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
Avoid deprecated AnsibleFilterTypeError (#9992)
Avoid deprecated AnsibleFilterTypeError.
This commit is contained in:
parent
04cfce78ea
commit
8525e420bc
3 changed files with 15 additions and 4 deletions
2
changelogs/fragments/9992-filtertypeerror.yml
Normal file
2
changelogs/fragments/9992-filtertypeerror.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "hashids and unicode_normalize filter plugins - avoid deprecated ``AnsibleFilterTypeError`` on ansible-core 2.19 (https://github.com/ansible-collections/community.general/pull/9992)."
|
|
@ -9,12 +9,16 @@ from __future__ import annotations
|
||||||
from ansible.errors import (
|
from ansible.errors import (
|
||||||
AnsibleError,
|
AnsibleError,
|
||||||
AnsibleFilterError,
|
AnsibleFilterError,
|
||||||
AnsibleFilterTypeError,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
from ansible.module_utils.common.collections import is_sequence
|
from ansible.module_utils.common.collections import is_sequence
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.errors import AnsibleTypeError
|
||||||
|
except ImportError:
|
||||||
|
from ansible.errors import AnsibleFilterTypeError as AnsibleTypeError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from hashids import Hashids
|
from hashids import Hashids
|
||||||
HAS_HASHIDS = True
|
HAS_HASHIDS = True
|
||||||
|
@ -63,7 +67,7 @@ def hashids_encode(nums, salt=None, alphabet=None, min_length=None):
|
||||||
try:
|
try:
|
||||||
hashid = hashids.encode(*nums)
|
hashid = hashids.encode(*nums)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
raise AnsibleFilterTypeError(
|
raise AnsibleTypeError(
|
||||||
"Data to encode must by a tuple or list of ints: %s" % to_native(e)
|
"Data to encode must by a tuple or list of ints: %s" % to_native(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,14 @@ _value:
|
||||||
|
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
|
|
||||||
from ansible.errors import AnsibleFilterError, AnsibleFilterTypeError
|
from ansible.errors import AnsibleFilterError
|
||||||
from ansible.module_utils.six import text_type
|
from ansible.module_utils.six import text_type
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.errors import AnsibleTypeError
|
||||||
|
except ImportError:
|
||||||
|
from ansible.errors import AnsibleFilterTypeError as AnsibleTypeError
|
||||||
|
|
||||||
|
|
||||||
def unicode_normalize(data, form='NFC'):
|
def unicode_normalize(data, form='NFC'):
|
||||||
"""Applies normalization to 'unicode' strings.
|
"""Applies normalization to 'unicode' strings.
|
||||||
|
@ -65,7 +70,7 @@ def unicode_normalize(data, form='NFC'):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(data, text_type):
|
if not isinstance(data, text_type):
|
||||||
raise AnsibleFilterTypeError("%s is not a valid input type" % type(data))
|
raise AnsibleTypeError("%s is not a valid input type" % type(data))
|
||||||
|
|
||||||
if form not in ('NFC', 'NFD', 'NFKC', 'NFKD'):
|
if form not in ('NFC', 'NFD', 'NFKC', 'NFKD'):
|
||||||
raise AnsibleFilterError("%s is not a valid form" % form)
|
raise AnsibleFilterError("%s is not a valid form" % form)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue