|
10 | 10 |
|
11 | 11 | """A collection of text functions. |
12 | 12 |
|
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. |
16 | 18 | """ |
17 | 19 |
|
18 | 20 | __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' |
19 | | -__version__ = '2026032101' |
| 21 | +__version__ = '2026060201' |
20 | 22 |
|
21 | 23 | import operator |
22 | 24 | import re |
@@ -459,6 +461,15 @@ def sanitize_sensitive_data(msg, replacement='******'): |
459 | 461 | return msg |
460 | 462 |
|
461 | 463 |
|
| 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). |
462 | 473 | def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'): |
463 | 474 | """ |
464 | 475 | Convert an object to a byte string. |
|
0 commit comments