From 236c80c16e986b9f1083d2c7e02d0d6ec850690b Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 26 Dec 2019 13:39:10 -0600 Subject: [PATCH] fix imp deprecation --- src/pyramid/path.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pyramid/path.py b/src/pyramid/path.py index 6a85c3e952..0ec2849c19 100644 --- a/src/pyramid/path.py +++ b/src/pyramid/path.py @@ -1,7 +1,6 @@ import os import pkg_resources import sys -import imp from zope.interface import implementer @@ -9,12 +8,20 @@ from pyramid._compat import string_types -ignore_types = [imp.C_EXTENSION, imp.C_BUILTIN] -init_names = [ - '__init__%s' % x[0] - for x in imp.get_suffixes() - if x[0] and x[2] not in ignore_types -] +try: + from importlib.machinery import SOURCE_SUFFIXES +except ImportError: + # `importlib.machinery` is missing on Python < 3.3 + # `imp` is deprecated on Python > 3.4 + import imp + + ignore_types = [imp.C_EXTENSION, imp.C_BUILTIN] + SOURCE_SUFFIXES = [ + _suffix for _suffix, _, _type in imp.get_suffixes() + if _suffix and _type not in ignore_types + ] + +init_names = ['__init__%s' % x for x in SOURCE_SUFFIXES] def caller_path(path, level=2):