Replace to_native with to_text. (#897)

This commit is contained in:
Felix Fontein
2025-05-18 01:31:33 +02:00
committed by GitHub
parent 9b8e4e81a9
commit 7294841a28
19 changed files with 48 additions and 48 deletions

View File

@@ -225,7 +225,7 @@ output_json:
import typing as t
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
ACMEClient,
create_backend,
@@ -291,7 +291,7 @@ def main() -> t.NoReturn:
result.update(
{
"headers": info,
"output_text": to_native(data),
"output_text": to_text(data),
}
)
# See if we can parse the result as JSON

View File

@@ -279,7 +279,7 @@ from ssl import (
)
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_bytes, to_native
from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible_collections.community.crypto.plugins.module_utils._crypto.cryptography_support import (
CRYPTOGRAPHY_TIMEZONE,
cryptography_get_extensions_from_cert,
@@ -419,7 +419,7 @@ def main() -> t.NoReturn:
# If the item is a string_type
if isinstance(tls_ctx_option, (str, bytes)):
# Convert tls_ctx_option to a native string
tls_ctx_option_str = to_native(tls_ctx_option)
tls_ctx_option_str = to_text(tls_ctx_option)
# Get the tls_ctx_option_str attribute from ssl
tls_ctx_option_attr = getattr(ssl, tls_ctx_option_str, None)
# If tls_ctx_option_attr is an integer

View File

@@ -424,7 +424,7 @@ import typing as t
from base64 import b64decode
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_bytes, to_native
from ansible.module_utils.common.text.converters import to_bytes, to_text
# used to get <luks-name> out of lsblk output in format 'crypt <luks-name>'
@@ -487,7 +487,7 @@ class Handler:
if self._passphrase_encoding == "text":
return to_bytes(passphrase)
try:
return b64decode(to_native(passphrase))
return b64decode(to_text(passphrase))
except Exception as exc:
self._module.fail_json(
f"Error while base64-decoding '{parameter_name}': {exc}"

View File

@@ -135,7 +135,7 @@ import tempfile
import typing as t
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ansible.module_utils.common.text.converters import to_text
from ansible_collections.community.crypto.plugins.module_utils._crypto.math import (
count_bits,
)
@@ -298,7 +298,7 @@ class DHParameterOpenSSL(DHParameterBase):
self.path,
]
rc, out, err = module.run_command(command, check_rc=False)
result = to_native(out)
result = to_text(out)
if rc != 0:
# If the call failed the file probably does not exist or is
# unreadable
@@ -311,7 +311,7 @@ class DHParameterOpenSSL(DHParameterBase):
bits = int(match.group(1))
# if output contains "WARNING" we've got a problem
if "WARNING" in result or "WARNING" in to_native(err):
if "WARNING" in result or "WARNING" in to_text(err):
return False
return bits == self.size

View File

@@ -282,7 +282,7 @@ import traceback
import typing as t
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_bytes, to_native
from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
OpenSSLBadPassphraseError,
OpenSSLObjectError,
@@ -559,7 +559,7 @@ class Pkcs(OpenSSLObject):
expected_content = to_bytes(
"".join(
[
to_native(pem)
to_text(pem)
for pem in [pkey, cert] + other_certs
if pem is not None
]
@@ -848,7 +848,7 @@ def main() -> t.NoReturn:
pkey, cert, other_certs, _friendly_name = pkcs12.parse()
dump_content = "".join(
[
to_native(pem)
to_text(pem)
for pem in [pkey, cert] + other_certs
if pem is not None
]