From 96021565a97bc52a6b11b483ec2b0d3a222433d1 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 20 Oct 2015 14:07:33 +0100 Subject: [PATCH] Don't use the deprecated `imp.get_suffixes()` under Py3. --- salt/loader.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/salt/loader.py b/salt/loader.py index 3b25ff737f..189a5f5a9f 100644 --- a/salt/loader.py +++ b/salt/loader.py @@ -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)