ansible-core 2.18.5rc1__py3-none-any.whl → 2.19.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ansible/_internal/__init__.py +53 -0
- ansible/_internal/_ansiballz.py +265 -0
- ansible/_internal/_datatag/__init__.py +0 -0
- ansible/_internal/_datatag/_tags.py +130 -0
- ansible/_internal/_datatag/_utils.py +19 -0
- ansible/_internal/_datatag/_wrappers.py +33 -0
- ansible/_internal/_errors/__init__.py +0 -0
- ansible/_internal/_errors/_captured.py +128 -0
- ansible/_internal/_errors/_handler.py +91 -0
- ansible/_internal/_errors/_utils.py +310 -0
- ansible/_internal/_json/__init__.py +160 -0
- ansible/_internal/_json/_legacy_encoder.py +34 -0
- ansible/_internal/_json/_profiles/__init__.py +0 -0
- ansible/_internal/_json/_profiles/_cache_persistence.py +55 -0
- ansible/_internal/_json/_profiles/_inventory_legacy.py +40 -0
- ansible/_internal/_json/_profiles/_legacy.py +198 -0
- ansible/_internal/_locking.py +21 -0
- ansible/_internal/_plugins/__init__.py +0 -0
- ansible/_internal/_plugins/_cache.py +57 -0
- ansible/_internal/_task.py +78 -0
- ansible/_internal/_templating/__init__.py +10 -0
- ansible/_internal/_templating/_access.py +86 -0
- ansible/_internal/_templating/_chain_templar.py +63 -0
- ansible/_internal/_templating/_datatag.py +95 -0
- ansible/_internal/_templating/_engine.py +588 -0
- ansible/_internal/_templating/_errors.py +28 -0
- ansible/_internal/_templating/_jinja_bits.py +1066 -0
- ansible/_internal/_templating/_jinja_common.py +332 -0
- ansible/_internal/_templating/_jinja_patches.py +44 -0
- ansible/_internal/_templating/_jinja_plugins.py +351 -0
- ansible/_internal/_templating/_lazy_containers.py +633 -0
- ansible/_internal/_templating/_marker_behaviors.py +103 -0
- ansible/_internal/_templating/_transform.py +63 -0
- ansible/_internal/_templating/_utils.py +107 -0
- ansible/_internal/_wrapt.py +1052 -0
- ansible/_internal/_yaml/__init__.py +0 -0
- ansible/_internal/_yaml/_constructor.py +240 -0
- ansible/_internal/_yaml/_dumper.py +62 -0
- ansible/_internal/_yaml/_errors.py +166 -0
- ansible/_internal/_yaml/_loader.py +66 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/README.md +11 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/action/debug.py +36 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/apply_trust.py +19 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/dump_object.py +18 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/finalize.py +16 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/origin.py +18 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/python_literal_eval.py +24 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/python_literal_eval.yml +33 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/tag_names.py +16 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/true_type.py +17 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/filter/unmask.py +49 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/lookup/config.py +21 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/lookup/config.yml +2 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/test/tagged.py +15 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/test/tagged.yml +19 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/test/tagged_with.py +18 -0
- ansible/_internal/ansible_collections/ansible/_protomatter/plugins/test/tagged_with.yml +19 -0
- ansible/cli/__init__.py +153 -89
- ansible/cli/_ssh_askpass.py +47 -0
- ansible/cli/adhoc.py +14 -7
- ansible/cli/arguments/option_helpers.py +154 -7
- ansible/cli/config.py +43 -68
- ansible/cli/console.py +10 -8
- ansible/cli/doc.py +48 -46
- ansible/cli/galaxy.py +27 -20
- ansible/cli/inventory.py +28 -26
- ansible/cli/playbook.py +4 -12
- ansible/cli/pull.py +51 -11
- ansible/cli/scripts/ansible_connection_cli_stub.py +7 -7
- ansible/cli/vault.py +12 -11
- ansible/compat/__init__.py +2 -2
- ansible/config/base.yml +165 -108
- ansible/config/manager.py +52 -49
- ansible/constants.py +3 -4
- ansible/errors/__init__.py +277 -235
- ansible/executor/interpreter_discovery.py +28 -149
- ansible/executor/module_common.py +426 -493
- ansible/executor/play_iterator.py +22 -27
- ansible/executor/playbook_executor.py +11 -11
- ansible/executor/powershell/async_watchdog.ps1 +97 -102
- ansible/executor/powershell/async_wrapper.ps1 +202 -151
- ansible/executor/powershell/become_wrapper.ps1 +89 -144
- ansible/executor/powershell/bootstrap_wrapper.ps1 +24 -9
- ansible/executor/powershell/coverage_wrapper.ps1 +82 -135
- ansible/executor/powershell/exec_wrapper.ps1 +462 -196
- ansible/executor/powershell/module_manifest.py +417 -265
- ansible/executor/powershell/module_wrapper.ps1 +169 -186
- ansible/executor/powershell/psrp_fetch_file.ps1 +41 -0
- ansible/executor/powershell/psrp_put_file.ps1 +122 -0
- ansible/executor/powershell/winrm_fetch_file.ps1 +46 -0
- ansible/executor/powershell/winrm_put_file.ps1 +36 -0
- ansible/executor/process/worker.py +136 -76
- ansible/executor/stats.py +5 -5
- ansible/executor/task_executor.py +237 -236
- ansible/executor/task_queue_manager.py +62 -38
- ansible/executor/task_result.py +21 -12
- ansible/galaxy/__init__.py +2 -2
- ansible/galaxy/api.py +22 -18
- ansible/galaxy/collection/__init__.py +1 -1
- ansible/galaxy/collection/concrete_artifact_manager.py +8 -11
- ansible/galaxy/dependency_resolution/dataclasses.py +14 -4
- ansible/galaxy/dependency_resolution/providers.py +1 -1
- ansible/galaxy/dependency_resolution/reporters.py +81 -0
- ansible/galaxy/role.py +4 -8
- ansible/galaxy/token.py +28 -21
- ansible/inventory/data.py +47 -57
- ansible/inventory/group.py +44 -72
- ansible/inventory/helpers.py +9 -0
- ansible/inventory/host.py +32 -54
- ansible/inventory/manager.py +77 -34
- ansible/keyword_desc.yml +1 -1
- ansible/module_utils/_internal/__init__.py +55 -0
- ansible/module_utils/_internal/_ambient_context.py +58 -0
- ansible/module_utils/_internal/_ansiballz.py +133 -0
- ansible/module_utils/_internal/_concurrent/_daemon_threading.py +1 -0
- ansible/module_utils/_internal/_dataclass_annotation_patch.py +64 -0
- ansible/module_utils/_internal/_dataclass_validation.py +217 -0
- ansible/module_utils/_internal/_datatag/__init__.py +928 -0
- ansible/module_utils/_internal/_datatag/_tags.py +38 -0
- ansible/module_utils/_internal/_debugging.py +31 -0
- ansible/module_utils/_internal/_errors.py +30 -0
- ansible/module_utils/_internal/_json/__init__.py +63 -0
- ansible/module_utils/_internal/_json/_legacy_encoder.py +26 -0
- ansible/module_utils/_internal/_json/_profiles/__init__.py +410 -0
- ansible/module_utils/_internal/_json/_profiles/_fallback_to_str.py +73 -0
- ansible/module_utils/_internal/_json/_profiles/_module_legacy_c2m.py +31 -0
- ansible/module_utils/_internal/_json/_profiles/_module_legacy_m2c.py +35 -0
- ansible/module_utils/_internal/_json/_profiles/_module_modern_c2m.py +35 -0
- ansible/module_utils/_internal/_json/_profiles/_module_modern_m2c.py +33 -0
- ansible/module_utils/_internal/_json/_profiles/_tagless.py +50 -0
- ansible/module_utils/_internal/_patches/__init__.py +66 -0
- ansible/module_utils/_internal/_patches/_dataclass_annotation_patch.py +55 -0
- ansible/module_utils/_internal/_patches/_socket_patch.py +34 -0
- ansible/module_utils/_internal/_patches/_sys_intern_patch.py +34 -0
- ansible/module_utils/_internal/_plugin_exec_context.py +49 -0
- ansible/module_utils/_internal/_testing.py +0 -0
- ansible/module_utils/_internal/_traceback.py +89 -0
- ansible/module_utils/ansible_release.py +2 -2
- ansible/module_utils/api.py +1 -2
- ansible/module_utils/basic.py +154 -120
- ansible/module_utils/common/_utils.py +24 -28
- ansible/module_utils/common/collections.py +1 -2
- ansible/module_utils/common/dict_transformations.py +2 -2
- ansible/module_utils/common/file.py +2 -2
- ansible/module_utils/common/json.py +90 -84
- ansible/module_utils/common/locale.py +2 -2
- ansible/module_utils/common/messages.py +108 -0
- ansible/module_utils/common/parameters.py +27 -24
- ansible/module_utils/common/process.py +2 -2
- ansible/module_utils/common/respawn.py +41 -19
- ansible/module_utils/common/sentinel.py +66 -0
- ansible/module_utils/common/sys_info.py +8 -8
- ansible/module_utils/common/text/converters.py +16 -37
- ansible/module_utils/common/validation.py +35 -24
- ansible/module_utils/common/warnings.py +86 -25
- ansible/module_utils/common/yaml.py +29 -3
- ansible/module_utils/compat/datetime.py +33 -21
- ansible/module_utils/compat/paramiko.py +21 -10
- ansible/module_utils/compat/typing.py +6 -5
- ansible/module_utils/connection.py +2 -2
- ansible/module_utils/csharp/Ansible.Basic.cs +14 -11
- ansible/module_utils/csharp/Ansible.Become.cs +1 -0
- ansible/module_utils/csharp/Ansible._Async.cs +517 -0
- ansible/module_utils/datatag.py +46 -0
- ansible/module_utils/distro/__init__.py +2 -2
- ansible/module_utils/facts/ansible_collector.py +4 -5
- ansible/module_utils/facts/collector.py +13 -14
- ansible/module_utils/facts/compat.py +4 -4
- ansible/module_utils/facts/default_collectors.py +1 -1
- ansible/module_utils/facts/hardware/aix.py +34 -0
- ansible/module_utils/facts/hardware/base.py +1 -1
- ansible/module_utils/facts/hardware/darwin.py +1 -3
- ansible/module_utils/facts/hardware/freebsd.py +2 -2
- ansible/module_utils/facts/hardware/linux.py +4 -4
- ansible/module_utils/facts/namespace.py +1 -1
- ansible/module_utils/facts/network/base.py +1 -1
- ansible/module_utils/facts/network/fc_wwn.py +1 -2
- ansible/module_utils/facts/network/iscsi.py +1 -2
- ansible/module_utils/facts/network/nvme.py +1 -2
- ansible/module_utils/facts/other/facter.py +1 -2
- ansible/module_utils/facts/other/ohai.py +2 -3
- ansible/module_utils/facts/system/apparmor.py +1 -2
- ansible/module_utils/facts/system/caps.py +1 -1
- ansible/module_utils/facts/system/chroot.py +1 -2
- ansible/module_utils/facts/system/cmdline.py +1 -2
- ansible/module_utils/facts/system/date_time.py +5 -3
- ansible/module_utils/facts/system/distribution.py +9 -8
- ansible/module_utils/facts/system/dns.py +1 -1
- ansible/module_utils/facts/system/env.py +1 -2
- ansible/module_utils/facts/system/fips.py +7 -20
- ansible/module_utils/facts/system/loadavg.py +1 -2
- ansible/module_utils/facts/system/local.py +1 -2
- ansible/module_utils/facts/system/lsb.py +1 -2
- ansible/module_utils/facts/system/pkg_mgr.py +1 -2
- ansible/module_utils/facts/system/platform.py +1 -2
- ansible/module_utils/facts/system/python.py +1 -2
- ansible/module_utils/facts/system/selinux.py +1 -1
- ansible/module_utils/facts/system/service_mgr.py +1 -2
- ansible/module_utils/facts/system/ssh_pub_keys.py +1 -1
- ansible/module_utils/facts/system/systemd.py +1 -1
- ansible/module_utils/facts/system/user.py +1 -2
- ansible/module_utils/facts/utils.py +3 -3
- ansible/module_utils/facts/virtual/base.py +1 -1
- ansible/module_utils/facts/virtual/sunos.py +3 -15
- ansible/module_utils/facts/virtual/sysctl.py +3 -16
- ansible/module_utils/json_utils.py +2 -2
- ansible/module_utils/parsing/convert_bool.py +1 -1
- ansible/module_utils/service.py +18 -21
- ansible/module_utils/splitter.py +7 -7
- ansible/module_utils/testing.py +31 -0
- ansible/module_utils/urls.py +60 -31
- ansible/modules/add_host.py +4 -4
- ansible/modules/apt.py +60 -46
- ansible/modules/apt_key.py +19 -12
- ansible/modules/apt_repository.py +19 -16
- ansible/modules/assemble.py +6 -6
- ansible/modules/assert.py +4 -4
- ansible/modules/async_status.py +10 -12
- ansible/modules/async_wrapper.py +8 -3
- ansible/modules/blockinfile.py +6 -7
- ansible/modules/command.py +10 -17
- ansible/modules/copy.py +57 -144
- ansible/modules/cron.py +20 -15
- ansible/modules/deb822_repository.py +8 -9
- ansible/modules/debconf.py +5 -5
- ansible/modules/debug.py +4 -4
- ansible/modules/dnf.py +8 -8
- ansible/modules/dnf5.py +39 -13
- ansible/modules/dpkg_selections.py +4 -4
- ansible/modules/expect.py +8 -10
- ansible/modules/fail.py +4 -4
- ansible/modules/fetch.py +4 -4
- ansible/modules/file.py +174 -133
- ansible/modules/find.py +19 -17
- ansible/modules/gather_facts.py +3 -3
- ansible/modules/get_url.py +59 -53
- ansible/modules/getent.py +7 -9
- ansible/modules/git.py +28 -25
- ansible/modules/group.py +6 -6
- ansible/modules/group_by.py +4 -4
- ansible/modules/hostname.py +13 -29
- ansible/modules/import_playbook.py +6 -6
- ansible/modules/import_role.py +6 -6
- ansible/modules/import_tasks.py +6 -6
- ansible/modules/include_role.py +6 -6
- ansible/modules/include_tasks.py +6 -6
- ansible/modules/include_vars.py +6 -6
- ansible/modules/iptables.py +86 -73
- ansible/modules/known_hosts.py +10 -10
- ansible/modules/lineinfile.py +5 -5
- ansible/modules/meta.py +4 -4
- ansible/modules/mount_facts.py +2 -2
- ansible/modules/package.py +4 -4
- ansible/modules/package_facts.py +22 -10
- ansible/modules/pause.py +6 -6
- ansible/modules/ping.py +6 -6
- ansible/modules/pip.py +10 -11
- ansible/modules/raw.py +4 -4
- ansible/modules/reboot.py +6 -6
- ansible/modules/replace.py +9 -13
- ansible/modules/rpm_key.py +7 -8
- ansible/modules/script.py +4 -4
- ansible/modules/service.py +7 -8
- ansible/modules/service_facts.py +87 -10
- ansible/modules/set_fact.py +5 -5
- ansible/modules/set_stats.py +4 -4
- ansible/modules/setup.py +2 -2
- ansible/modules/shell.py +6 -6
- ansible/modules/slurp.py +6 -6
- ansible/modules/stat.py +9 -23
- ansible/modules/subversion.py +15 -15
- ansible/modules/systemd.py +6 -6
- ansible/modules/systemd_service.py +6 -6
- ansible/modules/sysvinit.py +6 -6
- ansible/modules/tempfile.py +5 -6
- ansible/modules/template.py +6 -6
- ansible/modules/unarchive.py +32 -11
- ansible/modules/uri.py +33 -26
- ansible/modules/user.py +53 -34
- ansible/modules/validate_argument_spec.py +10 -7
- ansible/modules/wait_for.py +32 -27
- ansible/modules/wait_for_connection.py +6 -6
- ansible/modules/yum_repository.py +6 -6
- ansible/parsing/ajson.py +14 -32
- ansible/parsing/dataloader.py +99 -54
- ansible/parsing/mod_args.py +28 -44
- ansible/parsing/plugin_docs.py +21 -86
- ansible/parsing/quoting.py +1 -1
- ansible/parsing/splitter.py +27 -12
- ansible/parsing/utils/addresses.py +24 -24
- ansible/parsing/utils/yaml.py +32 -61
- ansible/parsing/vault/__init__.py +319 -87
- ansible/parsing/yaml/__init__.py +0 -18
- ansible/parsing/yaml/dumper.py +6 -120
- ansible/parsing/yaml/loader.py +6 -39
- ansible/parsing/yaml/objects.py +36 -339
- ansible/playbook/__init__.py +1 -1
- ansible/playbook/attribute.py +8 -3
- ansible/playbook/base.py +182 -132
- ansible/playbook/block.py +26 -24
- ansible/playbook/collectionsearch.py +1 -15
- ansible/playbook/conditional.py +3 -77
- ansible/playbook/handler.py +8 -2
- ansible/playbook/helpers.py +41 -53
- ansible/playbook/included_file.py +6 -15
- ansible/playbook/loop_control.py +2 -2
- ansible/playbook/play.py +85 -44
- ansible/playbook/play_context.py +12 -17
- ansible/playbook/playbook_include.py +14 -15
- ansible/playbook/role/__init__.py +24 -26
- ansible/playbook/role/definition.py +15 -17
- ansible/playbook/role/include.py +2 -4
- ansible/playbook/role/metadata.py +10 -11
- ansible/playbook/role_include.py +3 -3
- ansible/playbook/taggable.py +13 -8
- ansible/playbook/task.py +188 -118
- ansible/playbook/task_include.py +5 -5
- ansible/plugins/__init__.py +68 -21
- ansible/plugins/action/__init__.py +209 -176
- ansible/plugins/action/add_host.py +1 -1
- ansible/plugins/action/assemble.py +1 -1
- ansible/plugins/action/assert.py +54 -66
- ansible/plugins/action/copy.py +7 -11
- ansible/plugins/action/debug.py +37 -31
- ansible/plugins/action/dnf.py +3 -4
- ansible/plugins/action/fail.py +1 -1
- ansible/plugins/action/fetch.py +4 -5
- ansible/plugins/action/gather_facts.py +7 -6
- ansible/plugins/action/group_by.py +1 -1
- ansible/plugins/action/include_vars.py +10 -11
- ansible/plugins/action/package.py +3 -6
- ansible/plugins/action/pause.py +2 -2
- ansible/plugins/action/script.py +15 -8
- ansible/plugins/action/service.py +6 -11
- ansible/plugins/action/set_fact.py +3 -12
- ansible/plugins/action/set_stats.py +3 -8
- ansible/plugins/action/template.py +35 -59
- ansible/plugins/action/unarchive.py +1 -1
- ansible/plugins/action/validate_argument_spec.py +5 -5
- ansible/plugins/action/wait_for_connection.py +1 -1
- ansible/plugins/become/__init__.py +31 -8
- ansible/plugins/become/runas.py +71 -0
- ansible/plugins/become/su.py +13 -8
- ansible/plugins/become/sudo.py +19 -0
- ansible/plugins/cache/__init__.py +35 -44
- ansible/plugins/cache/base.py +8 -0
- ansible/plugins/cache/jsonfile.py +10 -16
- ansible/plugins/cache/memory.py +6 -12
- ansible/plugins/callback/__init__.py +141 -123
- ansible/plugins/callback/default.py +30 -23
- ansible/plugins/callback/junit.py +28 -24
- ansible/plugins/callback/minimal.py +17 -14
- ansible/plugins/callback/oneline.py +13 -7
- ansible/plugins/callback/tree.py +10 -6
- ansible/plugins/connection/__init__.py +47 -34
- ansible/plugins/connection/local.py +150 -54
- ansible/plugins/connection/paramiko_ssh.py +21 -18
- ansible/plugins/connection/psrp.py +76 -165
- ansible/plugins/connection/ssh.py +301 -78
- ansible/plugins/connection/winrm.py +58 -140
- ansible/plugins/doc_fragments/action_common_attributes.py +14 -14
- ansible/plugins/doc_fragments/action_core.py +6 -6
- ansible/plugins/doc_fragments/backup.py +2 -2
- ansible/plugins/doc_fragments/checksum_common.py +27 -0
- ansible/plugins/doc_fragments/constructed.py +6 -2
- ansible/plugins/doc_fragments/decrypt.py +2 -2
- ansible/plugins/doc_fragments/default_callback.py +2 -2
- ansible/plugins/doc_fragments/files.py +2 -2
- ansible/plugins/doc_fragments/inventory_cache.py +2 -2
- ansible/plugins/doc_fragments/result_format_callback.py +2 -2
- ansible/plugins/doc_fragments/return_common.py +2 -2
- ansible/plugins/doc_fragments/template_common.py +4 -4
- ansible/plugins/doc_fragments/url.py +17 -1
- ansible/plugins/doc_fragments/url_windows.py +2 -2
- ansible/plugins/doc_fragments/validate.py +2 -2
- ansible/plugins/doc_fragments/vars_plugin_staging.py +2 -2
- ansible/plugins/filter/__init__.py +6 -2
- ansible/plugins/filter/b64decode.yml +22 -0
- ansible/plugins/filter/b64encode.yml +22 -0
- ansible/plugins/filter/bool.yml +11 -4
- ansible/plugins/filter/core.py +218 -108
- ansible/plugins/filter/encryption.py +32 -32
- ansible/plugins/filter/flatten.yml +3 -2
- ansible/plugins/filter/human_to_bytes.yml +1 -1
- ansible/plugins/filter/mathstuff.py +30 -37
- ansible/plugins/filter/password_hash.yml +8 -0
- ansible/plugins/filter/regex_search.yml +1 -4
- ansible/plugins/filter/split.yml +1 -1
- ansible/plugins/filter/to_nice_yaml.yml +0 -4
- ansible/plugins/filter/to_yaml.yml +0 -4
- ansible/plugins/filter/unvault.yml +1 -1
- ansible/plugins/filter/urls.py +1 -1
- ansible/plugins/filter/urlsplit.py +8 -9
- ansible/plugins/filter/vault.yml +14 -9
- ansible/plugins/filter/win_basename.yml +6 -1
- ansible/plugins/filter/win_dirname.yml +5 -0
- ansible/plugins/inventory/__init__.py +97 -77
- ansible/plugins/inventory/advanced_host_list.py +7 -5
- ansible/plugins/inventory/auto.py +11 -4
- ansible/plugins/inventory/constructed.py +21 -24
- ansible/plugins/inventory/generator.py +16 -11
- ansible/plugins/inventory/host_list.py +7 -5
- ansible/plugins/inventory/ini.py +78 -44
- ansible/plugins/inventory/script.py +189 -119
- ansible/plugins/inventory/toml.py +16 -126
- ansible/plugins/inventory/yaml.py +10 -8
- ansible/plugins/list.py +3 -3
- ansible/plugins/loader.py +197 -82
- ansible/plugins/lookup/__init__.py +21 -4
- ansible/plugins/lookup/config.py +21 -35
- ansible/plugins/lookup/csvfile.py +3 -2
- ansible/plugins/lookup/dict.py +1 -6
- ansible/plugins/lookup/env.py +12 -9
- ansible/plugins/lookup/file.py +5 -8
- ansible/plugins/lookup/first_found.py +86 -55
- ansible/plugins/lookup/indexed_items.py +1 -10
- ansible/plugins/lookup/ini.py +14 -13
- ansible/plugins/lookup/items.py +1 -1
- ansible/plugins/lookup/lines.py +8 -1
- ansible/plugins/lookup/list.py +1 -1
- ansible/plugins/lookup/nested.py +2 -18
- ansible/plugins/lookup/password.py +5 -5
- ansible/plugins/lookup/pipe.py +5 -7
- ansible/plugins/lookup/sequence.py +18 -8
- ansible/plugins/lookup/subelements.py +1 -4
- ansible/plugins/lookup/template.py +42 -36
- ansible/plugins/lookup/together.py +0 -12
- ansible/plugins/lookup/unvault.py +1 -5
- ansible/plugins/lookup/url.py +2 -8
- ansible/plugins/lookup/vars.py +16 -24
- ansible/plugins/shell/__init__.py +2 -2
- ansible/plugins/shell/cmd.py +2 -2
- ansible/plugins/shell/powershell.py +39 -22
- ansible/plugins/shell/sh.py +3 -2
- ansible/plugins/strategy/__init__.py +94 -113
- ansible/plugins/strategy/debug.py +2 -2
- ansible/plugins/strategy/free.py +13 -28
- ansible/plugins/strategy/host_pinned.py +2 -2
- ansible/plugins/strategy/linear.py +31 -33
- ansible/plugins/terminal/__init__.py +4 -4
- ansible/plugins/test/__init__.py +7 -2
- ansible/plugins/test/core.py +54 -20
- ansible/plugins/test/files.py +1 -1
- ansible/plugins/test/mathstuff.py +3 -3
- ansible/plugins/test/uri.py +3 -3
- ansible/plugins/vars/host_group_vars.py +7 -14
- ansible/release.py +2 -2
- ansible/template/__init__.py +368 -944
- ansible/utils/__init__.py +0 -18
- ansible/utils/_ssh_agent.py +657 -0
- ansible/utils/collection_loader/__init__.py +52 -5
- ansible/utils/collection_loader/_collection_config.py +5 -6
- ansible/utils/collection_loader/_collection_finder.py +79 -93
- ansible/utils/collection_loader/_collection_meta.py +13 -8
- ansible/utils/display.py +428 -58
- ansible/utils/encrypt.py +27 -19
- ansible/utils/fqcn.py +2 -2
- ansible/utils/hashing.py +2 -2
- ansible/utils/helpers.py +2 -2
- ansible/utils/listify.py +8 -8
- ansible/utils/lock.py +2 -2
- ansible/utils/path.py +4 -4
- ansible/utils/plugin_docs.py +14 -13
- ansible/utils/sentinel.py +4 -62
- ansible/utils/singleton.py +2 -0
- ansible/utils/ssh_functions.py +1 -1
- ansible/utils/unsafe_proxy.py +23 -332
- ansible/utils/vars.py +28 -8
- ansible/utils/version.py +2 -2
- ansible/vars/clean.py +4 -4
- ansible/vars/hostvars.py +60 -90
- ansible/vars/manager.py +205 -264
- ansible/vars/reserved.py +8 -9
- ansible_core-2.19.0b1.dist-info/BSD-3-Clause.txt +28 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/METADATA +5 -4
- ansible_core-2.19.0b1.dist-info/RECORD +1070 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/WHEEL +1 -1
- ansible_test/_data/completion/docker.txt +7 -7
- ansible_test/_data/completion/remote.txt +6 -6
- ansible_test/_data/completion/windows.txt +1 -0
- ansible_test/_data/requirements/ansible.txt +2 -2
- ansible_test/_data/requirements/sanity.ansible-doc.txt +3 -3
- ansible_test/_data/requirements/sanity.changelog.txt +1 -1
- ansible_test/_data/requirements/sanity.import.plugin.txt +2 -2
- ansible_test/_data/requirements/sanity.pylint.txt +4 -4
- ansible_test/_data/requirements/sanity.validate-modules.txt +2 -2
- ansible_test/_data/requirements/sanity.yamllint.txt +1 -1
- ansible_test/_data/requirements/units.txt +1 -0
- ansible_test/_internal/__init__.py +1 -0
- ansible_test/_internal/ansible_util.py +2 -0
- ansible_test/_internal/become.py +1 -0
- ansible_test/_internal/bootstrap.py +1 -0
- ansible_test/_internal/cache.py +1 -0
- ansible_test/_internal/cgroup.py +1 -0
- ansible_test/_internal/ci/__init__.py +1 -0
- ansible_test/_internal/ci/azp.py +1 -0
- ansible_test/_internal/ci/local.py +1 -0
- ansible_test/_internal/classification/__init__.py +1 -0
- ansible_test/_internal/classification/common.py +1 -0
- ansible_test/_internal/classification/csharp.py +1 -0
- ansible_test/_internal/classification/powershell.py +1 -0
- ansible_test/_internal/classification/python.py +1 -0
- ansible_test/_internal/cli/__init__.py +1 -0
- ansible_test/_internal/cli/actions.py +1 -0
- ansible_test/_internal/cli/argparsing/__init__.py +1 -0
- ansible_test/_internal/cli/argparsing/actions.py +1 -0
- ansible_test/_internal/cli/argparsing/argcompletion.py +1 -0
- ansible_test/_internal/cli/argparsing/parsers.py +1 -0
- ansible_test/_internal/cli/commands/__init__.py +11 -0
- ansible_test/_internal/cli/commands/coverage/__init__.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/__init__.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/targets/__init__.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/targets/combine.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/targets/expand.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/targets/filter.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/targets/generate.py +1 -0
- ansible_test/_internal/cli/commands/coverage/analyze/targets/missing.py +1 -0
- ansible_test/_internal/cli/commands/coverage/combine.py +1 -0
- ansible_test/_internal/cli/commands/coverage/erase.py +1 -0
- ansible_test/_internal/cli/commands/coverage/html.py +1 -0
- ansible_test/_internal/cli/commands/coverage/report.py +1 -0
- ansible_test/_internal/cli/commands/coverage/xml.py +1 -0
- ansible_test/_internal/cli/commands/env.py +1 -0
- ansible_test/_internal/cli/commands/integration/__init__.py +1 -0
- ansible_test/_internal/cli/commands/integration/network.py +1 -0
- ansible_test/_internal/cli/commands/integration/posix.py +1 -0
- ansible_test/_internal/cli/commands/integration/windows.py +1 -0
- ansible_test/_internal/cli/commands/sanity.py +9 -0
- ansible_test/_internal/cli/commands/shell.py +1 -0
- ansible_test/_internal/cli/commands/units.py +1 -0
- ansible_test/_internal/cli/compat.py +1 -0
- ansible_test/_internal/cli/completers.py +1 -0
- ansible_test/_internal/cli/converters.py +1 -0
- ansible_test/_internal/cli/environments.py +1 -0
- ansible_test/_internal/cli/epilog.py +1 -0
- ansible_test/_internal/cli/parsers/__init__.py +1 -0
- ansible_test/_internal/cli/parsers/base_argument_parsers.py +1 -0
- ansible_test/_internal/cli/parsers/helpers.py +1 -0
- ansible_test/_internal/cli/parsers/host_config_parsers.py +1 -0
- ansible_test/_internal/cli/parsers/key_value_parsers.py +1 -0
- ansible_test/_internal/cli/parsers/value_parsers.py +1 -0
- ansible_test/_internal/commands/__init__.py +1 -0
- ansible_test/_internal/commands/coverage/__init__.py +2 -1
- ansible_test/_internal/commands/coverage/analyze/__init__.py +1 -0
- ansible_test/_internal/commands/coverage/analyze/targets/__init__.py +1 -0
- ansible_test/_internal/commands/coverage/analyze/targets/combine.py +1 -0
- ansible_test/_internal/commands/coverage/analyze/targets/expand.py +1 -0
- ansible_test/_internal/commands/coverage/analyze/targets/filter.py +1 -0
- ansible_test/_internal/commands/coverage/analyze/targets/generate.py +1 -0
- ansible_test/_internal/commands/coverage/analyze/targets/missing.py +1 -0
- ansible_test/_internal/commands/coverage/combine.py +2 -1
- ansible_test/_internal/commands/coverage/erase.py +1 -0
- ansible_test/_internal/commands/coverage/html.py +1 -0
- ansible_test/_internal/commands/coverage/report.py +1 -0
- ansible_test/_internal/commands/coverage/xml.py +1 -0
- ansible_test/_internal/commands/env/__init__.py +2 -0
- ansible_test/_internal/commands/integration/__init__.py +4 -0
- ansible_test/_internal/commands/integration/cloud/__init__.py +1 -0
- ansible_test/_internal/commands/integration/cloud/acme.py +2 -1
- ansible_test/_internal/commands/integration/cloud/aws.py +1 -0
- ansible_test/_internal/commands/integration/cloud/azure.py +1 -0
- ansible_test/_internal/commands/integration/cloud/cs.py +1 -0
- ansible_test/_internal/commands/integration/cloud/digitalocean.py +1 -0
- ansible_test/_internal/commands/integration/cloud/galaxy.py +3 -2
- ansible_test/_internal/commands/integration/cloud/hcloud.py +1 -0
- ansible_test/_internal/commands/integration/cloud/httptester.py +2 -1
- ansible_test/_internal/commands/integration/cloud/nios.py +2 -1
- ansible_test/_internal/commands/integration/cloud/opennebula.py +1 -0
- ansible_test/_internal/commands/integration/cloud/openshift.py +1 -0
- ansible_test/_internal/commands/integration/cloud/scaleway.py +1 -0
- ansible_test/_internal/commands/integration/cloud/vcenter.py +1 -0
- ansible_test/_internal/commands/integration/cloud/vultr.py +1 -0
- ansible_test/_internal/commands/integration/coverage.py +1 -0
- ansible_test/_internal/commands/integration/filters.py +1 -0
- ansible_test/_internal/commands/integration/network.py +1 -0
- ansible_test/_internal/commands/integration/posix.py +1 -0
- ansible_test/_internal/commands/integration/windows.py +1 -0
- ansible_test/_internal/commands/sanity/__init__.py +16 -1
- ansible_test/_internal/commands/sanity/ansible_doc.py +1 -0
- ansible_test/_internal/commands/sanity/bin_symlinks.py +1 -0
- ansible_test/_internal/commands/sanity/compile.py +1 -0
- ansible_test/_internal/commands/sanity/ignores.py +1 -0
- ansible_test/_internal/commands/sanity/import.py +1 -0
- ansible_test/_internal/commands/sanity/integration_aliases.py +1 -0
- ansible_test/_internal/commands/sanity/pep8.py +1 -0
- ansible_test/_internal/commands/sanity/pslint.py +1 -0
- ansible_test/_internal/commands/sanity/pylint.py +24 -26
- ansible_test/_internal/commands/sanity/shellcheck.py +1 -0
- ansible_test/_internal/commands/sanity/validate_modules.py +1 -0
- ansible_test/_internal/commands/sanity/yamllint.py +1 -0
- ansible_test/_internal/commands/shell/__init__.py +1 -0
- ansible_test/_internal/commands/units/__init__.py +1 -0
- ansible_test/_internal/compat/__init__.py +1 -0
- ansible_test/_internal/compat/packaging.py +1 -0
- ansible_test/_internal/compat/yaml.py +1 -0
- ansible_test/_internal/completion.py +1 -0
- ansible_test/_internal/config.py +2 -0
- ansible_test/_internal/connections.py +1 -0
- ansible_test/_internal/constants.py +1 -0
- ansible_test/_internal/containers.py +1 -0
- ansible_test/_internal/content_config.py +1 -0
- ansible_test/_internal/core_ci.py +1 -0
- ansible_test/_internal/coverage_util.py +11 -10
- ansible_test/_internal/data.py +1 -0
- ansible_test/_internal/delegation.py +1 -0
- ansible_test/_internal/dev/__init__.py +1 -0
- ansible_test/_internal/dev/container_probe.py +1 -0
- ansible_test/_internal/diff.py +3 -2
- ansible_test/_internal/docker_util.py +2 -1
- ansible_test/_internal/encoding.py +1 -0
- ansible_test/_internal/executor.py +1 -0
- ansible_test/_internal/git.py +1 -0
- ansible_test/_internal/host_configs.py +1 -0
- ansible_test/_internal/host_profiles.py +1 -0
- ansible_test/_internal/http.py +1 -0
- ansible_test/_internal/init.py +1 -0
- ansible_test/_internal/inventory.py +35 -3
- ansible_test/_internal/io.py +1 -0
- ansible_test/_internal/metadata.py +1 -0
- ansible_test/_internal/payload.py +1 -0
- ansible_test/_internal/provider/__init__.py +1 -0
- ansible_test/_internal/provider/layout/__init__.py +1 -0
- ansible_test/_internal/provider/layout/ansible.py +1 -0
- ansible_test/_internal/provider/layout/collection.py +1 -0
- ansible_test/_internal/provider/layout/unsupported.py +1 -0
- ansible_test/_internal/provider/source/__init__.py +1 -0
- ansible_test/_internal/provider/source/git.py +1 -0
- ansible_test/_internal/provider/source/installed.py +1 -0
- ansible_test/_internal/provider/source/unsupported.py +1 -0
- ansible_test/_internal/provider/source/unversioned.py +1 -0
- ansible_test/_internal/provisioning.py +1 -0
- ansible_test/_internal/pypi_proxy.py +6 -5
- ansible_test/_internal/python_requirements.py +1 -0
- ansible_test/_internal/ssh.py +1 -0
- ansible_test/_internal/target.py +1 -0
- ansible_test/_internal/test.py +3 -2
- ansible_test/_internal/thread.py +1 -0
- ansible_test/_internal/timeout.py +1 -0
- ansible_test/_internal/util.py +1 -0
- ansible_test/_internal/util_common.py +5 -2
- ansible_test/_internal/venv.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/action-plugin-docs.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/changelog/sphinx.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/changelog.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/empty-init.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/line-endings.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/no-assert.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/no-get-exception.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/no-illegal-filenames.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/no-smart-quotes.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/replace-urlopen.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py +28 -1
- ansible_test/_util/controller/sanity/code-smell/shebang.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/symlinks.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/use-argspec-type-path.py +1 -0
- ansible_test/_util/controller/sanity/code-smell/use-compat-six.py +1 -0
- ansible_test/_util/controller/sanity/integration-aliases/yaml_to_json.py +2 -1
- ansible_test/_util/controller/sanity/pep8/current-ignore.txt +4 -0
- ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg +7 -5
- ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg +7 -5
- ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg +7 -5
- ansible_test/_util/controller/sanity/pylint/config/collection.cfg +3 -5
- ansible_test/_util/controller/sanity/pylint/config/default.cfg +7 -7
- ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py +1 -13
- ansible_test/_util/controller/sanity/pylint/plugins/hide_unraisable.py +1 -0
- ansible_test/_util/controller/sanity/pylint/plugins/string_format.py +1 -8
- ansible_test/_util/controller/sanity/pylint/plugins/unwanted.py +1 -8
- ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py +55 -28
- ansible_test/_util/controller/sanity/validate-modules/validate_modules/module_args.py +12 -5
- ansible_test/_util/controller/sanity/validate-modules/validate_modules/schema.py +13 -2
- ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py +1 -0
- ansible_test/_util/controller/sanity/yamllint/yamllinter.py +35 -17
- ansible_test/_util/controller/tools/collection_detail.py +1 -0
- ansible_test/_util/controller/tools/yaml_to_json.py +2 -1
- ansible_test/_util/target/pytest/plugins/ansible_forked.py +6 -1
- ansible_test/_util/target/pytest/plugins/ansible_pytest_collections.py +2 -1
- ansible_test/_util/target/pytest/plugins/ansible_pytest_coverage.py +1 -0
- ansible_test/_util/target/sanity/compile/compile.py +1 -0
- ansible_test/_util/target/sanity/import/importer.py +15 -16
- ansible_test/_util/target/setup/bootstrap.sh +9 -20
- ansible_test/_util/target/setup/probe_cgroups.py +1 -0
- ansible_test/_util/target/setup/quiet_pip.py +1 -0
- ansible_test/_util/target/setup/requirements.py +35 -27
- ansible_test/_util/target/tools/virtualenvcheck.py +2 -1
- ansible_test/_util/target/tools/yamlcheck.py +2 -1
- ansible/compat/selectors.py +0 -32
- ansible/errors/yaml_strings.py +0 -138
- ansible/executor/action_write_locks.py +0 -44
- ansible/executor/discovery/python_target.py +0 -47
- ansible/executor/powershell/module_powershell_wrapper.ps1 +0 -86
- ansible/executor/powershell/module_script_wrapper.ps1 +0 -22
- ansible/module_utils/compat/importlib.py +0 -26
- ansible/module_utils/compat/selectors.py +0 -32
- ansible/module_utils/pycompat24.py +0 -73
- ansible/parsing/utils/jsonify.py +0 -36
- ansible/parsing/yaml/constructor.py +0 -178
- ansible/template/native_helpers.py +0 -251
- ansible/template/template.py +0 -43
- ansible/template/vars.py +0 -77
- ansible/utils/native_jinja.py +0 -11
- ansible/vars/fact_cache.py +0 -71
- ansible_core-2.18.5rc1.dist-info/RECORD +0 -992
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/Apache-License.txt +0 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/COPYING +0 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/MIT-license.txt +0 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/PSF-license.txt +0 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/entry_points.txt +0 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/simplified_bsd.txt +0 -0
- {ansible_core-2.18.5rc1.dist-info → ansible_core-2.19.0b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1052 @@
|
|
1
|
+
# Copyright (c) 2013-2023, Graham Dumpleton
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
18
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
19
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
20
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
21
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
22
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
23
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
24
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
26
|
+
# copied from https://github.com/GrahamDumpleton/wrapt/blob/1.15.0/src/wrapt/wrappers.py
|
27
|
+
|
28
|
+
# LOCAL PATCHES:
|
29
|
+
# - disabled optional relative import of the _wrappers C extension; we shouldn't need it
|
30
|
+
|
31
|
+
from __future__ import annotations
|
32
|
+
|
33
|
+
# The following makes it easier for us to script updates of the bundled code
|
34
|
+
_BUNDLED_METADATA = {"pypi_name": "wrapt", "version": "1.15.0"}
|
35
|
+
|
36
|
+
import os
|
37
|
+
import sys
|
38
|
+
import functools
|
39
|
+
import operator
|
40
|
+
import weakref
|
41
|
+
import inspect
|
42
|
+
|
43
|
+
PY2 = sys.version_info[0] == 2
|
44
|
+
|
45
|
+
if PY2:
|
46
|
+
string_types = basestring,
|
47
|
+
else:
|
48
|
+
string_types = str,
|
49
|
+
|
50
|
+
def with_metaclass(meta, *bases):
|
51
|
+
"""Create a base class with a metaclass."""
|
52
|
+
return meta("NewBase", bases, {})
|
53
|
+
|
54
|
+
class _ObjectProxyMethods(object):
|
55
|
+
|
56
|
+
# We use properties to override the values of __module__ and
|
57
|
+
# __doc__. If we add these in ObjectProxy, the derived class
|
58
|
+
# __dict__ will still be setup to have string variants of these
|
59
|
+
# attributes and the rules of descriptors means that they appear to
|
60
|
+
# take precedence over the properties in the base class. To avoid
|
61
|
+
# that, we copy the properties into the derived class type itself
|
62
|
+
# via a meta class. In that way the properties will always take
|
63
|
+
# precedence.
|
64
|
+
|
65
|
+
@property
|
66
|
+
def __module__(self):
|
67
|
+
return self.__wrapped__.__module__
|
68
|
+
|
69
|
+
@__module__.setter
|
70
|
+
def __module__(self, value):
|
71
|
+
self.__wrapped__.__module__ = value
|
72
|
+
|
73
|
+
@property
|
74
|
+
def __doc__(self):
|
75
|
+
return self.__wrapped__.__doc__
|
76
|
+
|
77
|
+
@__doc__.setter
|
78
|
+
def __doc__(self, value):
|
79
|
+
self.__wrapped__.__doc__ = value
|
80
|
+
|
81
|
+
# We similar use a property for __dict__. We need __dict__ to be
|
82
|
+
# explicit to ensure that vars() works as expected.
|
83
|
+
|
84
|
+
@property
|
85
|
+
def __dict__(self):
|
86
|
+
return self.__wrapped__.__dict__
|
87
|
+
|
88
|
+
# Need to also propagate the special __weakref__ attribute for case
|
89
|
+
# where decorating classes which will define this. If do not define
|
90
|
+
# it and use a function like inspect.getmembers() on a decorator
|
91
|
+
# class it will fail. This can't be in the derived classes.
|
92
|
+
|
93
|
+
@property
|
94
|
+
def __weakref__(self):
|
95
|
+
return self.__wrapped__.__weakref__
|
96
|
+
|
97
|
+
class _ObjectProxyMetaType(type):
|
98
|
+
def __new__(cls, name, bases, dictionary):
|
99
|
+
# Copy our special properties into the class so that they
|
100
|
+
# always take precedence over attributes of the same name added
|
101
|
+
# during construction of a derived class. This is to save
|
102
|
+
# duplicating the implementation for them in all derived classes.
|
103
|
+
|
104
|
+
dictionary.update(vars(_ObjectProxyMethods))
|
105
|
+
|
106
|
+
return type.__new__(cls, name, bases, dictionary)
|
107
|
+
|
108
|
+
class ObjectProxy(with_metaclass(_ObjectProxyMetaType)):
|
109
|
+
|
110
|
+
__slots__ = '__wrapped__'
|
111
|
+
|
112
|
+
def __init__(self, wrapped):
|
113
|
+
object.__setattr__(self, '__wrapped__', wrapped)
|
114
|
+
|
115
|
+
# Python 3.2+ has the __qualname__ attribute, but it does not
|
116
|
+
# allow it to be overridden using a property and it must instead
|
117
|
+
# be an actual string object instead.
|
118
|
+
|
119
|
+
try:
|
120
|
+
object.__setattr__(self, '__qualname__', wrapped.__qualname__)
|
121
|
+
except AttributeError:
|
122
|
+
pass
|
123
|
+
|
124
|
+
# Python 3.10 onwards also does not allow itself to be overridden
|
125
|
+
# using a property and it must instead be set explicitly.
|
126
|
+
|
127
|
+
try:
|
128
|
+
object.__setattr__(self, '__annotations__', wrapped.__annotations__)
|
129
|
+
except AttributeError:
|
130
|
+
pass
|
131
|
+
|
132
|
+
@property
|
133
|
+
def __name__(self):
|
134
|
+
return self.__wrapped__.__name__
|
135
|
+
|
136
|
+
@__name__.setter
|
137
|
+
def __name__(self, value):
|
138
|
+
self.__wrapped__.__name__ = value
|
139
|
+
|
140
|
+
@property
|
141
|
+
def __class__(self):
|
142
|
+
return self.__wrapped__.__class__
|
143
|
+
|
144
|
+
@__class__.setter
|
145
|
+
def __class__(self, value):
|
146
|
+
self.__wrapped__.__class__ = value
|
147
|
+
|
148
|
+
def __dir__(self):
|
149
|
+
return dir(self.__wrapped__)
|
150
|
+
|
151
|
+
def __str__(self):
|
152
|
+
return str(self.__wrapped__)
|
153
|
+
|
154
|
+
if not PY2:
|
155
|
+
def __bytes__(self):
|
156
|
+
return bytes(self.__wrapped__)
|
157
|
+
|
158
|
+
def __repr__(self):
|
159
|
+
return '<{} at 0x{:x} for {} at 0x{:x}>'.format(
|
160
|
+
type(self).__name__, id(self),
|
161
|
+
type(self.__wrapped__).__name__,
|
162
|
+
id(self.__wrapped__))
|
163
|
+
|
164
|
+
def __reversed__(self):
|
165
|
+
return reversed(self.__wrapped__)
|
166
|
+
|
167
|
+
if not PY2:
|
168
|
+
def __round__(self):
|
169
|
+
return round(self.__wrapped__)
|
170
|
+
|
171
|
+
if sys.hexversion >= 0x03070000:
|
172
|
+
def __mro_entries__(self, bases):
|
173
|
+
return (self.__wrapped__,)
|
174
|
+
|
175
|
+
def __lt__(self, other):
|
176
|
+
return self.__wrapped__ < other
|
177
|
+
|
178
|
+
def __le__(self, other):
|
179
|
+
return self.__wrapped__ <= other
|
180
|
+
|
181
|
+
def __eq__(self, other):
|
182
|
+
return self.__wrapped__ == other
|
183
|
+
|
184
|
+
def __ne__(self, other):
|
185
|
+
return self.__wrapped__ != other
|
186
|
+
|
187
|
+
def __gt__(self, other):
|
188
|
+
return self.__wrapped__ > other
|
189
|
+
|
190
|
+
def __ge__(self, other):
|
191
|
+
return self.__wrapped__ >= other
|
192
|
+
|
193
|
+
def __hash__(self):
|
194
|
+
return hash(self.__wrapped__)
|
195
|
+
|
196
|
+
def __nonzero__(self):
|
197
|
+
return bool(self.__wrapped__)
|
198
|
+
|
199
|
+
def __bool__(self):
|
200
|
+
return bool(self.__wrapped__)
|
201
|
+
|
202
|
+
def __setattr__(self, name, value):
|
203
|
+
if name.startswith('_self_'):
|
204
|
+
object.__setattr__(self, name, value)
|
205
|
+
|
206
|
+
elif name == '__wrapped__':
|
207
|
+
object.__setattr__(self, name, value)
|
208
|
+
try:
|
209
|
+
object.__delattr__(self, '__qualname__')
|
210
|
+
except AttributeError:
|
211
|
+
pass
|
212
|
+
try:
|
213
|
+
object.__setattr__(self, '__qualname__', value.__qualname__)
|
214
|
+
except AttributeError:
|
215
|
+
pass
|
216
|
+
try:
|
217
|
+
object.__delattr__(self, '__annotations__')
|
218
|
+
except AttributeError:
|
219
|
+
pass
|
220
|
+
try:
|
221
|
+
object.__setattr__(self, '__annotations__', value.__annotations__)
|
222
|
+
except AttributeError:
|
223
|
+
pass
|
224
|
+
|
225
|
+
elif name == '__qualname__':
|
226
|
+
setattr(self.__wrapped__, name, value)
|
227
|
+
object.__setattr__(self, name, value)
|
228
|
+
|
229
|
+
elif name == '__annotations__':
|
230
|
+
setattr(self.__wrapped__, name, value)
|
231
|
+
object.__setattr__(self, name, value)
|
232
|
+
|
233
|
+
elif hasattr(type(self), name):
|
234
|
+
object.__setattr__(self, name, value)
|
235
|
+
|
236
|
+
else:
|
237
|
+
setattr(self.__wrapped__, name, value)
|
238
|
+
|
239
|
+
def __getattr__(self, name):
|
240
|
+
# If we are being to lookup '__wrapped__' then the
|
241
|
+
# '__init__()' method cannot have been called.
|
242
|
+
|
243
|
+
if name == '__wrapped__':
|
244
|
+
raise ValueError('wrapper has not been initialised')
|
245
|
+
|
246
|
+
return getattr(self.__wrapped__, name)
|
247
|
+
|
248
|
+
def __delattr__(self, name):
|
249
|
+
if name.startswith('_self_'):
|
250
|
+
object.__delattr__(self, name)
|
251
|
+
|
252
|
+
elif name == '__wrapped__':
|
253
|
+
raise TypeError('__wrapped__ must be an object')
|
254
|
+
|
255
|
+
elif name == '__qualname__':
|
256
|
+
object.__delattr__(self, name)
|
257
|
+
delattr(self.__wrapped__, name)
|
258
|
+
|
259
|
+
elif hasattr(type(self), name):
|
260
|
+
object.__delattr__(self, name)
|
261
|
+
|
262
|
+
else:
|
263
|
+
delattr(self.__wrapped__, name)
|
264
|
+
|
265
|
+
def __add__(self, other):
|
266
|
+
return self.__wrapped__ + other
|
267
|
+
|
268
|
+
def __sub__(self, other):
|
269
|
+
return self.__wrapped__ - other
|
270
|
+
|
271
|
+
def __mul__(self, other):
|
272
|
+
return self.__wrapped__ * other
|
273
|
+
|
274
|
+
def __div__(self, other):
|
275
|
+
return operator.div(self.__wrapped__, other)
|
276
|
+
|
277
|
+
def __truediv__(self, other):
|
278
|
+
return operator.truediv(self.__wrapped__, other)
|
279
|
+
|
280
|
+
def __floordiv__(self, other):
|
281
|
+
return self.__wrapped__ // other
|
282
|
+
|
283
|
+
def __mod__(self, other):
|
284
|
+
return self.__wrapped__ % other
|
285
|
+
|
286
|
+
def __divmod__(self, other):
|
287
|
+
return divmod(self.__wrapped__, other)
|
288
|
+
|
289
|
+
def __pow__(self, other, *args):
|
290
|
+
return pow(self.__wrapped__, other, *args)
|
291
|
+
|
292
|
+
def __lshift__(self, other):
|
293
|
+
return self.__wrapped__ << other
|
294
|
+
|
295
|
+
def __rshift__(self, other):
|
296
|
+
return self.__wrapped__ >> other
|
297
|
+
|
298
|
+
def __and__(self, other):
|
299
|
+
return self.__wrapped__ & other
|
300
|
+
|
301
|
+
def __xor__(self, other):
|
302
|
+
return self.__wrapped__ ^ other
|
303
|
+
|
304
|
+
def __or__(self, other):
|
305
|
+
return self.__wrapped__ | other
|
306
|
+
|
307
|
+
def __radd__(self, other):
|
308
|
+
return other + self.__wrapped__
|
309
|
+
|
310
|
+
def __rsub__(self, other):
|
311
|
+
return other - self.__wrapped__
|
312
|
+
|
313
|
+
def __rmul__(self, other):
|
314
|
+
return other * self.__wrapped__
|
315
|
+
|
316
|
+
def __rdiv__(self, other):
|
317
|
+
return operator.div(other, self.__wrapped__)
|
318
|
+
|
319
|
+
def __rtruediv__(self, other):
|
320
|
+
return operator.truediv(other, self.__wrapped__)
|
321
|
+
|
322
|
+
def __rfloordiv__(self, other):
|
323
|
+
return other // self.__wrapped__
|
324
|
+
|
325
|
+
def __rmod__(self, other):
|
326
|
+
return other % self.__wrapped__
|
327
|
+
|
328
|
+
def __rdivmod__(self, other):
|
329
|
+
return divmod(other, self.__wrapped__)
|
330
|
+
|
331
|
+
def __rpow__(self, other, *args):
|
332
|
+
return pow(other, self.__wrapped__, *args)
|
333
|
+
|
334
|
+
def __rlshift__(self, other):
|
335
|
+
return other << self.__wrapped__
|
336
|
+
|
337
|
+
def __rrshift__(self, other):
|
338
|
+
return other >> self.__wrapped__
|
339
|
+
|
340
|
+
def __rand__(self, other):
|
341
|
+
return other & self.__wrapped__
|
342
|
+
|
343
|
+
def __rxor__(self, other):
|
344
|
+
return other ^ self.__wrapped__
|
345
|
+
|
346
|
+
def __ror__(self, other):
|
347
|
+
return other | self.__wrapped__
|
348
|
+
|
349
|
+
def __iadd__(self, other):
|
350
|
+
self.__wrapped__ += other
|
351
|
+
return self
|
352
|
+
|
353
|
+
def __isub__(self, other):
|
354
|
+
self.__wrapped__ -= other
|
355
|
+
return self
|
356
|
+
|
357
|
+
def __imul__(self, other):
|
358
|
+
self.__wrapped__ *= other
|
359
|
+
return self
|
360
|
+
|
361
|
+
def __idiv__(self, other):
|
362
|
+
self.__wrapped__ = operator.idiv(self.__wrapped__, other)
|
363
|
+
return self
|
364
|
+
|
365
|
+
def __itruediv__(self, other):
|
366
|
+
self.__wrapped__ = operator.itruediv(self.__wrapped__, other)
|
367
|
+
return self
|
368
|
+
|
369
|
+
def __ifloordiv__(self, other):
|
370
|
+
self.__wrapped__ //= other
|
371
|
+
return self
|
372
|
+
|
373
|
+
def __imod__(self, other):
|
374
|
+
self.__wrapped__ %= other
|
375
|
+
return self
|
376
|
+
|
377
|
+
def __ipow__(self, other):
|
378
|
+
self.__wrapped__ **= other
|
379
|
+
return self
|
380
|
+
|
381
|
+
def __ilshift__(self, other):
|
382
|
+
self.__wrapped__ <<= other
|
383
|
+
return self
|
384
|
+
|
385
|
+
def __irshift__(self, other):
|
386
|
+
self.__wrapped__ >>= other
|
387
|
+
return self
|
388
|
+
|
389
|
+
def __iand__(self, other):
|
390
|
+
self.__wrapped__ &= other
|
391
|
+
return self
|
392
|
+
|
393
|
+
def __ixor__(self, other):
|
394
|
+
self.__wrapped__ ^= other
|
395
|
+
return self
|
396
|
+
|
397
|
+
def __ior__(self, other):
|
398
|
+
self.__wrapped__ |= other
|
399
|
+
return self
|
400
|
+
|
401
|
+
def __neg__(self):
|
402
|
+
return -self.__wrapped__
|
403
|
+
|
404
|
+
def __pos__(self):
|
405
|
+
return +self.__wrapped__
|
406
|
+
|
407
|
+
def __abs__(self):
|
408
|
+
return abs(self.__wrapped__)
|
409
|
+
|
410
|
+
def __invert__(self):
|
411
|
+
return ~self.__wrapped__
|
412
|
+
|
413
|
+
def __int__(self):
|
414
|
+
return int(self.__wrapped__)
|
415
|
+
|
416
|
+
def __long__(self):
|
417
|
+
return long(self.__wrapped__)
|
418
|
+
|
419
|
+
def __float__(self):
|
420
|
+
return float(self.__wrapped__)
|
421
|
+
|
422
|
+
def __complex__(self):
|
423
|
+
return complex(self.__wrapped__)
|
424
|
+
|
425
|
+
def __oct__(self):
|
426
|
+
return oct(self.__wrapped__)
|
427
|
+
|
428
|
+
def __hex__(self):
|
429
|
+
return hex(self.__wrapped__)
|
430
|
+
|
431
|
+
def __index__(self):
|
432
|
+
return operator.index(self.__wrapped__)
|
433
|
+
|
434
|
+
def __len__(self):
|
435
|
+
return len(self.__wrapped__)
|
436
|
+
|
437
|
+
def __contains__(self, value):
|
438
|
+
return value in self.__wrapped__
|
439
|
+
|
440
|
+
def __getitem__(self, key):
|
441
|
+
return self.__wrapped__[key]
|
442
|
+
|
443
|
+
def __setitem__(self, key, value):
|
444
|
+
self.__wrapped__[key] = value
|
445
|
+
|
446
|
+
def __delitem__(self, key):
|
447
|
+
del self.__wrapped__[key]
|
448
|
+
|
449
|
+
def __getslice__(self, i, j):
|
450
|
+
return self.__wrapped__[i:j]
|
451
|
+
|
452
|
+
def __setslice__(self, i, j, value):
|
453
|
+
self.__wrapped__[i:j] = value
|
454
|
+
|
455
|
+
def __delslice__(self, i, j):
|
456
|
+
del self.__wrapped__[i:j]
|
457
|
+
|
458
|
+
def __enter__(self):
|
459
|
+
return self.__wrapped__.__enter__()
|
460
|
+
|
461
|
+
def __exit__(self, *args, **kwargs):
|
462
|
+
return self.__wrapped__.__exit__(*args, **kwargs)
|
463
|
+
|
464
|
+
def __iter__(self):
|
465
|
+
return iter(self.__wrapped__)
|
466
|
+
|
467
|
+
def __copy__(self):
|
468
|
+
raise NotImplementedError('object proxy must define __copy__()')
|
469
|
+
|
470
|
+
def __deepcopy__(self, memo):
|
471
|
+
raise NotImplementedError('object proxy must define __deepcopy__()')
|
472
|
+
|
473
|
+
def __reduce__(self):
|
474
|
+
raise NotImplementedError(
|
475
|
+
'object proxy must define __reduce_ex__()')
|
476
|
+
|
477
|
+
def __reduce_ex__(self, protocol):
|
478
|
+
raise NotImplementedError(
|
479
|
+
'object proxy must define __reduce_ex__()')
|
480
|
+
|
481
|
+
class CallableObjectProxy(ObjectProxy):
|
482
|
+
|
483
|
+
def __call__(*args, **kwargs):
|
484
|
+
def _unpack_self(self, *args):
|
485
|
+
return self, args
|
486
|
+
|
487
|
+
self, args = _unpack_self(*args)
|
488
|
+
|
489
|
+
return self.__wrapped__(*args, **kwargs)
|
490
|
+
|
491
|
+
class PartialCallableObjectProxy(ObjectProxy):
|
492
|
+
|
493
|
+
def __init__(*args, **kwargs):
|
494
|
+
def _unpack_self(self, *args):
|
495
|
+
return self, args
|
496
|
+
|
497
|
+
self, args = _unpack_self(*args)
|
498
|
+
|
499
|
+
if len(args) < 1:
|
500
|
+
raise TypeError('partial type takes at least one argument')
|
501
|
+
|
502
|
+
wrapped, args = args[0], args[1:]
|
503
|
+
|
504
|
+
if not callable(wrapped):
|
505
|
+
raise TypeError('the first argument must be callable')
|
506
|
+
|
507
|
+
super(PartialCallableObjectProxy, self).__init__(wrapped)
|
508
|
+
|
509
|
+
self._self_args = args
|
510
|
+
self._self_kwargs = kwargs
|
511
|
+
|
512
|
+
def __call__(*args, **kwargs):
|
513
|
+
def _unpack_self(self, *args):
|
514
|
+
return self, args
|
515
|
+
|
516
|
+
self, args = _unpack_self(*args)
|
517
|
+
|
518
|
+
_args = self._self_args + args
|
519
|
+
|
520
|
+
_kwargs = dict(self._self_kwargs)
|
521
|
+
_kwargs.update(kwargs)
|
522
|
+
|
523
|
+
return self.__wrapped__(*_args, **_kwargs)
|
524
|
+
|
525
|
+
class _FunctionWrapperBase(ObjectProxy):
|
526
|
+
|
527
|
+
__slots__ = ('_self_instance', '_self_wrapper', '_self_enabled',
|
528
|
+
'_self_binding', '_self_parent')
|
529
|
+
|
530
|
+
def __init__(self, wrapped, instance, wrapper, enabled=None,
|
531
|
+
binding='function', parent=None):
|
532
|
+
|
533
|
+
super(_FunctionWrapperBase, self).__init__(wrapped)
|
534
|
+
|
535
|
+
object.__setattr__(self, '_self_instance', instance)
|
536
|
+
object.__setattr__(self, '_self_wrapper', wrapper)
|
537
|
+
object.__setattr__(self, '_self_enabled', enabled)
|
538
|
+
object.__setattr__(self, '_self_binding', binding)
|
539
|
+
object.__setattr__(self, '_self_parent', parent)
|
540
|
+
|
541
|
+
def __get__(self, instance, owner):
|
542
|
+
# This method is actually doing double duty for both unbound and
|
543
|
+
# bound derived wrapper classes. It should possibly be broken up
|
544
|
+
# and the distinct functionality moved into the derived classes.
|
545
|
+
# Can't do that straight away due to some legacy code which is
|
546
|
+
# relying on it being here in this base class.
|
547
|
+
#
|
548
|
+
# The distinguishing attribute which determines whether we are
|
549
|
+
# being called in an unbound or bound wrapper is the parent
|
550
|
+
# attribute. If binding has never occurred, then the parent will
|
551
|
+
# be None.
|
552
|
+
#
|
553
|
+
# First therefore, is if we are called in an unbound wrapper. In
|
554
|
+
# this case we perform the binding.
|
555
|
+
#
|
556
|
+
# We have one special case to worry about here. This is where we
|
557
|
+
# are decorating a nested class. In this case the wrapped class
|
558
|
+
# would not have a __get__() method to call. In that case we
|
559
|
+
# simply return self.
|
560
|
+
#
|
561
|
+
# Note that we otherwise still do binding even if instance is
|
562
|
+
# None and accessing an unbound instance method from a class.
|
563
|
+
# This is because we need to be able to later detect that
|
564
|
+
# specific case as we will need to extract the instance from the
|
565
|
+
# first argument of those passed in.
|
566
|
+
|
567
|
+
if self._self_parent is None:
|
568
|
+
if not inspect.isclass(self.__wrapped__):
|
569
|
+
descriptor = self.__wrapped__.__get__(instance, owner)
|
570
|
+
|
571
|
+
return self.__bound_function_wrapper__(descriptor, instance,
|
572
|
+
self._self_wrapper, self._self_enabled,
|
573
|
+
self._self_binding, self)
|
574
|
+
|
575
|
+
return self
|
576
|
+
|
577
|
+
# Now we have the case of binding occurring a second time on what
|
578
|
+
# was already a bound function. In this case we would usually
|
579
|
+
# return ourselves again. This mirrors what Python does.
|
580
|
+
#
|
581
|
+
# The special case this time is where we were originally bound
|
582
|
+
# with an instance of None and we were likely an instance
|
583
|
+
# method. In that case we rebind against the original wrapped
|
584
|
+
# function from the parent again.
|
585
|
+
|
586
|
+
if self._self_instance is None and self._self_binding == 'function':
|
587
|
+
descriptor = self._self_parent.__wrapped__.__get__(
|
588
|
+
instance, owner)
|
589
|
+
|
590
|
+
return self._self_parent.__bound_function_wrapper__(
|
591
|
+
descriptor, instance, self._self_wrapper,
|
592
|
+
self._self_enabled, self._self_binding,
|
593
|
+
self._self_parent)
|
594
|
+
|
595
|
+
return self
|
596
|
+
|
597
|
+
def __call__(*args, **kwargs):
|
598
|
+
def _unpack_self(self, *args):
|
599
|
+
return self, args
|
600
|
+
|
601
|
+
self, args = _unpack_self(*args)
|
602
|
+
|
603
|
+
# If enabled has been specified, then evaluate it at this point
|
604
|
+
# and if the wrapper is not to be executed, then simply return
|
605
|
+
# the bound function rather than a bound wrapper for the bound
|
606
|
+
# function. When evaluating enabled, if it is callable we call
|
607
|
+
# it, otherwise we evaluate it as a boolean.
|
608
|
+
|
609
|
+
if self._self_enabled is not None:
|
610
|
+
if callable(self._self_enabled):
|
611
|
+
if not self._self_enabled():
|
612
|
+
return self.__wrapped__(*args, **kwargs)
|
613
|
+
elif not self._self_enabled:
|
614
|
+
return self.__wrapped__(*args, **kwargs)
|
615
|
+
|
616
|
+
# This can occur where initial function wrapper was applied to
|
617
|
+
# a function that was already bound to an instance. In that case
|
618
|
+
# we want to extract the instance from the function and use it.
|
619
|
+
|
620
|
+
if self._self_binding in ('function', 'classmethod'):
|
621
|
+
if self._self_instance is None:
|
622
|
+
instance = getattr(self.__wrapped__, '__self__', None)
|
623
|
+
if instance is not None:
|
624
|
+
return self._self_wrapper(self.__wrapped__, instance,
|
625
|
+
args, kwargs)
|
626
|
+
|
627
|
+
# This is generally invoked when the wrapped function is being
|
628
|
+
# called as a normal function and is not bound to a class as an
|
629
|
+
# instance method. This is also invoked in the case where the
|
630
|
+
# wrapped function was a method, but this wrapper was in turn
|
631
|
+
# wrapped using the staticmethod decorator.
|
632
|
+
|
633
|
+
return self._self_wrapper(self.__wrapped__, self._self_instance,
|
634
|
+
args, kwargs)
|
635
|
+
|
636
|
+
def __set_name__(self, owner, name):
|
637
|
+
# This is a special method use to supply information to
|
638
|
+
# descriptors about what the name of variable in a class
|
639
|
+
# definition is. Not wanting to add this to ObjectProxy as not
|
640
|
+
# sure of broader implications of doing that. Thus restrict to
|
641
|
+
# FunctionWrapper used by decorators.
|
642
|
+
|
643
|
+
if hasattr(self.__wrapped__, "__set_name__"):
|
644
|
+
self.__wrapped__.__set_name__(owner, name)
|
645
|
+
|
646
|
+
def __instancecheck__(self, instance):
|
647
|
+
# This is a special method used by isinstance() to make checks
|
648
|
+
# instance of the `__wrapped__`.
|
649
|
+
return isinstance(instance, self.__wrapped__)
|
650
|
+
|
651
|
+
def __subclasscheck__(self, subclass):
|
652
|
+
# This is a special method used by issubclass() to make checks
|
653
|
+
# about inheritance of classes. We need to upwrap any object
|
654
|
+
# proxy. Not wanting to add this to ObjectProxy as not sure of
|
655
|
+
# broader implications of doing that. Thus restrict to
|
656
|
+
# FunctionWrapper used by decorators.
|
657
|
+
|
658
|
+
if hasattr(subclass, "__wrapped__"):
|
659
|
+
return issubclass(subclass.__wrapped__, self.__wrapped__)
|
660
|
+
else:
|
661
|
+
return issubclass(subclass, self.__wrapped__)
|
662
|
+
|
663
|
+
class BoundFunctionWrapper(_FunctionWrapperBase):
|
664
|
+
|
665
|
+
def __call__(*args, **kwargs):
|
666
|
+
def _unpack_self(self, *args):
|
667
|
+
return self, args
|
668
|
+
|
669
|
+
self, args = _unpack_self(*args)
|
670
|
+
|
671
|
+
# If enabled has been specified, then evaluate it at this point
|
672
|
+
# and if the wrapper is not to be executed, then simply return
|
673
|
+
# the bound function rather than a bound wrapper for the bound
|
674
|
+
# function. When evaluating enabled, if it is callable we call
|
675
|
+
# it, otherwise we evaluate it as a boolean.
|
676
|
+
|
677
|
+
if self._self_enabled is not None:
|
678
|
+
if callable(self._self_enabled):
|
679
|
+
if not self._self_enabled():
|
680
|
+
return self.__wrapped__(*args, **kwargs)
|
681
|
+
elif not self._self_enabled:
|
682
|
+
return self.__wrapped__(*args, **kwargs)
|
683
|
+
|
684
|
+
# We need to do things different depending on whether we are
|
685
|
+
# likely wrapping an instance method vs a static method or class
|
686
|
+
# method.
|
687
|
+
|
688
|
+
if self._self_binding == 'function':
|
689
|
+
if self._self_instance is None:
|
690
|
+
# This situation can occur where someone is calling the
|
691
|
+
# instancemethod via the class type and passing the instance
|
692
|
+
# as the first argument. We need to shift the args before
|
693
|
+
# making the call to the wrapper and effectively bind the
|
694
|
+
# instance to the wrapped function using a partial so the
|
695
|
+
# wrapper doesn't see anything as being different.
|
696
|
+
|
697
|
+
if not args:
|
698
|
+
raise TypeError('missing 1 required positional argument')
|
699
|
+
|
700
|
+
instance, args = args[0], args[1:]
|
701
|
+
wrapped = PartialCallableObjectProxy(self.__wrapped__, instance)
|
702
|
+
return self._self_wrapper(wrapped, instance, args, kwargs)
|
703
|
+
|
704
|
+
return self._self_wrapper(self.__wrapped__, self._self_instance,
|
705
|
+
args, kwargs)
|
706
|
+
|
707
|
+
else:
|
708
|
+
# As in this case we would be dealing with a classmethod or
|
709
|
+
# staticmethod, then _self_instance will only tell us whether
|
710
|
+
# when calling the classmethod or staticmethod they did it via an
|
711
|
+
# instance of the class it is bound to and not the case where
|
712
|
+
# done by the class type itself. We thus ignore _self_instance
|
713
|
+
# and use the __self__ attribute of the bound function instead.
|
714
|
+
# For a classmethod, this means instance will be the class type
|
715
|
+
# and for a staticmethod it will be None. This is probably the
|
716
|
+
# more useful thing we can pass through even though we loose
|
717
|
+
# knowledge of whether they were called on the instance vs the
|
718
|
+
# class type, as it reflects what they have available in the
|
719
|
+
# decoratored function.
|
720
|
+
|
721
|
+
instance = getattr(self.__wrapped__, '__self__', None)
|
722
|
+
|
723
|
+
return self._self_wrapper(self.__wrapped__, instance, args,
|
724
|
+
kwargs)
|
725
|
+
|
726
|
+
class FunctionWrapper(_FunctionWrapperBase):
|
727
|
+
|
728
|
+
__bound_function_wrapper__ = BoundFunctionWrapper
|
729
|
+
|
730
|
+
def __init__(self, wrapped, wrapper, enabled=None):
|
731
|
+
# What it is we are wrapping here could be anything. We need to
|
732
|
+
# try and detect specific cases though. In particular, we need
|
733
|
+
# to detect when we are given something that is a method of a
|
734
|
+
# class. Further, we need to know when it is likely an instance
|
735
|
+
# method, as opposed to a class or static method. This can
|
736
|
+
# become problematic though as there isn't strictly a fool proof
|
737
|
+
# method of knowing.
|
738
|
+
#
|
739
|
+
# The situations we could encounter when wrapping a method are:
|
740
|
+
#
|
741
|
+
# 1. The wrapper is being applied as part of a decorator which
|
742
|
+
# is a part of the class definition. In this case what we are
|
743
|
+
# given is the raw unbound function, classmethod or staticmethod
|
744
|
+
# wrapper objects.
|
745
|
+
#
|
746
|
+
# The problem here is that we will not know we are being applied
|
747
|
+
# in the context of the class being set up. This becomes
|
748
|
+
# important later for the case of an instance method, because in
|
749
|
+
# that case we just see it as a raw function and can't
|
750
|
+
# distinguish it from wrapping a normal function outside of
|
751
|
+
# a class context.
|
752
|
+
#
|
753
|
+
# 2. The wrapper is being applied when performing monkey
|
754
|
+
# patching of the class type afterwards and the method to be
|
755
|
+
# wrapped was retrieved direct from the __dict__ of the class
|
756
|
+
# type. This is effectively the same as (1) above.
|
757
|
+
#
|
758
|
+
# 3. The wrapper is being applied when performing monkey
|
759
|
+
# patching of the class type afterwards and the method to be
|
760
|
+
# wrapped was retrieved from the class type. In this case
|
761
|
+
# binding will have been performed where the instance against
|
762
|
+
# which the method is bound will be None at that point.
|
763
|
+
#
|
764
|
+
# This case is a problem because we can no longer tell if the
|
765
|
+
# method was a static method, plus if using Python3, we cannot
|
766
|
+
# tell if it was an instance method as the concept of an
|
767
|
+
# unnbound method no longer exists.
|
768
|
+
#
|
769
|
+
# 4. The wrapper is being applied when performing monkey
|
770
|
+
# patching of an instance of a class. In this case binding will
|
771
|
+
# have been perfomed where the instance was not None.
|
772
|
+
#
|
773
|
+
# This case is a problem because we can no longer tell if the
|
774
|
+
# method was a static method.
|
775
|
+
#
|
776
|
+
# Overall, the best we can do is look at the original type of the
|
777
|
+
# object which was wrapped prior to any binding being done and
|
778
|
+
# see if it is an instance of classmethod or staticmethod. In
|
779
|
+
# the case where other decorators are between us and them, if
|
780
|
+
# they do not propagate the __class__ attribute so that the
|
781
|
+
# isinstance() checks works, then likely this will do the wrong
|
782
|
+
# thing where classmethod and staticmethod are used.
|
783
|
+
#
|
784
|
+
# Since it is likely to be very rare that anyone even puts
|
785
|
+
# decorators around classmethod and staticmethod, likelihood of
|
786
|
+
# that being an issue is very small, so we accept it and suggest
|
787
|
+
# that those other decorators be fixed. It is also only an issue
|
788
|
+
# if a decorator wants to actually do things with the arguments.
|
789
|
+
#
|
790
|
+
# As to not being able to identify static methods properly, we
|
791
|
+
# just hope that that isn't something people are going to want
|
792
|
+
# to wrap, or if they do suggest they do it the correct way by
|
793
|
+
# ensuring that it is decorated in the class definition itself,
|
794
|
+
# or patch it in the __dict__ of the class type.
|
795
|
+
#
|
796
|
+
# So to get the best outcome we can, whenever we aren't sure what
|
797
|
+
# it is, we label it as a 'function'. If it was already bound and
|
798
|
+
# that is rebound later, we assume that it will be an instance
|
799
|
+
# method and try an cope with the possibility that the 'self'
|
800
|
+
# argument it being passed as an explicit argument and shuffle
|
801
|
+
# the arguments around to extract 'self' for use as the instance.
|
802
|
+
|
803
|
+
if isinstance(wrapped, classmethod):
|
804
|
+
binding = 'classmethod'
|
805
|
+
|
806
|
+
elif isinstance(wrapped, staticmethod):
|
807
|
+
binding = 'staticmethod'
|
808
|
+
|
809
|
+
elif hasattr(wrapped, '__self__'):
|
810
|
+
if inspect.isclass(wrapped.__self__):
|
811
|
+
binding = 'classmethod'
|
812
|
+
else:
|
813
|
+
binding = 'function'
|
814
|
+
|
815
|
+
else:
|
816
|
+
binding = 'function'
|
817
|
+
|
818
|
+
super(FunctionWrapper, self).__init__(wrapped, None, wrapper,
|
819
|
+
enabled, binding)
|
820
|
+
|
821
|
+
# disabled support for native extension; we likely don't need it
|
822
|
+
# try:
|
823
|
+
# if not os.environ.get('WRAPT_DISABLE_EXTENSIONS'):
|
824
|
+
# from ._wrappers import (ObjectProxy, CallableObjectProxy,
|
825
|
+
# PartialCallableObjectProxy, FunctionWrapper,
|
826
|
+
# BoundFunctionWrapper, _FunctionWrapperBase)
|
827
|
+
# except ImportError:
|
828
|
+
# pass
|
829
|
+
|
830
|
+
# Helper functions for applying wrappers to existing functions.
|
831
|
+
|
832
|
+
def resolve_path(module, name):
|
833
|
+
if isinstance(module, string_types):
|
834
|
+
__import__(module)
|
835
|
+
module = sys.modules[module]
|
836
|
+
|
837
|
+
parent = module
|
838
|
+
|
839
|
+
path = name.split('.')
|
840
|
+
attribute = path[0]
|
841
|
+
|
842
|
+
# We can't just always use getattr() because in doing
|
843
|
+
# that on a class it will cause binding to occur which
|
844
|
+
# will complicate things later and cause some things not
|
845
|
+
# to work. For the case of a class we therefore access
|
846
|
+
# the __dict__ directly. To cope though with the wrong
|
847
|
+
# class being given to us, or a method being moved into
|
848
|
+
# a base class, we need to walk the class hierarchy to
|
849
|
+
# work out exactly which __dict__ the method was defined
|
850
|
+
# in, as accessing it from __dict__ will fail if it was
|
851
|
+
# not actually on the class given. Fallback to using
|
852
|
+
# getattr() if we can't find it. If it truly doesn't
|
853
|
+
# exist, then that will fail.
|
854
|
+
|
855
|
+
def lookup_attribute(parent, attribute):
|
856
|
+
if inspect.isclass(parent):
|
857
|
+
for cls in inspect.getmro(parent):
|
858
|
+
if attribute in vars(cls):
|
859
|
+
return vars(cls)[attribute]
|
860
|
+
else:
|
861
|
+
return getattr(parent, attribute)
|
862
|
+
else:
|
863
|
+
return getattr(parent, attribute)
|
864
|
+
|
865
|
+
original = lookup_attribute(parent, attribute)
|
866
|
+
|
867
|
+
for attribute in path[1:]:
|
868
|
+
parent = original
|
869
|
+
original = lookup_attribute(parent, attribute)
|
870
|
+
|
871
|
+
return (parent, attribute, original)
|
872
|
+
|
873
|
+
def apply_patch(parent, attribute, replacement):
|
874
|
+
setattr(parent, attribute, replacement)
|
875
|
+
|
876
|
+
def wrap_object(module, name, factory, args=(), kwargs={}):
|
877
|
+
(parent, attribute, original) = resolve_path(module, name)
|
878
|
+
wrapper = factory(original, *args, **kwargs)
|
879
|
+
apply_patch(parent, attribute, wrapper)
|
880
|
+
return wrapper
|
881
|
+
|
882
|
+
# Function for applying a proxy object to an attribute of a class
|
883
|
+
# instance. The wrapper works by defining an attribute of the same name
|
884
|
+
# on the class which is a descriptor and which intercepts access to the
|
885
|
+
# instance attribute. Note that this cannot be used on attributes which
|
886
|
+
# are themselves defined by a property object.
|
887
|
+
|
888
|
+
class AttributeWrapper(object):
|
889
|
+
|
890
|
+
def __init__(self, attribute, factory, args, kwargs):
|
891
|
+
self.attribute = attribute
|
892
|
+
self.factory = factory
|
893
|
+
self.args = args
|
894
|
+
self.kwargs = kwargs
|
895
|
+
|
896
|
+
def __get__(self, instance, owner):
|
897
|
+
value = instance.__dict__[self.attribute]
|
898
|
+
return self.factory(value, *self.args, **self.kwargs)
|
899
|
+
|
900
|
+
def __set__(self, instance, value):
|
901
|
+
instance.__dict__[self.attribute] = value
|
902
|
+
|
903
|
+
def __delete__(self, instance):
|
904
|
+
del instance.__dict__[self.attribute]
|
905
|
+
|
906
|
+
def wrap_object_attribute(module, name, factory, args=(), kwargs={}):
|
907
|
+
path, attribute = name.rsplit('.', 1)
|
908
|
+
parent = resolve_path(module, path)[2]
|
909
|
+
wrapper = AttributeWrapper(attribute, factory, args, kwargs)
|
910
|
+
apply_patch(parent, attribute, wrapper)
|
911
|
+
return wrapper
|
912
|
+
|
913
|
+
# Functions for creating a simple decorator using a FunctionWrapper,
|
914
|
+
# plus short cut functions for applying wrappers to functions. These are
|
915
|
+
# for use when doing monkey patching. For a more featured way of
|
916
|
+
# creating decorators see the decorator decorator instead.
|
917
|
+
|
918
|
+
def function_wrapper(wrapper):
|
919
|
+
def _wrapper(wrapped, instance, args, kwargs):
|
920
|
+
target_wrapped = args[0]
|
921
|
+
if instance is None:
|
922
|
+
target_wrapper = wrapper
|
923
|
+
elif inspect.isclass(instance):
|
924
|
+
target_wrapper = wrapper.__get__(None, instance)
|
925
|
+
else:
|
926
|
+
target_wrapper = wrapper.__get__(instance, type(instance))
|
927
|
+
return FunctionWrapper(target_wrapped, target_wrapper)
|
928
|
+
return FunctionWrapper(wrapper, _wrapper)
|
929
|
+
|
930
|
+
def wrap_function_wrapper(module, name, wrapper):
|
931
|
+
return wrap_object(module, name, FunctionWrapper, (wrapper,))
|
932
|
+
|
933
|
+
def patch_function_wrapper(module, name):
|
934
|
+
def _wrapper(wrapper):
|
935
|
+
return wrap_object(module, name, FunctionWrapper, (wrapper,))
|
936
|
+
return _wrapper
|
937
|
+
|
938
|
+
def transient_function_wrapper(module, name):
|
939
|
+
def _decorator(wrapper):
|
940
|
+
def _wrapper(wrapped, instance, args, kwargs):
|
941
|
+
target_wrapped = args[0]
|
942
|
+
if instance is None:
|
943
|
+
target_wrapper = wrapper
|
944
|
+
elif inspect.isclass(instance):
|
945
|
+
target_wrapper = wrapper.__get__(None, instance)
|
946
|
+
else:
|
947
|
+
target_wrapper = wrapper.__get__(instance, type(instance))
|
948
|
+
def _execute(wrapped, instance, args, kwargs):
|
949
|
+
(parent, attribute, original) = resolve_path(module, name)
|
950
|
+
replacement = FunctionWrapper(original, target_wrapper)
|
951
|
+
setattr(parent, attribute, replacement)
|
952
|
+
try:
|
953
|
+
return wrapped(*args, **kwargs)
|
954
|
+
finally:
|
955
|
+
setattr(parent, attribute, original)
|
956
|
+
return FunctionWrapper(target_wrapped, _execute)
|
957
|
+
return FunctionWrapper(wrapper, _wrapper)
|
958
|
+
return _decorator
|
959
|
+
|
960
|
+
# A weak function proxy. This will work on instance methods, class
|
961
|
+
# methods, static methods and regular functions. Special treatment is
|
962
|
+
# needed for the method types because the bound method is effectively a
|
963
|
+
# transient object and applying a weak reference to one will immediately
|
964
|
+
# result in it being destroyed and the weakref callback called. The weak
|
965
|
+
# reference is therefore applied to the instance the method is bound to
|
966
|
+
# and the original function. The function is then rebound at the point
|
967
|
+
# of a call via the weak function proxy.
|
968
|
+
|
969
|
+
def _weak_function_proxy_callback(ref, proxy, callback):
|
970
|
+
if proxy._self_expired:
|
971
|
+
return
|
972
|
+
|
973
|
+
proxy._self_expired = True
|
974
|
+
|
975
|
+
# This could raise an exception. We let it propagate back and let
|
976
|
+
# the weakref.proxy() deal with it, at which point it generally
|
977
|
+
# prints out a short error message direct to stderr and keeps going.
|
978
|
+
|
979
|
+
if callback is not None:
|
980
|
+
callback(proxy)
|
981
|
+
|
982
|
+
class WeakFunctionProxy(ObjectProxy):
|
983
|
+
|
984
|
+
__slots__ = ('_self_expired', '_self_instance')
|
985
|
+
|
986
|
+
def __init__(self, wrapped, callback=None):
|
987
|
+
# We need to determine if the wrapped function is actually a
|
988
|
+
# bound method. In the case of a bound method, we need to keep a
|
989
|
+
# reference to the original unbound function and the instance.
|
990
|
+
# This is necessary because if we hold a reference to the bound
|
991
|
+
# function, it will be the only reference and given it is a
|
992
|
+
# temporary object, it will almost immediately expire and
|
993
|
+
# the weakref callback triggered. So what is done is that we
|
994
|
+
# hold a reference to the instance and unbound function and
|
995
|
+
# when called bind the function to the instance once again and
|
996
|
+
# then call it. Note that we avoid using a nested function for
|
997
|
+
# the callback here so as not to cause any odd reference cycles.
|
998
|
+
|
999
|
+
_callback = callback and functools.partial(
|
1000
|
+
_weak_function_proxy_callback, proxy=self,
|
1001
|
+
callback=callback)
|
1002
|
+
|
1003
|
+
self._self_expired = False
|
1004
|
+
|
1005
|
+
if isinstance(wrapped, _FunctionWrapperBase):
|
1006
|
+
self._self_instance = weakref.ref(wrapped._self_instance,
|
1007
|
+
_callback)
|
1008
|
+
|
1009
|
+
if wrapped._self_parent is not None:
|
1010
|
+
super(WeakFunctionProxy, self).__init__(
|
1011
|
+
weakref.proxy(wrapped._self_parent, _callback))
|
1012
|
+
|
1013
|
+
else:
|
1014
|
+
super(WeakFunctionProxy, self).__init__(
|
1015
|
+
weakref.proxy(wrapped, _callback))
|
1016
|
+
|
1017
|
+
return
|
1018
|
+
|
1019
|
+
try:
|
1020
|
+
self._self_instance = weakref.ref(wrapped.__self__, _callback)
|
1021
|
+
|
1022
|
+
super(WeakFunctionProxy, self).__init__(
|
1023
|
+
weakref.proxy(wrapped.__func__, _callback))
|
1024
|
+
|
1025
|
+
except AttributeError:
|
1026
|
+
self._self_instance = None
|
1027
|
+
|
1028
|
+
super(WeakFunctionProxy, self).__init__(
|
1029
|
+
weakref.proxy(wrapped, _callback))
|
1030
|
+
|
1031
|
+
def __call__(*args, **kwargs):
|
1032
|
+
def _unpack_self(self, *args):
|
1033
|
+
return self, args
|
1034
|
+
|
1035
|
+
self, args = _unpack_self(*args)
|
1036
|
+
|
1037
|
+
# We perform a boolean check here on the instance and wrapped
|
1038
|
+
# function as that will trigger the reference error prior to
|
1039
|
+
# calling if the reference had expired.
|
1040
|
+
|
1041
|
+
instance = self._self_instance and self._self_instance()
|
1042
|
+
function = self.__wrapped__ and self.__wrapped__
|
1043
|
+
|
1044
|
+
# If the wrapped function was originally a bound function, for
|
1045
|
+
# which we retained a reference to the instance and the unbound
|
1046
|
+
# function we need to rebind the function and then call it. If
|
1047
|
+
# not just called the wrapped function.
|
1048
|
+
|
1049
|
+
if instance is None:
|
1050
|
+
return self.__wrapped__(*args, **kwargs)
|
1051
|
+
|
1052
|
+
return function.__get__(instance, type(instance))(*args, **kwargs)
|