mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #49487 from garethgreenaway/49452_collections_abc
[2018.3] Swapping out collections imports
This commit is contained in:
commit
baafd6ec85
9 changed files with 71 additions and 30 deletions
|
@ -6,7 +6,14 @@ 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
|
||||
|
||||
try:
|
||||
from collections.abc import Iterable, Sequence, Mapping
|
||||
except ImportError:
|
||||
from collections import Iterable, Sequence, Mapping
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
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
|
||||
|
||||
try:
|
||||
from collections.abc import Sequence
|
||||
except ImportError:
|
||||
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
|
||||
|
||||
try:
|
||||
from collections.abc import MutableMapping
|
||||
except ImportError:
|
||||
from collections import MutableMapping
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
HAS_PKG_RESOURCES = True
|
||||
|
|
|
@ -14,7 +14,11 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
# Import python libs
|
||||
import copy
|
||||
import threading
|
||||
import collections
|
||||
try:
|
||||
from collections.abc import MutableMapping
|
||||
except ImportError:
|
||||
from collections import MutableMapping
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from salt.ext import six
|
||||
|
@ -57,7 +61,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 +146,7 @@ class ContextDict(collections.MutableMapping):
|
|||
return new_obj
|
||||
|
||||
|
||||
class ChildContextDict(collections.MutableMapping):
|
||||
class ChildContextDict(MutableMapping):
|
||||
'''An overrideable child of ContextDict
|
||||
|
||||
'''
|
||||
|
@ -190,7 +194,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,12 +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
|
||||
|
||||
try:
|
||||
from collections.abc import Mapping
|
||||
except ImportError:
|
||||
from collections import Mapping
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.dictupdate
|
||||
import salt.utils.stringutils
|
||||
|
@ -100,7 +104,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 +170,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 +210,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 +252,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 +311,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 +347,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 +428,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,11 @@ http://stackoverflow.com/a/3233356
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import collections
|
||||
|
||||
try:
|
||||
from collections.abc import Mapping
|
||||
except ImportError:
|
||||
from collections import Mapping
|
||||
|
||||
# Import 3rd-party libs
|
||||
import copy
|
||||
|
@ -35,8 +39,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 +52,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
|
||||
|
||||
try:
|
||||
from collections.abc import MutableMapping
|
||||
except ImportError:
|
||||
from collections import MutableMapping
|
||||
|
||||
from multiprocessing.util import Finalize
|
||||
from salt.ext.six.moves import range
|
||||
|
||||
|
|
|
@ -11,10 +11,13 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import collections
|
||||
try:
|
||||
from collections.abc import Mapping, Sequence, Set
|
||||
except ImportError:
|
||||
from collections import Mapping, Sequence, Set
|
||||
|
||||
|
||||
class ImmutableDict(collections.Mapping):
|
||||
class ImmutableDict(Mapping):
|
||||
'''
|
||||
An immutable dictionary implementation
|
||||
'''
|
||||
|
@ -35,7 +38,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 +65,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,13 @@ 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 salt.exceptions
|
||||
|
||||
try:
|
||||
from collections.abc import MutableMapping
|
||||
except ImportError:
|
||||
from collections import MutableMapping
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -26,7 +30,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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue