mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Updating various imports that have been moved from collections to collections.abc, and will be deprecated in collections beginning in 3.8.
This commit is contained in:
parent
93df5c4f16
commit
d118a9fe53
10 changed files with 81 additions and 31 deletions
|
@ -6,7 +6,13 @@ Minion enabling different transports.
|
|||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# Import Python Libs
|
||||
import sys
|
||||
from collections import namedtuple, Iterable, Sequence, Mapping
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import Iterable, Sequence, Mapping
|
||||
from collections import namedtuple
|
||||
else:
|
||||
from collections import namedtuple, Iterable, Sequence, Mapping
|
||||
|
||||
import logging
|
||||
|
||||
# Import Salt Libs
|
||||
|
|
|
@ -5,12 +5,13 @@ File server pluggable modules and generic backend functions
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import collections
|
||||
|
||||
import errno
|
||||
import fnmatch
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
# Import salt libs
|
||||
|
@ -23,6 +24,11 @@ import salt.utils.versions
|
|||
from salt.utils.args import get_function_argspec as _argspec
|
||||
from salt.utils.decorators import ensure_unicode_args
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import Sequence
|
||||
else:
|
||||
from collections import Sequence
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
|
@ -341,7 +347,7 @@ class Fileserver(object):
|
|||
except AttributeError:
|
||||
back = six.text_type(back).split(',')
|
||||
|
||||
if isinstance(back, collections.Sequence):
|
||||
if isinstance(back, Sequence):
|
||||
# The test suite uses an ImmutableList type (based on
|
||||
# collections.Sequence) for lists, which breaks this function in
|
||||
# the test suite. This normalizes the value from the opts into a
|
||||
|
|
|
@ -18,7 +18,6 @@ import functools
|
|||
import threading
|
||||
import traceback
|
||||
import types
|
||||
from collections import MutableMapping
|
||||
from zipimport import zipimporter
|
||||
|
||||
# Import salt libs
|
||||
|
@ -50,6 +49,11 @@ else:
|
|||
import imp
|
||||
USE_IMPORTLIB = False
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import MutableMapping
|
||||
else:
|
||||
from collections import MutableMapping
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
HAS_PKG_RESOURCES = True
|
||||
|
|
|
@ -14,7 +14,12 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
# Import python libs
|
||||
import copy
|
||||
import threading
|
||||
import collections
|
||||
import sys
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import MutableMapping
|
||||
else:
|
||||
from collections import MutableMapping
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from salt.ext import six
|
||||
|
@ -57,7 +62,7 @@ def func_globals_inject(func, **overrides):
|
|||
del func_globals[injected]
|
||||
|
||||
|
||||
class ContextDict(collections.MutableMapping):
|
||||
class ContextDict(MutableMapping):
|
||||
'''
|
||||
A context manager that saves some per-thread state globally.
|
||||
Intended for use with Tornado's StackContext.
|
||||
|
@ -142,7 +147,7 @@ class ContextDict(collections.MutableMapping):
|
|||
return new_obj
|
||||
|
||||
|
||||
class ChildContextDict(collections.MutableMapping):
|
||||
class ChildContextDict(MutableMapping):
|
||||
'''An overrideable child of ContextDict
|
||||
|
||||
'''
|
||||
|
@ -190,7 +195,7 @@ class ChildContextDict(collections.MutableMapping):
|
|||
self.parent._state.data = self._old_data
|
||||
|
||||
|
||||
class NamespacedDictWrapper(collections.MutableMapping, dict):
|
||||
class NamespacedDictWrapper(MutableMapping, dict):
|
||||
'''
|
||||
Create a dict which wraps another dict with a specific prefix of key(s)
|
||||
|
||||
|
|
|
@ -7,11 +7,16 @@ and data structures.
|
|||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import collections
|
||||
import copy
|
||||
import fnmatch
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import MutableMapping, Mapping
|
||||
else:
|
||||
from collections import MutableMapping, Mapping
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.dictupdate
|
||||
|
@ -100,7 +105,7 @@ def decode(data, encoding=None, errors='strict', keep=False,
|
|||
_decode_func = salt.utils.stringutils.to_unicode \
|
||||
if not to_str \
|
||||
else salt.utils.stringutils.to_str
|
||||
if isinstance(data, collections.Mapping):
|
||||
if isinstance(data, Mapping):
|
||||
return decode_dict(data, encoding, errors, keep, normalize,
|
||||
preserve_dict_class, preserve_tuples, to_str)
|
||||
elif isinstance(data, list):
|
||||
|
@ -166,7 +171,7 @@ def decode_dict(data, encoding=None, errors='strict', keep=False,
|
|||
if preserve_tuples \
|
||||
else decode_list(value, encoding, errors, keep, normalize,
|
||||
preserve_dict_class, preserve_tuples, to_str)
|
||||
elif isinstance(value, collections.Mapping):
|
||||
elif isinstance(value, Mapping):
|
||||
value = decode_dict(value, encoding, errors, keep, normalize,
|
||||
preserve_dict_class, preserve_tuples, to_str)
|
||||
else:
|
||||
|
@ -206,7 +211,7 @@ def decode_list(data, encoding=None, errors='strict', keep=False,
|
|||
if preserve_tuples \
|
||||
else decode_list(item, encoding, errors, keep, normalize,
|
||||
preserve_dict_class, preserve_tuples, to_str)
|
||||
elif isinstance(item, collections.Mapping):
|
||||
elif isinstance(item, Mapping):
|
||||
item = decode_dict(item, encoding, errors, keep, normalize,
|
||||
preserve_dict_class, preserve_tuples, to_str)
|
||||
else:
|
||||
|
@ -248,7 +253,7 @@ def encode(data, encoding=None, errors='strict', keep=False,
|
|||
can be useful for cases where the data passed to this function is likely to
|
||||
contain binary blobs.
|
||||
'''
|
||||
if isinstance(data, collections.Mapping):
|
||||
if isinstance(data, Mapping):
|
||||
return encode_dict(data, encoding, errors, keep,
|
||||
preserve_dict_class, preserve_tuples)
|
||||
elif isinstance(data, list):
|
||||
|
@ -307,7 +312,7 @@ def encode_dict(data, encoding=None, errors='strict', keep=False,
|
|||
if preserve_tuples \
|
||||
else encode_list(value, encoding, errors, keep,
|
||||
preserve_dict_class, preserve_tuples)
|
||||
elif isinstance(value, collections.Mapping):
|
||||
elif isinstance(value, Mapping):
|
||||
value = encode_dict(value, encoding, errors, keep,
|
||||
preserve_dict_class, preserve_tuples)
|
||||
else:
|
||||
|
@ -343,7 +348,7 @@ def encode_list(data, encoding=None, errors='strict', keep=False,
|
|||
if preserve_tuples \
|
||||
else encode_list(item, encoding, errors, keep,
|
||||
preserve_dict_class, preserve_tuples)
|
||||
elif isinstance(item, collections.Mapping):
|
||||
elif isinstance(item, Mapping):
|
||||
item = encode_dict(item, encoding, errors, keep,
|
||||
preserve_dict_class, preserve_tuples)
|
||||
else:
|
||||
|
@ -424,15 +429,15 @@ def filter_by(lookup_dict,
|
|||
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.')
|
||||
|
||||
|
|
|
@ -6,7 +6,12 @@ http://stackoverflow.com/a/3233356
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import collections
|
||||
import sys
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import Mapping
|
||||
else:
|
||||
from collections import Mapping
|
||||
|
||||
# Import 3rd-party libs
|
||||
import copy
|
||||
|
@ -35,8 +40,8 @@ def update(dest, upd, recursive_update=True, merge_lists=False):
|
|||
When merging lists, duplicate values are removed. Values already
|
||||
present in the ``dest`` list are not added from the ``upd`` list.
|
||||
'''
|
||||
if (not isinstance(dest, collections.Mapping)) \
|
||||
or (not isinstance(upd, collections.Mapping)):
|
||||
if (not isinstance(dest, Mapping)) \
|
||||
or (not isinstance(upd, Mapping)):
|
||||
raise TypeError('Cannot update using non-dict types in dictupdate.update()')
|
||||
updkeys = list(upd.keys())
|
||||
if not set(list(dest.keys())) & set(updkeys):
|
||||
|
@ -48,8 +53,8 @@ def update(dest, upd, recursive_update=True, merge_lists=False):
|
|||
dest_subkey = dest.get(key, None)
|
||||
except AttributeError:
|
||||
dest_subkey = None
|
||||
if isinstance(dest_subkey, collections.Mapping) \
|
||||
and isinstance(val, collections.Mapping):
|
||||
if isinstance(dest_subkey, Mapping) \
|
||||
and isinstance(val, Mapping):
|
||||
ret = update(dest_subkey, val, merge_lists=merge_lists)
|
||||
dest[key] = ret
|
||||
elif isinstance(dest_subkey, list) \
|
||||
|
|
|
@ -60,7 +60,12 @@ import hashlib
|
|||
import logging
|
||||
import datetime
|
||||
import sys
|
||||
from collections import MutableMapping
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import MutableMapping
|
||||
else:
|
||||
from collections import MutableMapping
|
||||
|
||||
from multiprocessing.util import Finalize
|
||||
from salt.ext.six.moves import range
|
||||
|
||||
|
|
|
@ -11,10 +11,14 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import collections
|
||||
import sys
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import Mapping, Sequence, Set
|
||||
else:
|
||||
from collections import Mapping, Sequence, Set
|
||||
|
||||
|
||||
class ImmutableDict(collections.Mapping):
|
||||
class ImmutableDict(Mapping):
|
||||
'''
|
||||
An immutable dictionary implementation
|
||||
'''
|
||||
|
@ -35,7 +39,7 @@ class ImmutableDict(collections.Mapping):
|
|||
return '<{0} {1}>'.format(self.__class__.__name__, repr(self.__obj))
|
||||
|
||||
|
||||
class ImmutableList(collections.Sequence):
|
||||
class ImmutableList(Sequence):
|
||||
'''
|
||||
An immutable list implementation
|
||||
'''
|
||||
|
@ -62,7 +66,7 @@ class ImmutableList(collections.Sequence):
|
|||
return '<{0} {1}>'.format(self.__class__.__name__, repr(self.__obj))
|
||||
|
||||
|
||||
class ImmutableSet(collections.Set):
|
||||
class ImmutableSet(Set):
|
||||
'''
|
||||
An immutable set implementation
|
||||
'''
|
||||
|
|
|
@ -6,9 +6,14 @@ Lazily-evaluated data structures, primarily used by Salt's loader
|
|||
# Import Python Libs
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import logging
|
||||
import collections
|
||||
import sys
|
||||
import salt.exceptions
|
||||
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import MutableMapping
|
||||
else:
|
||||
from collections import MutableMapping
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -26,7 +31,7 @@ def verify_fun(lazy_obj, fun):
|
|||
raise salt.exceptions.CommandExecutionError(lazy_obj.missing_fun_string(fun))
|
||||
|
||||
|
||||
class LazyDict(collections.MutableMapping):
|
||||
class LazyDict(MutableMapping):
|
||||
'''
|
||||
A base class of dict which will lazily load keys once they are needed
|
||||
|
||||
|
|
|
@ -22,7 +22,12 @@
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
from collections import Callable
|
||||
|
||||
import sys
|
||||
if sys.version_info > (3, 7):
|
||||
from collections.abc import Callable
|
||||
else:
|
||||
from collections import Callable
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
|
Loading…
Add table
Reference in a new issue