ansible-core 2.19.3rc1__py3-none-any.whl → 2.20.0b2__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.

Potentially problematic release.


This version of ansible-core might be problematic. Click here for more details.

Files changed (201) hide show
  1. ansible/_internal/__init__.py +1 -4
  2. ansible/_internal/_ansiballz/_builder.py +1 -3
  3. ansible/_internal/_collection_proxy.py +7 -9
  4. ansible/_internal/_json/__init__.py +3 -4
  5. ansible/_internal/_templating/_engine.py +1 -1
  6. ansible/_internal/_templating/_jinja_plugins.py +1 -2
  7. ansible/_internal/_wrapt.py +105 -301
  8. ansible/cli/__init__.py +11 -10
  9. ansible/cli/adhoc.py +1 -2
  10. ansible/cli/arguments/option_helpers.py +1 -1
  11. ansible/cli/config.py +5 -6
  12. ansible/cli/doc.py +70 -68
  13. ansible/cli/galaxy.py +15 -24
  14. ansible/cli/inventory.py +0 -1
  15. ansible/cli/playbook.py +0 -1
  16. ansible/cli/pull.py +0 -1
  17. ansible/cli/scripts/ansible_connection_cli_stub.py +1 -1
  18. ansible/collections/list.py +4 -2
  19. ansible/config/base.yml +1 -25
  20. ansible/config/manager.py +0 -2
  21. ansible/executor/play_iterator.py +42 -20
  22. ansible/executor/playbook_executor.py +0 -9
  23. ansible/executor/task_executor.py +26 -18
  24. ansible/executor/task_queue_manager.py +1 -3
  25. ansible/galaxy/api.py +33 -80
  26. ansible/galaxy/collection/__init__.py +4 -17
  27. ansible/galaxy/dependency_resolution/dataclasses.py +0 -10
  28. ansible/galaxy/dependency_resolution/providers.py +24 -118
  29. ansible/galaxy/role.py +1 -33
  30. ansible/inventory/manager.py +2 -3
  31. ansible/keyword_desc.yml +0 -3
  32. ansible/module_utils/_internal/_datatag/__init__.py +2 -10
  33. ansible/module_utils/_internal/_no_six.py +86 -0
  34. ansible/module_utils/_text.py +28 -8
  35. ansible/module_utils/ansible_release.py +2 -2
  36. ansible/module_utils/basic.py +26 -23
  37. ansible/module_utils/common/_collections_compat.py +11 -2
  38. ansible/module_utils/common/collections.py +8 -3
  39. ansible/module_utils/common/dict_transformations.py +1 -2
  40. ansible/module_utils/common/network.py +4 -2
  41. ansible/module_utils/common/parameters.py +32 -41
  42. ansible/module_utils/common/text/converters.py +109 -23
  43. ansible/module_utils/common/text/formatters.py +6 -2
  44. ansible/module_utils/common/validation.py +11 -9
  45. ansible/module_utils/connection.py +8 -3
  46. ansible/module_utils/facts/hardware/linux.py +23 -7
  47. ansible/module_utils/facts/hardware/netbsd.py +1 -1
  48. ansible/module_utils/facts/hardware/sunos.py +2 -1
  49. ansible/module_utils/facts/packages.py +6 -2
  50. ansible/module_utils/facts/system/distribution.py +2 -1
  51. ansible/module_utils/facts/system/env.py +6 -3
  52. ansible/module_utils/facts/system/local.py +3 -1
  53. ansible/module_utils/parsing/convert_bool.py +6 -2
  54. ansible/module_utils/service.py +2 -3
  55. ansible/module_utils/six/__init__.py +19 -6
  56. ansible/module_utils/yumdnf.py +0 -5
  57. ansible/modules/apt.py +18 -13
  58. ansible/modules/apt_repository.py +1 -1
  59. ansible/modules/assemble.py +5 -9
  60. ansible/modules/blockinfile.py +39 -23
  61. ansible/modules/cron.py +26 -35
  62. ansible/modules/deb822_repository.py +83 -12
  63. ansible/modules/dnf.py +3 -7
  64. ansible/modules/dnf5.py +4 -6
  65. ansible/modules/expect.py +0 -3
  66. ansible/modules/find.py +1 -2
  67. ansible/modules/get_url.py +1 -1
  68. ansible/modules/git.py +4 -5
  69. ansible/modules/include_vars.py +1 -1
  70. ansible/modules/known_hosts.py +7 -1
  71. ansible/modules/lineinfile.py +71 -63
  72. ansible/modules/package_facts.py +1 -1
  73. ansible/modules/pip.py +8 -2
  74. ansible/modules/replace.py +6 -6
  75. ansible/modules/service.py +3 -4
  76. ansible/modules/stat.py +20 -0
  77. ansible/modules/uri.py +9 -10
  78. ansible/modules/user.py +1 -2
  79. ansible/modules/wait_for.py +2 -2
  80. ansible/modules/wait_for_connection.py +2 -1
  81. ansible/modules/yum_repository.py +1 -16
  82. ansible/parsing/dataloader.py +24 -31
  83. ansible/parsing/mod_args.py +3 -0
  84. ansible/parsing/vault/__init__.py +1 -2
  85. ansible/playbook/base.py +8 -56
  86. ansible/playbook/block.py +1 -63
  87. ansible/playbook/collectionsearch.py +1 -2
  88. ansible/playbook/handler.py +1 -7
  89. ansible/playbook/helpers.py +15 -20
  90. ansible/playbook/included_file.py +1 -1
  91. ansible/playbook/play.py +105 -49
  92. ansible/playbook/play_context.py +4 -0
  93. ansible/playbook/role/__init__.py +10 -65
  94. ansible/playbook/role/definition.py +3 -4
  95. ansible/playbook/role/include.py +2 -3
  96. ansible/playbook/role/metadata.py +1 -12
  97. ansible/playbook/role/requirement.py +1 -2
  98. ansible/playbook/role_include.py +1 -2
  99. ansible/playbook/taggable.py +16 -5
  100. ansible/playbook/task.py +51 -55
  101. ansible/plugins/action/__init__.py +20 -19
  102. ansible/plugins/action/add_host.py +1 -2
  103. ansible/plugins/action/fetch.py +3 -5
  104. ansible/plugins/action/group_by.py +1 -2
  105. ansible/plugins/action/include_vars.py +20 -22
  106. ansible/plugins/action/script.py +1 -3
  107. ansible/plugins/action/template.py +1 -2
  108. ansible/plugins/action/uri.py +4 -2
  109. ansible/plugins/cache/__init__.py +1 -0
  110. ansible/plugins/callback/__init__.py +13 -6
  111. ansible/plugins/connection/__init__.py +3 -7
  112. ansible/plugins/connection/local.py +2 -3
  113. ansible/plugins/connection/psrp.py +0 -2
  114. ansible/plugins/connection/ssh.py +2 -7
  115. ansible/plugins/connection/winrm.py +0 -2
  116. ansible/plugins/doc_fragments/result_format_callback.py +15 -0
  117. ansible/plugins/filter/core.py +4 -5
  118. ansible/plugins/filter/encryption.py +3 -27
  119. ansible/plugins/filter/mathstuff.py +1 -2
  120. ansible/plugins/filter/to_nice_yaml.yml +31 -3
  121. ansible/plugins/filter/to_yaml.yml +29 -12
  122. ansible/plugins/inventory/__init__.py +1 -2
  123. ansible/plugins/inventory/toml.py +3 -6
  124. ansible/plugins/inventory/yaml.py +1 -2
  125. ansible/plugins/loader.py +3 -4
  126. ansible/plugins/lookup/password.py +1 -2
  127. ansible/plugins/lookup/subelements.py +2 -3
  128. ansible/plugins/lookup/url.py +1 -1
  129. ansible/plugins/lookup/varnames.py +1 -2
  130. ansible/plugins/shell/__init__.py +9 -4
  131. ansible/plugins/shell/powershell.py +8 -24
  132. ansible/plugins/strategy/__init__.py +6 -3
  133. ansible/plugins/test/core.py +4 -1
  134. ansible/plugins/test/falsy.yml +1 -1
  135. ansible/plugins/test/regex.yml +18 -6
  136. ansible/plugins/test/truthy.yml +1 -1
  137. ansible/release.py +2 -2
  138. ansible/template/__init__.py +3 -7
  139. ansible/utils/collection_loader/_collection_config.py +5 -0
  140. ansible/utils/collection_loader/_collection_finder.py +11 -14
  141. ansible/utils/context_objects.py +7 -4
  142. ansible/utils/display.py +7 -6
  143. ansible/utils/encrypt.py +0 -5
  144. ansible/utils/helpers.py +6 -2
  145. ansible/utils/jsonrpc.py +7 -3
  146. ansible/utils/plugin_docs.py +49 -38
  147. ansible/utils/ssh_functions.py +0 -19
  148. ansible/utils/unsafe_proxy.py +7 -7
  149. ansible/vars/clean.py +2 -3
  150. ansible/vars/manager.py +28 -22
  151. ansible/vars/plugins.py +1 -31
  152. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/METADATA +3 -3
  153. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/RECORD +199 -200
  154. ansible_test/_data/completion/docker.txt +7 -7
  155. ansible_test/_data/completion/network.txt +0 -1
  156. ansible_test/_data/completion/remote.txt +4 -4
  157. ansible_test/_data/requirements/ansible-test.txt +1 -1
  158. ansible_test/_data/requirements/sanity.changelog.txt +1 -1
  159. ansible_test/_data/requirements/sanity.pep8.txt +1 -1
  160. ansible_test/_data/requirements/sanity.pylint.txt +4 -4
  161. ansible_test/_internal/cache.py +2 -5
  162. ansible_test/_internal/cli/compat.py +1 -1
  163. ansible_test/_internal/commands/coverage/combine.py +1 -3
  164. ansible_test/_internal/commands/integration/__init__.py +3 -7
  165. ansible_test/_internal/commands/integration/cloud/httptester.py +1 -1
  166. ansible_test/_internal/commands/integration/coverage.py +1 -3
  167. ansible_test/_internal/commands/integration/filters.py +5 -10
  168. ansible_test/_internal/commands/sanity/validate_modules.py +1 -5
  169. ansible_test/_internal/commands/units/__init__.py +1 -13
  170. ansible_test/_internal/completion.py +2 -5
  171. ansible_test/_internal/config.py +2 -7
  172. ansible_test/_internal/coverage_util.py +1 -1
  173. ansible_test/_internal/delegation.py +2 -0
  174. ansible_test/_internal/docker_util.py +1 -1
  175. ansible_test/_internal/host_profiles.py +6 -11
  176. ansible_test/_internal/provider/__init__.py +2 -5
  177. ansible_test/_internal/provisioning.py +2 -5
  178. ansible_test/_internal/pypi_proxy.py +1 -1
  179. ansible_test/_internal/target.py +2 -6
  180. ansible_test/_internal/thread.py +1 -4
  181. ansible_test/_internal/util.py +9 -14
  182. ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py +14 -19
  183. ansible_test/_util/controller/sanity/pylint/plugins/unwanted.py +40 -27
  184. ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py +31 -18
  185. ansible_test/_util/controller/sanity/validate-modules/validate_modules/module_args.py +1 -2
  186. ansible_test/_util/controller/sanity/validate-modules/validate_modules/schema.py +59 -71
  187. ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py +1 -2
  188. ansible_test/_util/target/cli/ansible_test_cli_stub.py +4 -2
  189. ansible_test/_util/target/common/constants.py +2 -2
  190. ansible_test/_util/target/setup/bootstrap.sh +0 -6
  191. ansible/utils/py3compat.py +0 -27
  192. ansible_test/_data/pytest/config/legacy.ini +0 -4
  193. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/WHEEL +0 -0
  194. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/entry_points.txt +0 -0
  195. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/licenses/COPYING +0 -0
  196. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/licenses/licenses/Apache-License.txt +0 -0
  197. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/licenses/licenses/BSD-3-Clause.txt +0 -0
  198. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/licenses/licenses/MIT-license.txt +0 -0
  199. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/licenses/licenses/PSF-license.txt +0 -0
  200. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/licenses/licenses/simplified_bsd.txt +0 -0
  201. {ansible_core-2.19.3rc1.dist-info → ansible_core-2.20.0b2.dist-info}/top_level.txt +0 -0
@@ -9,9 +9,19 @@ import os
9
9
  import typing as t
10
10
 
11
11
  from collections import deque
12
- from itertools import chain
12
+ from collections.abc import (
13
+ KeysView,
14
+ Set,
15
+ Sequence,
16
+ Mapping,
17
+ MutableMapping,
18
+ MutableSet,
19
+ MutableSequence,
20
+ )
21
+ from itertools import chain # pylint: disable=unused-import
13
22
 
14
23
  from ansible.module_utils.common.collections import is_iterable
24
+ from ansible.module_utils._internal import _no_six
15
25
  from ansible.module_utils._internal._datatag import AnsibleSerializable, AnsibleTagHelper
16
26
  from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
17
27
  from ansible.module_utils.common.warnings import warn
@@ -33,26 +43,6 @@ from ansible.module_utils.errors import (
33
43
  SubParameterTypeError,
34
44
  )
35
45
  from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
36
-
37
- from ansible.module_utils.six.moves.collections_abc import (
38
- KeysView,
39
- Set,
40
- Sequence,
41
- Mapping,
42
- MutableMapping,
43
- MutableSet,
44
- MutableSequence,
45
- )
46
-
47
- from ansible.module_utils.six import (
48
- binary_type,
49
- integer_types,
50
- string_types,
51
- text_type,
52
- PY2,
53
- PY3,
54
- )
55
-
56
46
  from ansible.module_utils.common.validation import (
57
47
  check_mutually_exclusive,
58
48
  check_required_arguments,
@@ -243,7 +233,7 @@ def _handle_aliases(argument_spec, parameters, alias_warnings=None, alias_deprec
243
233
  if aliases is None:
244
234
  continue
245
235
 
246
- if not is_iterable(aliases) or isinstance(aliases, (binary_type, text_type)):
236
+ if not is_iterable(aliases) or isinstance(aliases, (bytes, str)):
247
237
  raise TypeError('internal error: aliases must be a list or tuple')
248
238
 
249
239
  for alias in aliases:
@@ -346,7 +336,7 @@ def _list_no_log_values(argument_spec, params):
346
336
  for sub_param in sub_parameters:
347
337
  # Validate dict fields in case they came in as strings
348
338
 
349
- if isinstance(sub_param, string_types):
339
+ if isinstance(sub_param, str):
350
340
  sub_param = check_type_dict(sub_param)
351
341
 
352
342
  if not isinstance(sub_param, Mapping):
@@ -362,7 +352,7 @@ def _return_datastructure_name(obj):
362
352
  """ Return native stringified values from datastructures.
363
353
 
364
354
  For use with removing sensitive values pre-jsonification."""
365
- if isinstance(obj, (text_type, binary_type)):
355
+ if isinstance(obj, (str, bytes)):
366
356
  if obj:
367
357
  yield to_native(obj, errors='surrogate_or_strict')
368
358
  return
@@ -375,7 +365,7 @@ def _return_datastructure_name(obj):
375
365
  elif obj is None or isinstance(obj, bool):
376
366
  # This must come before int because bools are also ints
377
367
  return
378
- elif isinstance(obj, tuple(list(integer_types) + [float])):
368
+ elif isinstance(obj, (int, float)):
379
369
  yield to_native(obj, nonstring='simplerepr')
380
370
  else:
381
371
  raise TypeError('Unknown parameter type: %s' % (type(obj)))
@@ -413,26 +403,23 @@ def _remove_values_conditions(value, no_log_strings, deferred_removals):
413
403
  """
414
404
  original_value = value
415
405
 
416
- if isinstance(value, (text_type, binary_type)):
406
+ if isinstance(value, (str, bytes)):
417
407
  # Need native str type
418
408
  native_str_value = value
419
- if isinstance(value, text_type):
409
+ if isinstance(value, str):
420
410
  value_is_text = True
421
- if PY2:
422
- native_str_value = to_bytes(value, errors='surrogate_or_strict')
423
- elif isinstance(value, binary_type):
411
+ elif isinstance(value, bytes):
424
412
  value_is_text = False
425
- if PY3:
426
- native_str_value = to_text(value, errors='surrogate_or_strict')
413
+ native_str_value = to_text(value, errors='surrogate_or_strict')
427
414
 
428
415
  if native_str_value in no_log_strings:
429
416
  return 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER'
430
417
  for omit_me in no_log_strings:
431
418
  native_str_value = native_str_value.replace(omit_me, '*' * 8)
432
419
 
433
- if value_is_text and isinstance(native_str_value, binary_type):
420
+ if value_is_text and isinstance(native_str_value, bytes):
434
421
  value = to_text(native_str_value, encoding='utf-8', errors='surrogate_then_replace')
435
- elif not value_is_text and isinstance(native_str_value, text_type):
422
+ elif not value_is_text and isinstance(native_str_value, str):
436
423
  value = to_bytes(native_str_value, encoding='utf-8', errors='surrogate_then_replace')
437
424
  else:
438
425
  value = native_str_value
@@ -514,7 +501,7 @@ def _set_defaults(argument_spec, parameters, set_default=True):
514
501
 
515
502
  def _sanitize_keys_conditions(value, no_log_strings, ignore_keys, deferred_removals):
516
503
  """ Helper method to :func:`sanitize_keys` to build ``deferred_removals`` and avoid deep recursion. """
517
- if isinstance(value, (text_type, binary_type)):
504
+ if isinstance(value, (str, bytes)):
518
505
  return value
519
506
 
520
507
  if isinstance(value, Sequence):
@@ -541,7 +528,7 @@ def _sanitize_keys_conditions(value, no_log_strings, ignore_keys, deferred_remov
541
528
  deferred_removals.append((value, new_value))
542
529
  return new_value
543
530
 
544
- if isinstance(value, tuple(chain(integer_types, (float, bool, NoneType)))):
531
+ if isinstance(value, (int, float, bool, NoneType)):
545
532
  return value
546
533
 
547
534
  if isinstance(value, (datetime.datetime, datetime.date, datetime.time)):
@@ -560,8 +547,8 @@ def _validate_elements(wanted_type, parameter, values, options_context=None, err
560
547
  # Get param name for strings so we can later display this value in a useful error message if needed
561
548
  # Only pass 'kwargs' to our checkers and ignore custom callable checkers
562
549
  kwargs = {}
563
- if wanted_element_type == 'str' and isinstance(wanted_type, string_types):
564
- if isinstance(parameter, string_types):
550
+ if wanted_element_type == 'str' and isinstance(wanted_type, str):
551
+ if isinstance(parameter, str):
565
552
  kwargs['param'] = parameter
566
553
  elif isinstance(parameter, dict):
567
554
  kwargs['param'] = list(parameter.keys())[0]
@@ -620,7 +607,7 @@ def _validate_argument_types(argument_spec, parameters, prefix='', options_conte
620
607
  # Get param name for strings so we can later display this value in a useful error message if needed
621
608
  # Only pass 'kwargs' to our checkers and ignore custom callable checkers
622
609
  kwargs = {}
623
- if wanted_name == 'str' and isinstance(wanted_type, string_types):
610
+ if wanted_name == 'str' and isinstance(wanted_type, str):
624
611
  kwargs['param'] = list(parameters.keys())[0]
625
612
 
626
613
  # Get the name of the parent key if this is a nested option
@@ -659,7 +646,7 @@ def _validate_argument_values(argument_spec, parameters, options_context=None, e
659
646
  if choices is None:
660
647
  continue
661
648
 
662
- if isinstance(choices, (frozenset, KeysView, Sequence)) and not isinstance(choices, (binary_type, text_type)):
649
+ if isinstance(choices, (frozenset, KeysView, Sequence)) and not isinstance(choices, (bytes, str)):
663
650
  if param in parameters:
664
651
  # Allow one or more when type='list' param with choices
665
652
  if isinstance(parameters[param], list):
@@ -745,7 +732,7 @@ def _validate_sub_spec(
745
732
  options_context.append(param)
746
733
 
747
734
  # Make sure we can iterate over the elements
748
- if not isinstance(parameters[param], Sequence) or isinstance(parameters[param], string_types):
735
+ if not isinstance(parameters[param], Sequence) or isinstance(parameters[param], str):
749
736
  elements = [parameters[param]]
750
737
  else:
751
738
  elements = parameters[param]
@@ -940,3 +927,7 @@ def remove_values(value, no_log_strings):
940
927
  raise TypeError('Unknown container type encountered when removing private values from output')
941
928
 
942
929
  return new_value
930
+
931
+
932
+ def __getattr__(importable_name):
933
+ return _no_six.deprecate(importable_name, __name__, "binary_type", "text_type", "integer_types", "string_types", "PY2", "PY3")
@@ -8,11 +8,8 @@ from __future__ import annotations
8
8
  import codecs
9
9
  import json
10
10
 
11
- from ansible.module_utils.six import (
12
- binary_type,
13
- iteritems,
14
- text_type,
15
- )
11
+ from ansible.module_utils.compat import typing as _t
12
+ from ansible.module_utils._internal import _no_six
16
13
 
17
14
  try:
18
15
  codecs.lookup_error('surrogateescape')
@@ -25,8 +22,54 @@ _COMPOSED_ERROR_HANDLERS = frozenset((None, 'surrogate_or_replace',
25
22
  'surrogate_or_strict',
26
23
  'surrogate_then_replace'))
27
24
 
25
+ _T = _t.TypeVar('_T')
28
26
 
29
- def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
27
+ _NonStringPassthru: _t.TypeAlias = _t.Literal['passthru']
28
+ _NonStringOther: _t.TypeAlias = _t.Literal['simplerepr', 'empty', 'strict']
29
+ _NonStringAll: _t.TypeAlias = _t.Union[_NonStringPassthru, _NonStringOther]
30
+
31
+
32
+ @_t.overload
33
+ def to_bytes(
34
+ obj: object,
35
+ encoding: str = 'utf-8',
36
+ errors: str | None = None,
37
+ ) -> bytes: ...
38
+
39
+
40
+ @_t.overload
41
+ def to_bytes(
42
+ obj: bytes | str,
43
+ encoding: str = 'utf-8',
44
+ errors: str | None = None,
45
+ nonstring: _NonStringPassthru = 'passthru',
46
+ ) -> bytes: ...
47
+
48
+
49
+ @_t.overload
50
+ def to_bytes(
51
+ obj: _T,
52
+ encoding: str = 'utf-8',
53
+ errors: str | None = None,
54
+ nonstring: _NonStringPassthru = 'passthru',
55
+ ) -> _T: ...
56
+
57
+
58
+ @_t.overload
59
+ def to_bytes(
60
+ obj: object,
61
+ encoding: str = 'utf-8',
62
+ errors: str | None = None,
63
+ nonstring: _NonStringOther = 'simplerepr',
64
+ ) -> bytes: ...
65
+
66
+
67
+ def to_bytes(
68
+ obj: _T,
69
+ encoding: str = 'utf-8',
70
+ errors: str | None = None,
71
+ nonstring: _NonStringAll = 'simplerepr'
72
+ ) -> _T | bytes:
30
73
  """Make sure that a string is a byte string
31
74
 
32
75
  :arg obj: An object to make sure is a byte string. In most cases this
@@ -84,13 +127,13 @@ def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
84
127
  string is valid in the specified encoding. If it's important that the
85
128
  byte string is in the specified encoding do::
86
129
 
87
- encoded_string = to_bytes(to_text(input_string, 'latin-1'), 'utf-8')
130
+ encoded_string = to_bytes(to_text(input_string, encoding='latin-1'), encoding='utf-8')
88
131
 
89
132
  .. version_changed:: 2.3
90
133
 
91
134
  Added the ``surrogate_then_replace`` error handler and made it the default error handler.
92
135
  """
93
- if isinstance(obj, binary_type):
136
+ if isinstance(obj, bytes):
94
137
  return obj
95
138
 
96
139
  # We're given a text string
@@ -104,7 +147,7 @@ def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
104
147
  else:
105
148
  errors = 'replace'
106
149
 
107
- if isinstance(obj, text_type):
150
+ if isinstance(obj, str):
108
151
  try:
109
152
  # Try this first as it's the fastest
110
153
  return obj.encode(encoding, errors)
@@ -129,21 +172,60 @@ def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
129
172
  value = repr(obj)
130
173
  except UnicodeError:
131
174
  # Giving up
132
- return to_bytes('')
175
+ return b''
133
176
  elif nonstring == 'passthru':
134
177
  return obj
135
178
  elif nonstring == 'empty':
136
- # python2.4 doesn't have b''
137
- return to_bytes('')
179
+ return b''
138
180
  elif nonstring == 'strict':
139
181
  raise TypeError('obj must be a string type')
140
182
  else:
141
183
  raise TypeError('Invalid value %s for to_bytes\' nonstring parameter' % nonstring)
142
184
 
143
- return to_bytes(value, encoding, errors)
185
+ return to_bytes(value, encoding=encoding, errors=errors)
144
186
 
145
187
 
146
- def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
188
+ @_t.overload
189
+ def to_text(
190
+ obj: object,
191
+ encoding: str = 'utf-8',
192
+ errors: str | None = None,
193
+ ) -> str: ...
194
+
195
+
196
+ @_t.overload
197
+ def to_text(
198
+ obj: str | bytes,
199
+ encoding: str = 'utf-8',
200
+ errors: str | None = None,
201
+ nonstring: _NonStringPassthru = 'passthru',
202
+ ) -> str: ...
203
+
204
+
205
+ @_t.overload
206
+ def to_text(
207
+ obj: _T,
208
+ encoding: str = 'utf-8',
209
+ errors: str | None = None,
210
+ nonstring: _NonStringPassthru = 'passthru',
211
+ ) -> _T: ...
212
+
213
+
214
+ @_t.overload
215
+ def to_text(
216
+ obj: object,
217
+ encoding: str = 'utf-8',
218
+ errors: str | None = None,
219
+ nonstring: _NonStringOther = 'simplerepr',
220
+ ) -> str: ...
221
+
222
+
223
+ def to_text(
224
+ obj: _T,
225
+ encoding: str = 'utf-8',
226
+ errors: str | None = None,
227
+ nonstring: _NonStringAll = 'simplerepr'
228
+ ) -> _T | str:
147
229
  """Make sure that a string is a text string
148
230
 
149
231
  :arg obj: An object to make sure is a text string. In most cases this
@@ -194,7 +276,7 @@ def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
194
276
 
195
277
  Added the surrogate_then_replace error handler and made it the default error handler.
196
278
  """
197
- if isinstance(obj, text_type):
279
+ if isinstance(obj, str):
198
280
  return obj
199
281
 
200
282
  if errors in _COMPOSED_ERROR_HANDLERS:
@@ -205,7 +287,7 @@ def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
205
287
  else:
206
288
  errors = 'replace'
207
289
 
208
- if isinstance(obj, binary_type):
290
+ if isinstance(obj, bytes):
209
291
  # Note: We don't need special handling for surrogate_then_replace
210
292
  # because all bytes will either be made into surrogates or are valid
211
293
  # to decode.
@@ -221,17 +303,17 @@ def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
221
303
  value = repr(obj)
222
304
  except UnicodeError:
223
305
  # Giving up
224
- return u''
306
+ return ''
225
307
  elif nonstring == 'passthru':
226
308
  return obj
227
309
  elif nonstring == 'empty':
228
- return u''
310
+ return ''
229
311
  elif nonstring == 'strict':
230
312
  raise TypeError('obj must be a string type')
231
313
  else:
232
314
  raise TypeError('Invalid value %s for to_text\'s nonstring parameter' % nonstring)
233
315
 
234
- return to_text(value, encoding, errors)
316
+ return to_text(value, encoding=encoding, errors=errors)
235
317
 
236
318
 
237
319
  to_native = to_text
@@ -259,10 +341,10 @@ def container_to_bytes(d, encoding='utf-8', errors='surrogate_or_strict'):
259
341
  """
260
342
  # DTFIX-FUTURE: deprecate
261
343
 
262
- if isinstance(d, text_type):
344
+ if isinstance(d, str):
263
345
  return to_bytes(d, encoding=encoding, errors=errors)
264
346
  elif isinstance(d, dict):
265
- return dict(container_to_bytes(o, encoding, errors) for o in iteritems(d))
347
+ return dict(container_to_bytes(o, encoding, errors) for o in d.items())
266
348
  elif isinstance(d, list):
267
349
  return [container_to_bytes(o, encoding, errors) for o in d]
268
350
  elif isinstance(d, tuple):
@@ -279,14 +361,18 @@ def container_to_text(d, encoding='utf-8', errors='surrogate_or_strict'):
279
361
  """
280
362
  # DTFIX-FUTURE: deprecate
281
363
 
282
- if isinstance(d, binary_type):
364
+ if isinstance(d, bytes):
283
365
  # Warning, can traceback
284
366
  return to_text(d, encoding=encoding, errors=errors)
285
367
  elif isinstance(d, dict):
286
- return dict(container_to_text(o, encoding, errors) for o in iteritems(d))
368
+ return dict(container_to_text(o, encoding, errors) for o in d.items())
287
369
  elif isinstance(d, list):
288
370
  return [container_to_text(o, encoding, errors) for o in d]
289
371
  elif isinstance(d, tuple):
290
372
  return tuple(container_to_text(o, encoding, errors) for o in d)
291
373
  else:
292
374
  return d
375
+
376
+
377
+ def __getattr__(importable_name):
378
+ return _no_six.deprecate(importable_name, __name__, "binary_type", "text_type", "iteritems")
@@ -6,7 +6,7 @@ from __future__ import annotations
6
6
 
7
7
  import re
8
8
 
9
- from ansible.module_utils.six import iteritems
9
+ from ansible.module_utils._internal import _no_six
10
10
 
11
11
  SIZE_RANGES = {
12
12
  'Y': 1 << 80,
@@ -117,7 +117,7 @@ def bytes_to_human(size, isbits=False, unit=None):
117
117
  base = 'bits'
118
118
  suffix = ''
119
119
 
120
- for suffix, limit in sorted(iteritems(SIZE_RANGES), key=lambda item: -item[1]):
120
+ for suffix, limit in sorted(SIZE_RANGES.items(), key=lambda item: -item[1]):
121
121
  if (unit is None and size >= limit) or unit is not None and unit.upper() == suffix[0]:
122
122
  break
123
123
 
@@ -127,3 +127,7 @@ def bytes_to_human(size, isbits=False, unit=None):
127
127
  suffix = base
128
128
 
129
129
  return '%.2f %s' % (size / limit, suffix)
130
+
131
+
132
+ def __getattr__(importable_name):
133
+ return _no_six.deprecate(importable_name, __name__, "iteritems")
@@ -10,15 +10,13 @@ import os
10
10
  import re
11
11
 
12
12
  from ast import literal_eval
13
+ from ansible.module_utils._internal import _no_six
13
14
  from ansible.module_utils.common import json as _common_json
14
15
  from ansible.module_utils.common.text.converters import to_native
15
16
  from ansible.module_utils.common.collections import is_iterable
16
17
  from ansible.module_utils.common.text.formatters import human_to_bytes
17
18
  from ansible.module_utils.common.warnings import deprecate
18
19
  from ansible.module_utils.parsing.convert_bool import boolean
19
- from ansible.module_utils.six import (
20
- string_types,
21
- )
22
20
 
23
21
 
24
22
  def count_terms(terms, parameters):
@@ -43,7 +41,7 @@ def safe_eval(value, locals=None, include_exceptions=False):
43
41
  version="2.21",
44
42
  )
45
43
  # do not allow method calls to modules
46
- if not isinstance(value, string_types):
44
+ if not isinstance(value, str):
47
45
  # already templated to a datavaluestructure, perhaps?
48
46
  if include_exceptions:
49
47
  return (value, None)
@@ -194,7 +192,7 @@ def check_required_by(requirements, parameters, options_context=None):
194
192
  if key not in parameters or parameters[key] is None:
195
193
  continue
196
194
  # Support strings (single-item lists)
197
- if isinstance(value, string_types):
195
+ if isinstance(value, str):
198
196
  value = [value]
199
197
 
200
198
  if missing := [required for required in value if required not in parameters or parameters[required] is None]:
@@ -373,7 +371,7 @@ def check_type_str(value, allow_conversion=True, param=None, prefix=''):
373
371
  :returns: Original value if it is a string, the value converted to a string
374
372
  if allow_conversion=True, or raises a TypeError if allow_conversion=False.
375
373
  """
376
- if isinstance(value, string_types):
374
+ if isinstance(value, str):
377
375
  return value
378
376
 
379
377
  if value is None:
@@ -406,7 +404,7 @@ def check_type_list(value):
406
404
  return value
407
405
 
408
406
  # DTFIX-FUTURE: deprecate legacy comma split functionality, eventually replace with `_check_type_list_strict`
409
- if isinstance(value, string_types):
407
+ if isinstance(value, str):
410
408
  return value.split(",")
411
409
  elif isinstance(value, int) or isinstance(value, float):
412
410
  return [str(value)]
@@ -434,7 +432,7 @@ def check_type_dict(value):
434
432
  if isinstance(value, dict):
435
433
  return value
436
434
 
437
- if isinstance(value, string_types):
435
+ if isinstance(value, str):
438
436
  if value.startswith("{"):
439
437
  try:
440
438
  return json.loads(value)
@@ -497,7 +495,7 @@ def check_type_bool(value):
497
495
  if isinstance(value, bool):
498
496
  return value
499
497
 
500
- if isinstance(value, string_types) or isinstance(value, (int, float)):
498
+ if isinstance(value, str) or isinstance(value, (int, float)):
501
499
  return boolean(value)
502
500
 
503
501
  raise TypeError('%s cannot be converted to a bool' % type(value))
@@ -597,3 +595,7 @@ def check_type_jsonarg(value):
597
595
  return json.dumps(value, cls=_common_json._get_legacy_encoder(), _decode_bytes=True)
598
596
 
599
597
  raise TypeError('%s cannot be converted to a json string' % type(value))
598
+
599
+
600
+ def __getattr__(importable_name):
601
+ return _no_six.deprecate(importable_name, __name__, "string_types")
@@ -36,9 +36,10 @@ import struct
36
36
  import uuid
37
37
 
38
38
  from functools import partial
39
+
40
+ from ansible.module_utils._internal import _no_six
39
41
  from ansible.module_utils.common.text.converters import to_bytes, to_text
40
42
  from ansible.module_utils.common.json import _get_legacy_encoder
41
- from ansible.module_utils.six import iteritems
42
43
 
43
44
 
44
45
  def write_to_stream(stream, obj):
@@ -95,7 +96,7 @@ class ConnectionError(Exception):
95
96
 
96
97
  def __init__(self, message, *args, **kwargs):
97
98
  super(ConnectionError, self).__init__(message)
98
- for k, v in iteritems(kwargs):
99
+ for k, v in kwargs.items():
99
100
  setattr(self, k, v)
100
101
 
101
102
 
@@ -149,7 +150,7 @@ class Connection(object):
149
150
  raise ConnectionError(
150
151
  "Unable to decode JSON from response to {0}. Received '{1}'.".format(name, out)
151
152
  )
152
- params = [repr(arg) for arg in args] + ['{0}={1!r}'.format(k, v) for k, v in iteritems(kwargs)]
153
+ params = [repr(arg) for arg in args] + ['{0}={1!r}'.format(k, v) for k, v in kwargs.items()]
153
154
  params = ', '.join(params)
154
155
  raise ConnectionError(
155
156
  "Unable to decode JSON from response to {0}({1}). Received '{2}'.".format(name, params, out)
@@ -200,3 +201,7 @@ class Connection(object):
200
201
  sf.close()
201
202
 
202
203
  return to_text(response, errors='surrogate_or_strict')
204
+
205
+
206
+ def __getattr__(importable_name):
207
+ return _no_six.deprecate(importable_name, __name__, "iteritems")
@@ -24,13 +24,13 @@ import re
24
24
  import sys
25
25
  import time
26
26
 
27
+ from ansible.module_utils._internal import _no_six
27
28
  from ansible.module_utils._internal._concurrent import _futures
28
29
  from ansible.module_utils.common.locale import get_best_parsable_locale
29
30
  from ansible.module_utils.common.text.converters import to_text
30
31
  from ansible.module_utils.common.text.formatters import bytes_to_human
31
32
  from ansible.module_utils.facts.hardware.base import Hardware, HardwareCollector
32
33
  from ansible.module_utils.facts.utils import get_file_content, get_file_lines, get_mount_size
33
- from ansible.module_utils.six import iteritems
34
34
 
35
35
  # import this as a module to ensure we get the same module instance
36
36
  from ansible.module_utils.facts import timeout
@@ -653,7 +653,7 @@ class LinuxHardware(Hardware):
653
653
  retval[target].add(entry)
654
654
  except OSError:
655
655
  continue
656
- return dict((k, list(sorted(v))) for (k, v) in iteritems(retval))
656
+ return dict((k, list(sorted(v))) for (k, v) in retval.items())
657
657
  except OSError:
658
658
  return {}
659
659
 
@@ -665,7 +665,7 @@ class LinuxHardware(Hardware):
665
665
  device = elements[3]
666
666
  target = elements[5]
667
667
  retval[target].add(device)
668
- return dict((k, list(sorted(v))) for (k, v) in iteritems(retval))
668
+ return dict((k, list(sorted(v))) for (k, v) in retval.items())
669
669
  except OSError:
670
670
  return {}
671
671
 
@@ -750,7 +750,7 @@ class LinuxHardware(Hardware):
750
750
  d = {}
751
751
  d['virtual'] = virtual
752
752
  d['links'] = {}
753
- for (link_type, link_values) in iteritems(links):
753
+ for (link_type, link_values) in links.items():
754
754
  d['links'][link_type] = link_values.get(block, [])
755
755
  diskname = os.path.basename(sysdir)
756
756
  for key in ['vendor', 'model', 'sas_address', 'sas_device_handle']:
@@ -801,7 +801,7 @@ class LinuxHardware(Hardware):
801
801
  part_sysdir = sysdir + "/" + partname
802
802
 
803
803
  part['links'] = {}
804
- for (link_type, link_values) in iteritems(links):
804
+ for (link_type, link_values) in links.items():
805
805
  part['links'][link_type] = link_values.get(partname, [])
806
806
 
807
807
  part['start'] = get_file_content(part_sysdir + "/start", 0)
@@ -890,7 +890,8 @@ class LinuxHardware(Hardware):
890
890
  'size_g': items[-2],
891
891
  'free_g': items[-1],
892
892
  'num_lvs': items[2],
893
- 'num_pvs': items[1]
893
+ 'num_pvs': items[1],
894
+ 'lvs': {},
894
895
  }
895
896
 
896
897
  lvs_path = self.module.get_bin_path('lvs')
@@ -901,7 +902,18 @@ class LinuxHardware(Hardware):
901
902
  rc, lv_lines, err = self.module.run_command('%s %s' % (lvs_path, lvm_util_options))
902
903
  for lv_line in lv_lines.splitlines():
903
904
  items = lv_line.strip().split(',')
904
- lvs[items[0]] = {'size_g': items[3], 'vg': items[1]}
905
+ vg_name = items[1]
906
+ lv_name = items[0]
907
+ # The LV name is only unique per VG, so the top level fact lvs can be misleading.
908
+ # TODO: deprecate lvs in favor of vgs
909
+ lvs[lv_name] = {'size_g': items[3], 'vg': vg_name}
910
+ try:
911
+ vgs[vg_name]['lvs'][lv_name] = {'size_g': items[3]}
912
+ except KeyError:
913
+ self.module.warn(
914
+ "An LVM volume group was created while gathering LVM facts, "
915
+ "and is not included in ansible_facts['vgs']."
916
+ )
905
917
 
906
918
  pvs_path = self.module.get_bin_path('pvs')
907
919
  # pvs fields: PV VG #Fmt #Attr PSize PFree
@@ -925,3 +937,7 @@ class LinuxHardwareCollector(HardwareCollector):
925
937
  _fact_class = LinuxHardware
926
938
 
927
939
  required_facts = set(['platform'])
940
+
941
+
942
+ def __getattr__(importable_name):
943
+ return _no_six.deprecate(importable_name, __name__, "iteritems")
@@ -19,7 +19,7 @@ import os
19
19
  import re
20
20
  import time
21
21
 
22
- from ansible.module_utils.six.moves import reduce
22
+ from functools import reduce
23
23
 
24
24
  from ansible.module_utils.facts.hardware.base import Hardware, HardwareCollector
25
25
  from ansible.module_utils.facts.timeout import TimeoutError, timeout
@@ -18,12 +18,13 @@ from __future__ import annotations
18
18
  import re
19
19
  import time
20
20
 
21
+ from functools import reduce
22
+
21
23
  from ansible.module_utils.common.locale import get_best_parsable_locale
22
24
  from ansible.module_utils.common.text.formatters import bytes_to_human
23
25
  from ansible.module_utils.facts.utils import get_file_content, get_mount_size
24
26
  from ansible.module_utils.facts.hardware.base import Hardware, HardwareCollector
25
27
  from ansible.module_utils.facts import timeout
26
- from ansible.module_utils.six.moves import reduce
27
28
 
28
29
 
29
30
  class SunOSHardware(Hardware):