| 1 |
# Copyright (c), Toshio Kuratomi <[email protected]> 2016 |
| 2 |
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
|
| 6 |
from ansible.module_utils.common import warnings as _warnings |
| 7 |
|
| 8 |
|
| 9 |
_mini_six = { |
| 10 |
"binary_type": bytes, |
| 11 |
"text_type": str, |
| 12 |
"PY3": True, |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
def __getattr__(importable_name: str) -> object: |
| 17 |
"""Inject import-time deprecation warnings.""" |
| 18 |
help_text: str | None = None |
| 19 |
importable: object |
| 20 |
if importable_name == "codecs": |
| 21 |
import codecs |
| 22 |
importable = codecs |
| 23 |
elif importable_name in {"to_bytes", "to_native", "to_text"}: |
| 24 |
from ansible.module_utils.common.text import converters |
| 25 |
importable = getattr(converters, importable_name) |
| 26 |
help_text = "Use ansible.module_utils.common.text.converters instead." |
| 27 |
elif (importable := _mini_six.get(importable_name, ...)) is ...: |
| 28 |
raise AttributeError(f"module {__name__!r} has no attribute {importable_name!r}") |
| 29 |
|
| 30 |
_warnings.deprecate( |
| 31 |
msg=f"Importing {importable_name!r} from {__name__!r} is deprecated.", |
| 32 |
version="2.24", |
| 33 |
help_text=help_text, |
| 34 |
) |
| 35 |
return importable |