Don't use the deprecated imp.get_suffixes() under Py3.

This commit is contained in:
Pedro Algarvio 2015-10-20 14:07:33 +01:00
parent 2d5e06554a
commit 96021565a9

View File

@ -44,6 +44,20 @@ log = logging.getLogger(__name__)
SALT_BASE_PATH = os.path.abspath(os.path.dirname(salt.__file__))
LOADED_BASE_NAME = 'salt.loaded'
if six.PY3:
# pylint: disable=no-member,no-name-in-module,import-error
import importlib.machinery
SUFFIXES = []
for suffix in importlib.machinery.EXTENSION_SUFFIXES:
SUFFIXES.append((suffix, 'rb', 3))
for suffix in importlib.machinery.BYTECODE_SUFFIXES:
SUFFIXES.append((suffix, 'rb', 2))
for suffix in importlib.machinery.SOURCE_SUFFIXES:
SUFFIXES.append((suffix, 'r', 1))
# pylint: enable=no-member,no-name-in-module,import-error
else:
SUFFIXES = imp.get_suffixes()
# Because on the cloud drivers we do `from salt.cloud.libcloudfuncs import *`
# which simplifies code readability, it adds some unsupported functions into
# the driver's module scope.
@ -969,7 +983,7 @@ class LazyLoader(salt.utils.lazy.LazyDict):
# map of suffix to description for imp
self.suffix_map = {}
suffix_order = [] # local list to determine precedence of extensions
for (suffix, mode, kind) in imp.get_suffixes():
for (suffix, mode, kind) in SUFFIXES:
self.suffix_map[suffix] = (suffix, mode, kind)
suffix_order.append(suffix)