Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: pkgutil.py
"""Utilities to support packages."""
[0] Fix | Delete
[1] Fix | Delete
from collections import namedtuple
[2] Fix | Delete
from functools import singledispatch as simplegeneric
[3] Fix | Delete
import importlib
[4] Fix | Delete
import importlib.util
[5] Fix | Delete
import importlib.machinery
[6] Fix | Delete
import os
[7] Fix | Delete
import os.path
[8] Fix | Delete
import re
[9] Fix | Delete
import sys
[10] Fix | Delete
from types import ModuleType
[11] Fix | Delete
import warnings
[12] Fix | Delete
[13] Fix | Delete
__all__ = [
[14] Fix | Delete
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
[15] Fix | Delete
'walk_packages', 'iter_modules', 'get_data',
[16] Fix | Delete
'ImpImporter', 'ImpLoader', 'read_code', 'extend_path',
[17] Fix | Delete
'ModuleInfo',
[18] Fix | Delete
]
[19] Fix | Delete
[20] Fix | Delete
[21] Fix | Delete
ModuleInfo = namedtuple('ModuleInfo', 'module_finder name ispkg')
[22] Fix | Delete
ModuleInfo.__doc__ = 'A namedtuple with minimal info about a module.'
[23] Fix | Delete
[24] Fix | Delete
[25] Fix | Delete
def _get_spec(finder, name):
[26] Fix | Delete
"""Return the finder-specific module spec."""
[27] Fix | Delete
# Works with legacy finders.
[28] Fix | Delete
try:
[29] Fix | Delete
find_spec = finder.find_spec
[30] Fix | Delete
except AttributeError:
[31] Fix | Delete
loader = finder.find_module(name)
[32] Fix | Delete
if loader is None:
[33] Fix | Delete
return None
[34] Fix | Delete
return importlib.util.spec_from_loader(name, loader)
[35] Fix | Delete
else:
[36] Fix | Delete
return find_spec(name)
[37] Fix | Delete
[38] Fix | Delete
[39] Fix | Delete
def read_code(stream):
[40] Fix | Delete
# This helper is needed in order for the PEP 302 emulation to
[41] Fix | Delete
# correctly handle compiled files
[42] Fix | Delete
import marshal
[43] Fix | Delete
[44] Fix | Delete
magic = stream.read(4)
[45] Fix | Delete
if magic != importlib.util.MAGIC_NUMBER:
[46] Fix | Delete
return None
[47] Fix | Delete
[48] Fix | Delete
stream.read(12) # Skip rest of the header
[49] Fix | Delete
return marshal.load(stream)
[50] Fix | Delete
[51] Fix | Delete
[52] Fix | Delete
def walk_packages(path=None, prefix='', onerror=None):
[53] Fix | Delete
"""Yields ModuleInfo for all modules recursively
[54] Fix | Delete
on path, or, if path is None, all accessible modules.
[55] Fix | Delete
[56] Fix | Delete
'path' should be either None or a list of paths to look for
[57] Fix | Delete
modules in.
[58] Fix | Delete
[59] Fix | Delete
'prefix' is a string to output on the front of every module name
[60] Fix | Delete
on output.
[61] Fix | Delete
[62] Fix | Delete
Note that this function must import all *packages* (NOT all
[63] Fix | Delete
modules!) on the given path, in order to access the __path__
[64] Fix | Delete
attribute to find submodules.
[65] Fix | Delete
[66] Fix | Delete
'onerror' is a function which gets called with one argument (the
[67] Fix | Delete
name of the package which was being imported) if any exception
[68] Fix | Delete
occurs while trying to import a package. If no onerror function is
[69] Fix | Delete
supplied, ImportErrors are caught and ignored, while all other
[70] Fix | Delete
exceptions are propagated, terminating the search.
[71] Fix | Delete
[72] Fix | Delete
Examples:
[73] Fix | Delete
[74] Fix | Delete
# list all modules python can access
[75] Fix | Delete
walk_packages()
[76] Fix | Delete
[77] Fix | Delete
# list all submodules of ctypes
[78] Fix | Delete
walk_packages(ctypes.__path__, ctypes.__name__+'.')
[79] Fix | Delete
"""
[80] Fix | Delete
[81] Fix | Delete
def seen(p, m={}):
[82] Fix | Delete
if p in m:
[83] Fix | Delete
return True
[84] Fix | Delete
m[p] = True
[85] Fix | Delete
[86] Fix | Delete
for info in iter_modules(path, prefix):
[87] Fix | Delete
yield info
[88] Fix | Delete
[89] Fix | Delete
if info.ispkg:
[90] Fix | Delete
try:
[91] Fix | Delete
__import__(info.name)
[92] Fix | Delete
except ImportError:
[93] Fix | Delete
if onerror is not None:
[94] Fix | Delete
onerror(info.name)
[95] Fix | Delete
except Exception:
[96] Fix | Delete
if onerror is not None:
[97] Fix | Delete
onerror(info.name)
[98] Fix | Delete
else:
[99] Fix | Delete
raise
[100] Fix | Delete
else:
[101] Fix | Delete
path = getattr(sys.modules[info.name], '__path__', None) or []
[102] Fix | Delete
[103] Fix | Delete
# don't traverse path items we've seen before
[104] Fix | Delete
path = [p for p in path if not seen(p)]
[105] Fix | Delete
[106] Fix | Delete
yield from walk_packages(path, info.name+'.', onerror)
[107] Fix | Delete
[108] Fix | Delete
[109] Fix | Delete
def iter_modules(path=None, prefix=''):
[110] Fix | Delete
"""Yields ModuleInfo for all submodules on path,
[111] Fix | Delete
or, if path is None, all top-level modules on sys.path.
[112] Fix | Delete
[113] Fix | Delete
'path' should be either None or a list of paths to look for
[114] Fix | Delete
modules in.
[115] Fix | Delete
[116] Fix | Delete
'prefix' is a string to output on the front of every module name
[117] Fix | Delete
on output.
[118] Fix | Delete
"""
[119] Fix | Delete
if path is None:
[120] Fix | Delete
importers = iter_importers()
[121] Fix | Delete
elif isinstance(path, str):
[122] Fix | Delete
raise ValueError("path must be None or list of paths to look for "
[123] Fix | Delete
"modules in")
[124] Fix | Delete
else:
[125] Fix | Delete
importers = map(get_importer, path)
[126] Fix | Delete
[127] Fix | Delete
yielded = {}
[128] Fix | Delete
for i in importers:
[129] Fix | Delete
for name, ispkg in iter_importer_modules(i, prefix):
[130] Fix | Delete
if name not in yielded:
[131] Fix | Delete
yielded[name] = 1
[132] Fix | Delete
yield ModuleInfo(i, name, ispkg)
[133] Fix | Delete
[134] Fix | Delete
[135] Fix | Delete
@simplegeneric
[136] Fix | Delete
def iter_importer_modules(importer, prefix=''):
[137] Fix | Delete
if not hasattr(importer, 'iter_modules'):
[138] Fix | Delete
return []
[139] Fix | Delete
return importer.iter_modules(prefix)
[140] Fix | Delete
[141] Fix | Delete
[142] Fix | Delete
# Implement a file walker for the normal importlib path hook
[143] Fix | Delete
def _iter_file_finder_modules(importer, prefix=''):
[144] Fix | Delete
if importer.path is None or not os.path.isdir(importer.path):
[145] Fix | Delete
return
[146] Fix | Delete
[147] Fix | Delete
yielded = {}
[148] Fix | Delete
import inspect
[149] Fix | Delete
try:
[150] Fix | Delete
filenames = os.listdir(importer.path)
[151] Fix | Delete
except OSError:
[152] Fix | Delete
# ignore unreadable directories like import does
[153] Fix | Delete
filenames = []
[154] Fix | Delete
filenames.sort() # handle packages before same-named modules
[155] Fix | Delete
[156] Fix | Delete
for fn in filenames:
[157] Fix | Delete
modname = inspect.getmodulename(fn)
[158] Fix | Delete
if modname=='__init__' or modname in yielded:
[159] Fix | Delete
continue
[160] Fix | Delete
[161] Fix | Delete
path = os.path.join(importer.path, fn)
[162] Fix | Delete
ispkg = False
[163] Fix | Delete
[164] Fix | Delete
if not modname and os.path.isdir(path) and '.' not in fn:
[165] Fix | Delete
modname = fn
[166] Fix | Delete
try:
[167] Fix | Delete
dircontents = os.listdir(path)
[168] Fix | Delete
except OSError:
[169] Fix | Delete
# ignore unreadable directories like import does
[170] Fix | Delete
dircontents = []
[171] Fix | Delete
for fn in dircontents:
[172] Fix | Delete
subname = inspect.getmodulename(fn)
[173] Fix | Delete
if subname=='__init__':
[174] Fix | Delete
ispkg = True
[175] Fix | Delete
break
[176] Fix | Delete
else:
[177] Fix | Delete
continue # not a package
[178] Fix | Delete
[179] Fix | Delete
if modname and '.' not in modname:
[180] Fix | Delete
yielded[modname] = 1
[181] Fix | Delete
yield prefix + modname, ispkg
[182] Fix | Delete
[183] Fix | Delete
iter_importer_modules.register(
[184] Fix | Delete
importlib.machinery.FileFinder, _iter_file_finder_modules)
[185] Fix | Delete
[186] Fix | Delete
[187] Fix | Delete
def _import_imp():
[188] Fix | Delete
global imp
[189] Fix | Delete
with warnings.catch_warnings():
[190] Fix | Delete
warnings.simplefilter('ignore', DeprecationWarning)
[191] Fix | Delete
imp = importlib.import_module('imp')
[192] Fix | Delete
[193] Fix | Delete
class ImpImporter:
[194] Fix | Delete
"""PEP 302 Finder that wraps Python's "classic" import algorithm
[195] Fix | Delete
[196] Fix | Delete
ImpImporter(dirname) produces a PEP 302 finder that searches that
[197] Fix | Delete
directory. ImpImporter(None) produces a PEP 302 finder that searches
[198] Fix | Delete
the current sys.path, plus any modules that are frozen or built-in.
[199] Fix | Delete
[200] Fix | Delete
Note that ImpImporter does not currently support being used by placement
[201] Fix | Delete
on sys.meta_path.
[202] Fix | Delete
"""
[203] Fix | Delete
[204] Fix | Delete
def __init__(self, path=None):
[205] Fix | Delete
global imp
[206] Fix | Delete
warnings.warn("This emulation is deprecated, use 'importlib' instead",
[207] Fix | Delete
DeprecationWarning)
[208] Fix | Delete
_import_imp()
[209] Fix | Delete
self.path = path
[210] Fix | Delete
[211] Fix | Delete
def find_module(self, fullname, path=None):
[212] Fix | Delete
# Note: we ignore 'path' argument since it is only used via meta_path
[213] Fix | Delete
subname = fullname.split(".")[-1]
[214] Fix | Delete
if subname != fullname and self.path is None:
[215] Fix | Delete
return None
[216] Fix | Delete
if self.path is None:
[217] Fix | Delete
path = None
[218] Fix | Delete
else:
[219] Fix | Delete
path = [os.path.realpath(self.path)]
[220] Fix | Delete
try:
[221] Fix | Delete
file, filename, etc = imp.find_module(subname, path)
[222] Fix | Delete
except ImportError:
[223] Fix | Delete
return None
[224] Fix | Delete
return ImpLoader(fullname, file, filename, etc)
[225] Fix | Delete
[226] Fix | Delete
def iter_modules(self, prefix=''):
[227] Fix | Delete
if self.path is None or not os.path.isdir(self.path):
[228] Fix | Delete
return
[229] Fix | Delete
[230] Fix | Delete
yielded = {}
[231] Fix | Delete
import inspect
[232] Fix | Delete
try:
[233] Fix | Delete
filenames = os.listdir(self.path)
[234] Fix | Delete
except OSError:
[235] Fix | Delete
# ignore unreadable directories like import does
[236] Fix | Delete
filenames = []
[237] Fix | Delete
filenames.sort() # handle packages before same-named modules
[238] Fix | Delete
[239] Fix | Delete
for fn in filenames:
[240] Fix | Delete
modname = inspect.getmodulename(fn)
[241] Fix | Delete
if modname=='__init__' or modname in yielded:
[242] Fix | Delete
continue
[243] Fix | Delete
[244] Fix | Delete
path = os.path.join(self.path, fn)
[245] Fix | Delete
ispkg = False
[246] Fix | Delete
[247] Fix | Delete
if not modname and os.path.isdir(path) and '.' not in fn:
[248] Fix | Delete
modname = fn
[249] Fix | Delete
try:
[250] Fix | Delete
dircontents = os.listdir(path)
[251] Fix | Delete
except OSError:
[252] Fix | Delete
# ignore unreadable directories like import does
[253] Fix | Delete
dircontents = []
[254] Fix | Delete
for fn in dircontents:
[255] Fix | Delete
subname = inspect.getmodulename(fn)
[256] Fix | Delete
if subname=='__init__':
[257] Fix | Delete
ispkg = True
[258] Fix | Delete
break
[259] Fix | Delete
else:
[260] Fix | Delete
continue # not a package
[261] Fix | Delete
[262] Fix | Delete
if modname and '.' not in modname:
[263] Fix | Delete
yielded[modname] = 1
[264] Fix | Delete
yield prefix + modname, ispkg
[265] Fix | Delete
[266] Fix | Delete
[267] Fix | Delete
class ImpLoader:
[268] Fix | Delete
"""PEP 302 Loader that wraps Python's "classic" import algorithm
[269] Fix | Delete
"""
[270] Fix | Delete
code = source = None
[271] Fix | Delete
[272] Fix | Delete
def __init__(self, fullname, file, filename, etc):
[273] Fix | Delete
warnings.warn("This emulation is deprecated, use 'importlib' instead",
[274] Fix | Delete
DeprecationWarning)
[275] Fix | Delete
_import_imp()
[276] Fix | Delete
self.file = file
[277] Fix | Delete
self.filename = filename
[278] Fix | Delete
self.fullname = fullname
[279] Fix | Delete
self.etc = etc
[280] Fix | Delete
[281] Fix | Delete
def load_module(self, fullname):
[282] Fix | Delete
self._reopen()
[283] Fix | Delete
try:
[284] Fix | Delete
mod = imp.load_module(fullname, self.file, self.filename, self.etc)
[285] Fix | Delete
finally:
[286] Fix | Delete
if self.file:
[287] Fix | Delete
self.file.close()
[288] Fix | Delete
# Note: we don't set __loader__ because we want the module to look
[289] Fix | Delete
# normal; i.e. this is just a wrapper for standard import machinery
[290] Fix | Delete
return mod
[291] Fix | Delete
[292] Fix | Delete
def get_data(self, pathname):
[293] Fix | Delete
with open(pathname, "rb") as file:
[294] Fix | Delete
return file.read()
[295] Fix | Delete
[296] Fix | Delete
def _reopen(self):
[297] Fix | Delete
if self.file and self.file.closed:
[298] Fix | Delete
mod_type = self.etc[2]
[299] Fix | Delete
if mod_type==imp.PY_SOURCE:
[300] Fix | Delete
self.file = open(self.filename, 'r')
[301] Fix | Delete
elif mod_type in (imp.PY_COMPILED, imp.C_EXTENSION):
[302] Fix | Delete
self.file = open(self.filename, 'rb')
[303] Fix | Delete
[304] Fix | Delete
def _fix_name(self, fullname):
[305] Fix | Delete
if fullname is None:
[306] Fix | Delete
fullname = self.fullname
[307] Fix | Delete
elif fullname != self.fullname:
[308] Fix | Delete
raise ImportError("Loader for module %s cannot handle "
[309] Fix | Delete
"module %s" % (self.fullname, fullname))
[310] Fix | Delete
return fullname
[311] Fix | Delete
[312] Fix | Delete
def is_package(self, fullname):
[313] Fix | Delete
fullname = self._fix_name(fullname)
[314] Fix | Delete
return self.etc[2]==imp.PKG_DIRECTORY
[315] Fix | Delete
[316] Fix | Delete
def get_code(self, fullname=None):
[317] Fix | Delete
fullname = self._fix_name(fullname)
[318] Fix | Delete
if self.code is None:
[319] Fix | Delete
mod_type = self.etc[2]
[320] Fix | Delete
if mod_type==imp.PY_SOURCE:
[321] Fix | Delete
source = self.get_source(fullname)
[322] Fix | Delete
self.code = compile(source, self.filename, 'exec')
[323] Fix | Delete
elif mod_type==imp.PY_COMPILED:
[324] Fix | Delete
self._reopen()
[325] Fix | Delete
try:
[326] Fix | Delete
self.code = read_code(self.file)
[327] Fix | Delete
finally:
[328] Fix | Delete
self.file.close()
[329] Fix | Delete
elif mod_type==imp.PKG_DIRECTORY:
[330] Fix | Delete
self.code = self._get_delegate().get_code()
[331] Fix | Delete
return self.code
[332] Fix | Delete
[333] Fix | Delete
def get_source(self, fullname=None):
[334] Fix | Delete
fullname = self._fix_name(fullname)
[335] Fix | Delete
if self.source is None:
[336] Fix | Delete
mod_type = self.etc[2]
[337] Fix | Delete
if mod_type==imp.PY_SOURCE:
[338] Fix | Delete
self._reopen()
[339] Fix | Delete
try:
[340] Fix | Delete
self.source = self.file.read()
[341] Fix | Delete
finally:
[342] Fix | Delete
self.file.close()
[343] Fix | Delete
elif mod_type==imp.PY_COMPILED:
[344] Fix | Delete
if os.path.exists(self.filename[:-1]):
[345] Fix | Delete
with open(self.filename[:-1], 'r') as f:
[346] Fix | Delete
self.source = f.read()
[347] Fix | Delete
elif mod_type==imp.PKG_DIRECTORY:
[348] Fix | Delete
self.source = self._get_delegate().get_source()
[349] Fix | Delete
return self.source
[350] Fix | Delete
[351] Fix | Delete
def _get_delegate(self):
[352] Fix | Delete
finder = ImpImporter(self.filename)
[353] Fix | Delete
spec = _get_spec(finder, '__init__')
[354] Fix | Delete
return spec.loader
[355] Fix | Delete
[356] Fix | Delete
def get_filename(self, fullname=None):
[357] Fix | Delete
fullname = self._fix_name(fullname)
[358] Fix | Delete
mod_type = self.etc[2]
[359] Fix | Delete
if mod_type==imp.PKG_DIRECTORY:
[360] Fix | Delete
return self._get_delegate().get_filename()
[361] Fix | Delete
elif mod_type in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION):
[362] Fix | Delete
return self.filename
[363] Fix | Delete
return None
[364] Fix | Delete
[365] Fix | Delete
[366] Fix | Delete
try:
[367] Fix | Delete
import zipimport
[368] Fix | Delete
from zipimport import zipimporter
[369] Fix | Delete
[370] Fix | Delete
def iter_zipimport_modules(importer, prefix=''):
[371] Fix | Delete
dirlist = sorted(zipimport._zip_directory_cache[importer.archive])
[372] Fix | Delete
_prefix = importer.prefix
[373] Fix | Delete
plen = len(_prefix)
[374] Fix | Delete
yielded = {}
[375] Fix | Delete
import inspect
[376] Fix | Delete
for fn in dirlist:
[377] Fix | Delete
if not fn.startswith(_prefix):
[378] Fix | Delete
continue
[379] Fix | Delete
[380] Fix | Delete
fn = fn[plen:].split(os.sep)
[381] Fix | Delete
[382] Fix | Delete
if len(fn)==2 and fn[1].startswith('__init__.py'):
[383] Fix | Delete
if fn[0] not in yielded:
[384] Fix | Delete
yielded[fn[0]] = 1
[385] Fix | Delete
yield prefix + fn[0], True
[386] Fix | Delete
[387] Fix | Delete
if len(fn)!=1:
[388] Fix | Delete
continue
[389] Fix | Delete
[390] Fix | Delete
modname = inspect.getmodulename(fn[0])
[391] Fix | Delete
if modname=='__init__':
[392] Fix | Delete
continue
[393] Fix | Delete
[394] Fix | Delete
if modname and '.' not in modname and modname not in yielded:
[395] Fix | Delete
yielded[modname] = 1
[396] Fix | Delete
yield prefix + modname, False
[397] Fix | Delete
[398] Fix | Delete
iter_importer_modules.register(zipimporter, iter_zipimport_modules)
[399] Fix | Delete
[400] Fix | Delete
except ImportError:
[401] Fix | Delete
pass
[402] Fix | Delete
[403] Fix | Delete
[404] Fix | Delete
def get_importer(path_item):
[405] Fix | Delete
"""Retrieve a finder for the given path item
[406] Fix | Delete
[407] Fix | Delete
The returned finder is cached in sys.path_importer_cache
[408] Fix | Delete
if it was newly created by a path hook.
[409] Fix | Delete
[410] Fix | Delete
The cache (or part of it) can be cleared manually if a
[411] Fix | Delete
rescan of sys.path_hooks is necessary.
[412] Fix | Delete
"""
[413] Fix | Delete
path_item = os.fsdecode(path_item)
[414] Fix | Delete
try:
[415] Fix | Delete
importer = sys.path_importer_cache[path_item]
[416] Fix | Delete
except KeyError:
[417] Fix | Delete
for path_hook in sys.path_hooks:
[418] Fix | Delete
try:
[419] Fix | Delete
importer = path_hook(path_item)
[420] Fix | Delete
sys.path_importer_cache.setdefault(path_item, importer)
[421] Fix | Delete
break
[422] Fix | Delete
except ImportError:
[423] Fix | Delete
pass
[424] Fix | Delete
else:
[425] Fix | Delete
importer = None
[426] Fix | Delete
return importer
[427] Fix | Delete
[428] Fix | Delete
[429] Fix | Delete
def iter_importers(fullname=""):
[430] Fix | Delete
"""Yield finders for the given module name
[431] Fix | Delete
[432] Fix | Delete
If fullname contains a '.', the finders will be for the package
[433] Fix | Delete
containing fullname, otherwise they will be all registered top level
[434] Fix | Delete
finders (i.e. those on both sys.meta_path and sys.path_hooks).
[435] Fix | Delete
[436] Fix | Delete
If the named module is in a package, that package is imported as a side
[437] Fix | Delete
effect of invoking this function.
[438] Fix | Delete
[439] Fix | Delete
If no module name is specified, all top level finders are produced.
[440] Fix | Delete
"""
[441] Fix | Delete
if fullname.startswith('.'):
[442] Fix | Delete
msg = "Relative module name {!r} not supported".format(fullname)
[443] Fix | Delete
raise ImportError(msg)
[444] Fix | Delete
if '.' in fullname:
[445] Fix | Delete
# Get the containing package's __path__
[446] Fix | Delete
pkg_name = fullname.rpartition(".")[0]
[447] Fix | Delete
pkg = importlib.import_module(pkg_name)
[448] Fix | Delete
path = getattr(pkg, '__path__', None)
[449] Fix | Delete
if path is None:
[450] Fix | Delete
return
[451] Fix | Delete
else:
[452] Fix | Delete
yield from sys.meta_path
[453] Fix | Delete
path = sys.path
[454] Fix | Delete
for item in path:
[455] Fix | Delete
yield get_importer(item)
[456] Fix | Delete
[457] Fix | Delete
[458] Fix | Delete
def get_loader(module_or_name):
[459] Fix | Delete
"""Get a "loader" object for module_or_name
[460] Fix | Delete
[461] Fix | Delete
Returns None if the module cannot be found or imported.
[462] Fix | Delete
If the named module is not already imported, its containing package
[463] Fix | Delete
(if any) is imported, in order to establish the package __path__.
[464] Fix | Delete
"""
[465] Fix | Delete
if module_or_name in sys.modules:
[466] Fix | Delete
module_or_name = sys.modules[module_or_name]
[467] Fix | Delete
if module_or_name is None:
[468] Fix | Delete
return None
[469] Fix | Delete
if isinstance(module_or_name, ModuleType):
[470] Fix | Delete
module = module_or_name
[471] Fix | Delete
loader = getattr(module, '__loader__', None)
[472] Fix | Delete
if loader is not None:
[473] Fix | Delete
return loader
[474] Fix | Delete
if getattr(module, '__spec__', None) is None:
[475] Fix | Delete
return None
[476] Fix | Delete
fullname = module.__name__
[477] Fix | Delete
else:
[478] Fix | Delete
fullname = module_or_name
[479] Fix | Delete
return find_loader(fullname)
[480] Fix | Delete
[481] Fix | Delete
[482] Fix | Delete
def find_loader(fullname):
[483] Fix | Delete
"""Find a "loader" object for fullname
[484] Fix | Delete
[485] Fix | Delete
This is a backwards compatibility wrapper around
[486] Fix | Delete
importlib.util.find_spec that converts most failures to ImportError
[487] Fix | Delete
and only returns the loader rather than the full spec
[488] Fix | Delete
"""
[489] Fix | Delete
if fullname.startswith('.'):
[490] Fix | Delete
msg = "Relative module name {!r} not supported".format(fullname)
[491] Fix | Delete
raise ImportError(msg)
[492] Fix | Delete
try:
[493] Fix | Delete
spec = importlib.util.find_spec(fullname)
[494] Fix | Delete
except (ImportError, AttributeError, TypeError, ValueError) as ex:
[495] Fix | Delete
# This hack fixes an impedance mismatch between pkgutil and
[496] Fix | Delete
# importlib, where the latter raises other errors for cases where
[497] Fix | Delete
# pkgutil previously raised ImportError
[498] Fix | Delete
msg = "Error while finding loader for {!r} ({}: {})"
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function