Debian Codegraph @

lib/ansible/parsing/yaml/objects.py

raw
1 """Backwards compatibility types, which will be deprecated a future release. Do not use these in new code."""
2
3 from __future__ import annotations as _annotations
4
5 import typing as _t
6
7 from ansible.module_utils._internal import _datatag
8 from ansible.module_utils.common.text import converters as _converters
9 from ansible.parsing import vault as _vault
10
11 _UNSET = _t.cast(_t.Any, object())
12
13
14 class _AnsibleMapping(dict):
15 """Backwards compatibility type."""
16
17 def __new__(cls, value=_UNSET, /, **kwargs):
18 if value is _UNSET:
19 return dict(**kwargs)
20
21 return _datatag.AnsibleTagHelper.tag_copy(value, dict(value, **kwargs))
22
23
24 class _AnsibleUnicode(str):
25 """Backwards compatibility type."""
26
27 def __new__(cls, object=_UNSET, **kwargs):
28 if object is _UNSET:
29 return str(**kwargs)
30
31 return _datatag.AnsibleTagHelper.tag_copy(object, str(object, **kwargs))
32
33
34 class _AnsibleSequence(list):
35 """Backwards compatibility type."""
36
37 def __new__(cls, value=_UNSET, /):
38 if value is _UNSET:
39 return list()
40
41 return _datatag.AnsibleTagHelper.tag_copy(value, list(value))
42
43
44 class _AnsibleVaultEncryptedUnicode:
45 """Backwards compatibility type."""
46
47 def __new__(cls, ciphertext: str | bytes):
48 encrypted_string = _vault.EncryptedString(ciphertext=_converters.to_text(_datatag.AnsibleTagHelper.untag(ciphertext)))
49
50 return _datatag.AnsibleTagHelper.tag_copy(ciphertext, encrypted_string)
51
52
53 def __getattr__(name: str) -> _t.Any:
54 """Inject import-time deprecation warnings."""
55 if (value := globals().get(f'_{name}', None)) and name.startswith('Ansible'):
56 # deprecated: description='enable deprecation of everything in this module', core_version='2.23'
57 # from ansible.utils.display import Display
58 #
59 # Display().deprecated(
60 # msg=f"Importing {name!r} is deprecated.",
61 # help_text="Instances of this type cannot be created and will not be encountered.",
62 # version="2.27",
63 # )
64
65 return value
66
67 raise AttributeError(f'module {__name__!r} has no attribute {name!r}')