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