mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 19:20:22 -07:00
[PR #9379/22035608 backport][stable-10] plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9444)
plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9379)
* Replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting.
* Improve formulation.
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Use more f-strings.
* Remove unicode prefix for strings.
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
(cherry picked from commit 2203560867
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
0acaad60c8
commit
151f6c9ce3
34 changed files with 111 additions and 99 deletions
|
@ -81,7 +81,6 @@ RETURN = '''
|
|||
'''
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.csv import (initialize_dialect, read_csv, CSVError,
|
||||
DialectNotAvailableError,
|
||||
|
@ -99,7 +98,7 @@ def from_csv(data, dialect='excel', fieldnames=None, delimiter=None, skipinitial
|
|||
try:
|
||||
dialect = initialize_dialect(dialect, **dialect_params)
|
||||
except (CustomDialectFailureError, DialectNotAvailableError) as e:
|
||||
raise AnsibleFilterError(to_native(e))
|
||||
raise AnsibleFilterError(str(e))
|
||||
|
||||
reader = read_csv(data, dialect, fieldnames)
|
||||
|
||||
|
@ -109,7 +108,7 @@ def from_csv(data, dialect='excel', fieldnames=None, delimiter=None, skipinitial
|
|||
for row in reader:
|
||||
data_list.append(row)
|
||||
except CSVError as e:
|
||||
raise AnsibleFilterError("Unable to process file: %s" % to_native(e))
|
||||
raise AnsibleFilterError(f"Unable to process file: {e}")
|
||||
|
||||
return data_list
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ from ansible.errors import AnsibleFilterError
|
|||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.six.moves import StringIO
|
||||
from ansible.module_utils.six.moves.configparser import ConfigParser
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
|
||||
class IniParser(ConfigParser):
|
||||
|
@ -83,8 +82,7 @@ def from_ini(obj):
|
|||
try:
|
||||
parser.read_file(StringIO(obj))
|
||||
except Exception as ex:
|
||||
raise AnsibleFilterError(f'from_ini failed to parse given string: '
|
||||
f'{to_native(ex)}', orig_exc=ex)
|
||||
raise AnsibleFilterError(f'from_ini failed to parse given string: {ex}', orig_exc=ex)
|
||||
|
||||
return parser.as_dict()
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ from ansible.errors import AnsibleFilterError
|
|||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
from ansible.module_utils.six.moves import StringIO
|
||||
from ansible.module_utils.six.moves.configparser import ConfigParser
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
|
||||
class IniParser(ConfigParser):
|
||||
|
@ -79,7 +78,7 @@ def to_ini(obj):
|
|||
ini_parser.read_dict(obj)
|
||||
except Exception as ex:
|
||||
raise AnsibleFilterError('to_ini failed to parse given dict:'
|
||||
f'{to_native(ex)}', orig_exc=ex)
|
||||
f'{ex}', orig_exc=ex)
|
||||
|
||||
# catching empty dicts
|
||||
if obj == dict():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue