Skip to content

Commit 171a028

Browse files
authored
[stable-10] Avoid six in plugin code (#10873) (#10877)
Avoid six in plugin code (#10873) Avoid six in plugin code. (cherry picked from commit 6cd4665)
1 parent 4ab8f79 commit 171a028

37 files changed

+80
-130
lines changed

changelogs/fragments/10873-six.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- "Avoid usage of deprecated ``ansible.module_utils.six`` in all code that does not have to support Python 2 (https://github.com/ansible-collections/community.general/pull/10873)."

plugins/become/pmrun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
- This plugin ignores the C(become_user) supplied and uses C(pmrun)'s own configuration to select the user.
6060
"""
6161

62+
from shlex import quote as shlex_quote
6263
from ansible.plugins.become import BecomeBase
63-
from ansible.module_utils.six.moves import shlex_quote
6464

6565

6666
class BecomeModule(BecomeBase):

plugins/cache/pickle.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
except ImportError:
4949
import pickle
5050

51-
from ansible.module_utils.six import PY3
5251
from ansible.plugins.cache import BaseFileCacheModule
5352

5453

@@ -61,10 +60,7 @@ class CacheModule(BaseFileCacheModule):
6160
def _load(self, filepath):
6261
# Pickle is a binary format
6362
with open(filepath, 'rb') as f:
64-
if PY3:
65-
return pickle.load(f, encoding='bytes')
66-
else:
67-
return pickle.load(f)
63+
return pickle.load(f, encoding='bytes')
6864

6965
def _dump(self, value, filepath):
7066
with open(filepath, 'wb') as f:

plugins/callback/dense.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
except ImportError:
2828
pass
2929

30-
from ansible.module_utils.six import binary_type, text_type
3130
from collections.abc import MutableMapping, MutableSequence
3231
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
3332
from ansible.utils.color import colorize, hostcolor
@@ -236,7 +235,7 @@ def _clean_results(self, result):
236235

237236
# Remove empty attributes (list, dict, str)
238237
for attr in result.copy():
239-
if isinstance(result[attr], (MutableSequence, MutableMapping, binary_type, text_type)):
238+
if isinstance(result[attr], (MutableSequence, MutableMapping, bytes, str)):
240239
if not result[attr]:
241240
del result[attr]
242241

plugins/callback/elastic.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
from os.path import basename
8888

8989
from ansible.errors import AnsibleError, AnsibleRuntimeError
90-
from ansible.module_utils.six import raise_from
9190
from ansible.plugins.callback import CallbackBase
9291

9392
try:
@@ -312,9 +311,7 @@ def __init__(self, display=None):
312311
self.disabled = False
313312

314313
if ELASTIC_LIBRARY_IMPORT_ERROR:
315-
raise_from(
316-
AnsibleError('The `elastic-apm` must be installed to use this plugin'),
317-
ELASTIC_LIBRARY_IMPORT_ERROR)
314+
raise AnsibleError('The `elastic-apm` must be installed to use this plugin') from ELASTIC_LIBRARY_IMPORT_ERROR
318315

319316
self.tasks_data = OrderedDict()
320317

plugins/callback/nrdp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
type: string
6767
"""
6868

69-
from ansible.module_utils.six.moves.urllib.parse import urlencode
69+
from urllib.parse import urlencode
70+
7071
from ansible.module_utils.common.text.converters import to_bytes
7172
from ansible.module_utils.urls import open_url
7273
from ansible.plugins.callback import CallbackBase

plugins/callback/opentelemetry.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,12 @@
137137
import os
138138
import socket
139139
import uuid
140-
from time import time_ns
141-
142140
from collections import OrderedDict
143141
from os.path import basename
142+
from time import time_ns
143+
from urllib.parse import urlparse
144144

145145
from ansible.errors import AnsibleError
146-
from ansible.module_utils.six import raise_from
147-
from ansible.module_utils.six.moves.urllib.parse import urlparse
148146
from ansible.plugins.callback import CallbackBase
149147

150148
try:
@@ -499,9 +497,9 @@ def __init__(self, display=None):
499497
self.otel_exporter_otlp_traces_protocol = None
500498

501499
if OTEL_LIBRARY_IMPORT_ERROR:
502-
raise_from(
503-
AnsibleError('The `opentelemetry-api`, `opentelemetry-exporter-otlp` or `opentelemetry-sdk` must be installed to use this plugin'),
504-
OTEL_LIBRARY_IMPORT_ERROR)
500+
raise AnsibleError(
501+
'The `opentelemetry-api`, `opentelemetry-exporter-otlp` or `opentelemetry-sdk` must be installed to use this plugin'
502+
) from OTEL_LIBRARY_IMPORT_ERROR
505503

506504
self.tasks_data = OrderedDict()
507505

plugins/connection/chroot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@
7575
import os.path
7676
import subprocess
7777
import traceback
78+
from shlex import quote as shlex_quote
7879

7980
from ansible.errors import AnsibleError
8081
from ansible.module_utils.basic import is_executable
8182
from ansible.module_utils.common.process import get_bin_path
82-
from ansible.module_utils.six.moves import shlex_quote
8383
from ansible.module_utils.common.text.converters import to_bytes
8484
from ansible.plugins.connection import ConnectionBase, BUFSIZE
8585
from ansible.utils.display import Display

plugins/connection/jail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
import os.path
3939
import subprocess
4040
import traceback
41+
from shlex import quote as shlex_quote
4142

4243
from ansible.errors import AnsibleError
43-
from ansible.module_utils.six.moves import shlex_quote
4444
from ansible.module_utils.common.process import get_bin_path
4545
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
4646
from ansible.plugins.connection import ConnectionBase, BUFSIZE

plugins/connection/zone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import os.path
3232
import subprocess
3333
import traceback
34+
from shlex import quote as shlex_quote
3435

3536
from ansible.errors import AnsibleError
36-
from ansible.module_utils.six.moves import shlex_quote
3737
from ansible.module_utils.common.process import get_bin_path
3838
from ansible.module_utils.common.text.converters import to_bytes
3939
from ansible.plugins.connection import ConnectionBase, BUFSIZE

0 commit comments

Comments
 (0)