File: objects.py

package info (click to toggle)
ansible-core 2.19.0~beta6-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,628 kB
  • sloc: python: 180,313; cs: 4,929; sh: 4,601; xml: 34; makefile: 21
file content (67 lines) | stat: -rw-r--r-- 2,150 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Backwards compatibility types, which will be deprecated a future release. Do not use these in new code."""

from __future__ import annotations as _annotations

import typing as _t

from ansible.module_utils._internal import _datatag
from ansible.module_utils.common.text import converters as _converters
from ansible.parsing import vault as _vault

_UNSET = _t.cast(_t.Any, object())


class _AnsibleMapping(dict):
    """Backwards compatibility type."""

    def __new__(cls, value=_UNSET, /, **kwargs):
        if value is _UNSET:
            return dict(**kwargs)

        return _datatag.AnsibleTagHelper.tag_copy(value, dict(value, **kwargs))


class _AnsibleUnicode(str):
    """Backwards compatibility type."""

    def __new__(cls, object=_UNSET, **kwargs):
        if object is _UNSET:
            return str(**kwargs)

        return _datatag.AnsibleTagHelper.tag_copy(object, str(object, **kwargs))


class _AnsibleSequence(list):
    """Backwards compatibility type."""

    def __new__(cls, value=_UNSET, /):
        if value is _UNSET:
            return list()

        return _datatag.AnsibleTagHelper.tag_copy(value, list(value))


class _AnsibleVaultEncryptedUnicode:
    """Backwards compatibility type."""

    def __new__(cls, ciphertext: str | bytes):
        encrypted_string = _vault.EncryptedString(ciphertext=_converters.to_text(_datatag.AnsibleTagHelper.untag(ciphertext)))

        return _datatag.AnsibleTagHelper.tag_copy(ciphertext, encrypted_string)


def __getattr__(name: str) -> _t.Any:
    """Inject import-time deprecation warnings."""
    if (value := globals().get(f'_{name}', None)) and name.startswith('Ansible'):
        # deprecated: description='enable deprecation of everything in this module', core_version='2.23'
        # from ansible.utils.display import Display
        #
        # Display().deprecated(
        #     msg=f"Importing {name!r} is deprecated.",
        #     help_text="Instances of this type cannot be created and will not be encountered.",
        #     version="2.27",
        # )

        return value

    raise AttributeError(f'module {__name__!r} has no attribute {name!r}')