Skip to content

Commit 1fa32d0

Browse files
committed
docs(txt.py): document the Ansible origin of to_text/to_bytes
1 parent 13b851a commit 1fa32d0

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

txt.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
"""A collection of text functions.
1212
13-
The functions "to_text()" and "to_bytes()" were originally copied
14-
from Ansible's module_utils/_text.py (BSD license), then simplified
15-
for Python 3 only.
13+
The functions "to_text()" and "to_bytes()" were originally copied from
14+
Ansible (BSD license), then simplified for Python 3 only. Upstream now
15+
lives at ansible/module_utils/common/text/converters.py (historically
16+
module_utils/_text.py); see the comment above to_bytes() for what we
17+
intentionally left out and where to re-check it.
1618
"""
1719

1820
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
19-
__version__ = '2026032101'
21+
__version__ = '2026060201'
2022

2123
import operator
2224
import re
@@ -459,6 +461,15 @@ def sanitize_sensitive_data(msg, replacement='******'):
459461
return msg
460462

461463

464+
# `to_bytes` and `to_text` below are an extraction of Ansible's text converters
465+
# with the object-oriented and typing scaffolding stripped for our Python 3.9+
466+
# use-case. Look here if upstream behaviour ever needs to be re-checked or synced:
467+
# ansible/lib/ansible/module_utils/common/text/converters.py (to_bytes, to_text)
468+
# Original under the Simplified BSD License, (c) 2016 Toshio Kuratomi / Ansible
469+
# project. Deliberate omissions vs. upstream: the Python 2 fallback for when the
470+
# `surrogateescape` error handler is unavailable (it always is on Python 3), and
471+
# the str() -> repr() -> empty UnicodeError guard in the `simplerepr` path
472+
# (irrelevant for the command output and numbers we convert).
462473
def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
463474
"""
464475
Convert an object to a byte string.

0 commit comments

Comments
 (0)