mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -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
|
@ -220,7 +220,6 @@ RETURN = """
|
|||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.utils.display import Display
|
||||
import socket
|
||||
|
@ -345,7 +344,7 @@ class LookupModule(LookupBase):
|
|||
try:
|
||||
rdclass = dns.rdataclass.from_text(self.get_option('class'))
|
||||
except Exception as e:
|
||||
raise AnsibleError(f"dns lookup illegal CLASS: {to_native(e)}")
|
||||
raise AnsibleError(f"dns lookup illegal CLASS: {e}")
|
||||
myres.retry_servfail = self.get_option('retry_servfail')
|
||||
|
||||
for t in terms:
|
||||
|
@ -363,7 +362,7 @@ class LookupModule(LookupBase):
|
|||
nsaddr = dns.resolver.query(ns)[0].address
|
||||
nameservers.append(nsaddr)
|
||||
except Exception as e:
|
||||
raise AnsibleError(f"dns lookup NS: {to_native(e)}")
|
||||
raise AnsibleError(f"dns lookup NS: {e}")
|
||||
continue
|
||||
if '=' in t:
|
||||
try:
|
||||
|
@ -379,7 +378,7 @@ class LookupModule(LookupBase):
|
|||
try:
|
||||
rdclass = dns.rdataclass.from_text(arg)
|
||||
except Exception as e:
|
||||
raise AnsibleError(f"dns lookup illegal CLASS: {to_native(e)}")
|
||||
raise AnsibleError(f"dns lookup illegal CLASS: {e}")
|
||||
elif opt == 'retry_servfail':
|
||||
myres.retry_servfail = boolean(arg)
|
||||
elif opt == 'fail_on_error':
|
||||
|
@ -416,7 +415,7 @@ class LookupModule(LookupBase):
|
|||
except dns.exception.SyntaxError:
|
||||
pass
|
||||
except Exception as e:
|
||||
raise AnsibleError(f"dns.reversename unhandled exception {to_native(e)}")
|
||||
raise AnsibleError(f"dns.reversename unhandled exception {e}")
|
||||
domains = reversed_domains
|
||||
|
||||
if len(domains) > 1:
|
||||
|
@ -445,20 +444,20 @@ class LookupModule(LookupBase):
|
|||
ret.append(rd)
|
||||
except Exception as err:
|
||||
if fail_on_error:
|
||||
raise AnsibleError(f"Lookup failed: {str(err)}")
|
||||
raise AnsibleError(f"Lookup failed: {err}")
|
||||
ret.append(str(err))
|
||||
|
||||
except dns.resolver.NXDOMAIN as err:
|
||||
if fail_on_error:
|
||||
raise AnsibleError(f"Lookup failed: {str(err)}")
|
||||
raise AnsibleError(f"Lookup failed: {err}")
|
||||
if not real_empty:
|
||||
ret.append('NXDOMAIN')
|
||||
except (dns.resolver.NoAnswer, dns.resolver.Timeout, dns.resolver.NoNameservers) as err:
|
||||
if fail_on_error:
|
||||
raise AnsibleError(f"Lookup failed: {str(err)}")
|
||||
raise AnsibleError(f"Lookup failed: {err}")
|
||||
if not real_empty:
|
||||
ret.append("")
|
||||
except dns.exception.DNSException as err:
|
||||
raise AnsibleError(f"dns.resolver unhandled exception {to_native(err)}")
|
||||
raise AnsibleError(f"dns.resolver unhandled exception {err}")
|
||||
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue