Skip to content

Commit

Permalink
Take care of all other occurences which should be directed at `collec…
Browse files Browse the repository at this point in the history
…tions.abc`
  • Loading branch information
s0undt3ch authored and dwoz committed May 19, 2020
1 parent 385b99e commit d810801
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 270 deletions.
7 changes: 3 additions & 4 deletions salt/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
# 5. Cache auth token with relative data opts['token_dir']
# 6. Interface to verify tokens

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import collections
import getpass
import logging
import random
import time
from collections.abc import Iterable, Mapping

# Import salt libs
import salt.config
import salt.exceptions
import salt.loader
Expand Down Expand Up @@ -202,9 +201,9 @@ def _allow_custom_expire(self, load):
if expire_override is True:
return True

if isinstance(expire_override, collections.Mapping):
if isinstance(expire_override, Mapping):
expire_whitelist = expire_override.get(load["eauth"], [])
if isinstance(expire_whitelist, collections.Iterable):
if isinstance(expire_whitelist, Iterable):
if load.get("username") in expire_whitelist:
return True

Expand Down
19 changes: 11 additions & 8 deletions salt/client/ssh/wrapper/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
Return/control aspects of the grains data
"""

# Import python libs
from __future__ import absolute_import, print_function

import collections
import copy
import math

# Import salt libs
import salt.utils.data
import salt.utils.dictupdate
import salt.utils.json
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException

# Import 3rd-party libs
from salt.ext import six

try:
# Python 3
from collections.abc import Mapping
except ImportError:
# We still allow Py2 import because this could be executed in a machine with Py2.
from collections import Mapping # pylint: disable=no-name-in-module


# Seed the grains dict so cython will build
__grains__ = {}

Expand Down Expand Up @@ -261,15 +264,15 @@ def filter_by(lookup_dict, grain="os_family", merge=None, default="default", bas
if ret is None:
ret = base_values

elif isinstance(base_values, collections.Mapping):
if not isinstance(ret, collections.Mapping):
elif isinstance(base_values, Mapping):
if not isinstance(ret, Mapping):
raise SaltException(
"filter_by default and look-up values must both be dictionaries."
)
ret = salt.utils.dictupdate.update(copy.deepcopy(base_values), ret)

if merge:
if not isinstance(merge, collections.Mapping):
if not isinstance(merge, Mapping):
raise SaltException("filter_by merge argument must be a dictionary.")
else:
if ret is None:
Expand Down
14 changes: 8 additions & 6 deletions salt/client/ssh/wrapper/pillar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
"""
from __future__ import absolute_import, print_function

# Import python libs
import collections

# Import salt libs
import salt.pillar
import salt.utils.data
import salt.utils.dictupdate
from salt.defaults import DEFAULT_TARGET_DELIM

try:
# Python 3
from collections.abc import Mapping
except ImportError:
# We still allow Py2 import because this could be executed in a machine with Py2.
from collections import Mapping # pylint: disable=no-name-in-module


def get(key, default="", merge=False, delimiter=DEFAULT_TARGET_DELIM):
"""
Expand Down Expand Up @@ -53,9 +57,7 @@ def get(key, default="", merge=False, delimiter=DEFAULT_TARGET_DELIM):
"""
if merge:
ret = salt.utils.data.traverse_dict_and_list(__pillar__, key, {}, delimiter)
if isinstance(ret, collections.Mapping) and isinstance(
default, collections.Mapping
):
if isinstance(ret, Mapping) and isinstance(default, Mapping):
return salt.utils.dictupdate.update(default, ret)

return salt.utils.data.traverse_dict_and_list(__pillar__, key, default, delimiter)
Expand Down
4 changes: 2 additions & 2 deletions salt/fileserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ def backends(self, back=None):

if isinstance(back, Sequence):
# The test suite uses an ImmutableList type (based on
# collections.Sequence) for lists, which breaks this function in
# collections.abc.Sequence) for lists, which breaks this function in
# the test suite. This normalizes the value from the opts into a
# list if it is based on collections.Sequence.
# list if it is based on collections.abc.Sequence.
back = list(back)

ret = []
Expand Down
9 changes: 3 additions & 6 deletions salt/modules/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
master to the minion and vice-versa.
"""

# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals

import collections
import logging
import os
import sys
import traceback
from collections.abc import Mapping

# Import salt libs
import salt.crypt
import salt.payload
import salt.transport.client
import salt.utils.event
import salt.utils.zeromq
from salt.ext import six

__proxyenabled__ = ["*"]
log = logging.getLogger(__name__)
Expand All @@ -29,7 +26,7 @@ def _dict_subset(keys, master_dict):
"""
Return a dictionary of only the subset of keys/values specified in keys
"""
return dict([(k, v) for k, v in six.iteritems(master_dict) if k in keys])
return dict([(k, v) for k, v in master_dict.items() if k in keys])


def fire_master(data, tag, preload=None):
Expand Down Expand Up @@ -237,7 +234,7 @@ def send(
data_dict.update(kwargs)

# Allow values in the ``data`` arg to override any of the above values.
if isinstance(data, collections.Mapping):
if isinstance(data, Mapping):
data_dict.update(data)

if (
Expand Down
16 changes: 6 additions & 10 deletions salt/modules/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
This does **NOT** override any grains set in the minion config file.
"""

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import collections
Expand All @@ -19,6 +18,7 @@
import operator
import os
import random
from collections.abc import Mapping
from functools import reduce # pylint: disable=redefined-builtin

import salt.utils.compat
Expand All @@ -30,10 +30,6 @@
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException

# Import Salt libs
from salt.ext import six
from salt.ext.six.moves import range

__proxyenabled__ = ["*"]

# Seed the grains dict so cython will build
Expand Down Expand Up @@ -163,7 +159,7 @@ def items(sanitize=False):
"""
if salt.utils.data.is_true(sanitize):
out = dict(__grains__)
for key, func in six.iteritems(_SANITIZERS):
for key, func in _SANITIZERS.items():
if key in out:
out[key] = func(out[key])
return out
Expand Down Expand Up @@ -201,7 +197,7 @@ def item(*args, **kwargs):
pass

if salt.utils.data.is_true(kwargs.get("sanitize")):
for arg, func in six.iteritems(_SANITIZERS):
for arg, func in _SANITIZERS.items():
if arg in ret:
ret[arg] = func(ret[arg])
return ret
Expand All @@ -226,7 +222,7 @@ def setvals(grains, destructive=False, refresh_pillar=True):
salt '*' grains.setvals "{'key1': 'val1', 'key2': 'val2'}"
"""
new_grains = grains
if not isinstance(new_grains, collections.Mapping):
if not isinstance(new_grains, Mapping):
raise SaltException("setvals grains must be a dictionary.")
grains = {}
if os.path.isfile(__opts__["conf_file"]):
Expand Down Expand Up @@ -265,7 +261,7 @@ def setvals(grains, destructive=False, refresh_pillar=True):
return "Unable to read existing grains file: {0}".format(exc)
if not isinstance(grains, dict):
grains = {}
for key, val in six.iteritems(new_grains):
for key, val in new_grains.items():
if val is None and destructive is True:
if key in grains:
del grains[key]
Expand Down Expand Up @@ -788,7 +784,7 @@ def equals(key, value):
salt '*' grains.equals fqdn <expected_fqdn>
salt '*' grains.equals systemd:version 219
"""
return six.text_type(value) == six.text_type(get(key))
return str(value) == str(get(key))


# Provide a jinja function call compatible get aliased as fetch
Expand Down
4 changes: 2 additions & 2 deletions salt/modules/influxdbmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

import collections
import logging
from collections.abc import Sequence

# Import salt libs
import salt.utils.json
from salt.state import STATE_INTERNAL_KEYWORDS as _STATE_INTERNAL_KEYWORDS

Expand Down Expand Up @@ -714,7 +714,7 @@ def query(database, query, **client_args):
client = _client(**client_args)
_result = client.query(query, database=database)

if isinstance(_result, collections.Sequence):
if isinstance(_result, Sequence):
return [
_pull_query_results(_query_result)
for _query_result in _result
Expand Down
7 changes: 2 additions & 5 deletions salt/modules/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
"""
from __future__ import absolute_import, print_function, unicode_literals

import collections
import copy

# Import python libs
import inspect
import logging
import sys
from collections.abc import Mapping

# Import salt libs
import salt.loader
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException
Expand Down Expand Up @@ -358,7 +355,7 @@ def filter_by(
params = (key, minion_id) if minion_id else (key,)
if expr_funcs[tgt_type](*params):
if merge:
if not isinstance(merge, collections.Mapping):
if not isinstance(merge, Mapping):
raise SaltException(
"filter_by merge argument must be a dictionary."
)
Expand Down
Loading

0 comments on commit d810801

Please sign in to comment.