Make python 3.4 compat module loading (fix #1733)

This commit is contained in:
Lyndon White 2018-02-09 23:03:35 +08:00 committed by GitHub
parent ab33e274f5
commit 6ee5dff51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -43,15 +43,15 @@ fix_text = ftfy.fix_text
copy_array = copy_array
izip = getattr(itertools, 'izip', zip)
is_python2 = six.PY2
is_python3 = six.PY3
is_windows = sys.platform.startswith('win')
is_linux = sys.platform.startswith('linux')
is_osx = sys.platform == 'darwin'
is_python2 = six.PY2
is_python3 = six.PY3
is_python_pre_3_5 = is_python2 or (is_python3 and sys.version_info[1]<5)
if is_python2:
import imp
bytes_ = str
unicode_ = unicode # noqa: F821
basestring_ = basestring # noqa: F821
@ -60,7 +60,6 @@ if is_python2:
path2str = lambda path: str(path).decode('utf8')
elif is_python3:
import importlib.util
bytes_ = bytes
unicode_ = str
basestring_ = str
@ -111,9 +110,11 @@ def normalize_string_keys(old):
def import_file(name, loc):
loc = str(loc)
if is_python2:
if is_python_pre_3_5:
import imp
return imp.load_source(name, loc)
else:
import importlib.util
spec = importlib.util.spec_from_file_location(name, str(loc))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)