Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: modulefinder.py
"""Find modules used by a script, using introspection."""
[0] Fix | Delete
[1] Fix | Delete
import dis
[2] Fix | Delete
import importlib._bootstrap_external
[3] Fix | Delete
import importlib.machinery
[4] Fix | Delete
import marshal
[5] Fix | Delete
import os
[6] Fix | Delete
import io
[7] Fix | Delete
import sys
[8] Fix | Delete
import types
[9] Fix | Delete
import warnings
[10] Fix | Delete
[11] Fix | Delete
[12] Fix | Delete
LOAD_CONST = dis.opmap['LOAD_CONST']
[13] Fix | Delete
IMPORT_NAME = dis.opmap['IMPORT_NAME']
[14] Fix | Delete
STORE_NAME = dis.opmap['STORE_NAME']
[15] Fix | Delete
STORE_GLOBAL = dis.opmap['STORE_GLOBAL']
[16] Fix | Delete
STORE_OPS = STORE_NAME, STORE_GLOBAL
[17] Fix | Delete
EXTENDED_ARG = dis.EXTENDED_ARG
[18] Fix | Delete
[19] Fix | Delete
# Old imp constants:
[20] Fix | Delete
[21] Fix | Delete
_SEARCH_ERROR = 0
[22] Fix | Delete
_PY_SOURCE = 1
[23] Fix | Delete
_PY_COMPILED = 2
[24] Fix | Delete
_C_EXTENSION = 3
[25] Fix | Delete
_PKG_DIRECTORY = 5
[26] Fix | Delete
_C_BUILTIN = 6
[27] Fix | Delete
_PY_FROZEN = 7
[28] Fix | Delete
[29] Fix | Delete
# Modulefinder does a good job at simulating Python's, but it can not
[30] Fix | Delete
# handle __path__ modifications packages make at runtime. Therefore there
[31] Fix | Delete
# is a mechanism whereby you can register extra paths in this map for a
[32] Fix | Delete
# package, and it will be honored.
[33] Fix | Delete
[34] Fix | Delete
# Note this is a mapping is lists of paths.
[35] Fix | Delete
packagePathMap = {}
[36] Fix | Delete
[37] Fix | Delete
# A Public interface
[38] Fix | Delete
def AddPackagePath(packagename, path):
[39] Fix | Delete
packagePathMap.setdefault(packagename, []).append(path)
[40] Fix | Delete
[41] Fix | Delete
replacePackageMap = {}
[42] Fix | Delete
[43] Fix | Delete
# This ReplacePackage mechanism allows modulefinder to work around
[44] Fix | Delete
# situations in which a package injects itself under the name
[45] Fix | Delete
# of another package into sys.modules at runtime by calling
[46] Fix | Delete
# ReplacePackage("real_package_name", "faked_package_name")
[47] Fix | Delete
# before running ModuleFinder.
[48] Fix | Delete
[49] Fix | Delete
def ReplacePackage(oldname, newname):
[50] Fix | Delete
replacePackageMap[oldname] = newname
[51] Fix | Delete
[52] Fix | Delete
[53] Fix | Delete
def _find_module(name, path=None):
[54] Fix | Delete
"""An importlib reimplementation of imp.find_module (for our purposes)."""
[55] Fix | Delete
[56] Fix | Delete
# It's necessary to clear the caches for our Finder first, in case any
[57] Fix | Delete
# modules are being added/deleted/modified at runtime. In particular,
[58] Fix | Delete
# test_modulefinder.py changes file tree contents in a cache-breaking way:
[59] Fix | Delete
[60] Fix | Delete
importlib.machinery.PathFinder.invalidate_caches()
[61] Fix | Delete
[62] Fix | Delete
spec = importlib.machinery.PathFinder.find_spec(name, path)
[63] Fix | Delete
[64] Fix | Delete
if spec is None:
[65] Fix | Delete
raise ImportError("No module named {name!r}".format(name=name), name=name)
[66] Fix | Delete
[67] Fix | Delete
# Some special cases:
[68] Fix | Delete
[69] Fix | Delete
if spec.loader is importlib.machinery.BuiltinImporter:
[70] Fix | Delete
return None, None, ("", "", _C_BUILTIN)
[71] Fix | Delete
[72] Fix | Delete
if spec.loader is importlib.machinery.FrozenImporter:
[73] Fix | Delete
return None, None, ("", "", _PY_FROZEN)
[74] Fix | Delete
[75] Fix | Delete
file_path = spec.origin
[76] Fix | Delete
[77] Fix | Delete
if spec.loader.is_package(name):
[78] Fix | Delete
return None, os.path.dirname(file_path), ("", "", _PKG_DIRECTORY)
[79] Fix | Delete
[80] Fix | Delete
if isinstance(spec.loader, importlib.machinery.SourceFileLoader):
[81] Fix | Delete
kind = _PY_SOURCE
[82] Fix | Delete
[83] Fix | Delete
elif isinstance(spec.loader, importlib.machinery.ExtensionFileLoader):
[84] Fix | Delete
kind = _C_EXTENSION
[85] Fix | Delete
[86] Fix | Delete
elif isinstance(spec.loader, importlib.machinery.SourcelessFileLoader):
[87] Fix | Delete
kind = _PY_COMPILED
[88] Fix | Delete
[89] Fix | Delete
else: # Should never happen.
[90] Fix | Delete
return None, None, ("", "", _SEARCH_ERROR)
[91] Fix | Delete
[92] Fix | Delete
file = io.open_code(file_path)
[93] Fix | Delete
suffix = os.path.splitext(file_path)[-1]
[94] Fix | Delete
[95] Fix | Delete
return file, file_path, (suffix, "rb", kind)
[96] Fix | Delete
[97] Fix | Delete
[98] Fix | Delete
class Module:
[99] Fix | Delete
[100] Fix | Delete
def __init__(self, name, file=None, path=None):
[101] Fix | Delete
self.__name__ = name
[102] Fix | Delete
self.__file__ = file
[103] Fix | Delete
self.__path__ = path
[104] Fix | Delete
self.__code__ = None
[105] Fix | Delete
# The set of global names that are assigned to in the module.
[106] Fix | Delete
# This includes those names imported through starimports of
[107] Fix | Delete
# Python modules.
[108] Fix | Delete
self.globalnames = {}
[109] Fix | Delete
# The set of starimports this module did that could not be
[110] Fix | Delete
# resolved, ie. a starimport from a non-Python module.
[111] Fix | Delete
self.starimports = {}
[112] Fix | Delete
[113] Fix | Delete
def __repr__(self):
[114] Fix | Delete
s = "Module(%r" % (self.__name__,)
[115] Fix | Delete
if self.__file__ is not None:
[116] Fix | Delete
s = s + ", %r" % (self.__file__,)
[117] Fix | Delete
if self.__path__ is not None:
[118] Fix | Delete
s = s + ", %r" % (self.__path__,)
[119] Fix | Delete
s = s + ")"
[120] Fix | Delete
return s
[121] Fix | Delete
[122] Fix | Delete
class ModuleFinder:
[123] Fix | Delete
[124] Fix | Delete
def __init__(self, path=None, debug=0, excludes=None, replace_paths=None):
[125] Fix | Delete
if path is None:
[126] Fix | Delete
path = sys.path
[127] Fix | Delete
self.path = path
[128] Fix | Delete
self.modules = {}
[129] Fix | Delete
self.badmodules = {}
[130] Fix | Delete
self.debug = debug
[131] Fix | Delete
self.indent = 0
[132] Fix | Delete
self.excludes = excludes if excludes is not None else []
[133] Fix | Delete
self.replace_paths = replace_paths if replace_paths is not None else []
[134] Fix | Delete
self.processed_paths = [] # Used in debugging only
[135] Fix | Delete
[136] Fix | Delete
def msg(self, level, str, *args):
[137] Fix | Delete
if level <= self.debug:
[138] Fix | Delete
for i in range(self.indent):
[139] Fix | Delete
print(" ", end=' ')
[140] Fix | Delete
print(str, end=' ')
[141] Fix | Delete
for arg in args:
[142] Fix | Delete
print(repr(arg), end=' ')
[143] Fix | Delete
print()
[144] Fix | Delete
[145] Fix | Delete
def msgin(self, *args):
[146] Fix | Delete
level = args[0]
[147] Fix | Delete
if level <= self.debug:
[148] Fix | Delete
self.indent = self.indent + 1
[149] Fix | Delete
self.msg(*args)
[150] Fix | Delete
[151] Fix | Delete
def msgout(self, *args):
[152] Fix | Delete
level = args[0]
[153] Fix | Delete
if level <= self.debug:
[154] Fix | Delete
self.indent = self.indent - 1
[155] Fix | Delete
self.msg(*args)
[156] Fix | Delete
[157] Fix | Delete
def run_script(self, pathname):
[158] Fix | Delete
self.msg(2, "run_script", pathname)
[159] Fix | Delete
with io.open_code(pathname) as fp:
[160] Fix | Delete
stuff = ("", "rb", _PY_SOURCE)
[161] Fix | Delete
self.load_module('__main__', fp, pathname, stuff)
[162] Fix | Delete
[163] Fix | Delete
def load_file(self, pathname):
[164] Fix | Delete
dir, name = os.path.split(pathname)
[165] Fix | Delete
name, ext = os.path.splitext(name)
[166] Fix | Delete
with io.open_code(pathname) as fp:
[167] Fix | Delete
stuff = (ext, "rb", _PY_SOURCE)
[168] Fix | Delete
self.load_module(name, fp, pathname, stuff)
[169] Fix | Delete
[170] Fix | Delete
def import_hook(self, name, caller=None, fromlist=None, level=-1):
[171] Fix | Delete
self.msg(3, "import_hook", name, caller, fromlist, level)
[172] Fix | Delete
parent = self.determine_parent(caller, level=level)
[173] Fix | Delete
q, tail = self.find_head_package(parent, name)
[174] Fix | Delete
m = self.load_tail(q, tail)
[175] Fix | Delete
if not fromlist:
[176] Fix | Delete
return q
[177] Fix | Delete
if m.__path__:
[178] Fix | Delete
self.ensure_fromlist(m, fromlist)
[179] Fix | Delete
return None
[180] Fix | Delete
[181] Fix | Delete
def determine_parent(self, caller, level=-1):
[182] Fix | Delete
self.msgin(4, "determine_parent", caller, level)
[183] Fix | Delete
if not caller or level == 0:
[184] Fix | Delete
self.msgout(4, "determine_parent -> None")
[185] Fix | Delete
return None
[186] Fix | Delete
pname = caller.__name__
[187] Fix | Delete
if level >= 1: # relative import
[188] Fix | Delete
if caller.__path__:
[189] Fix | Delete
level -= 1
[190] Fix | Delete
if level == 0:
[191] Fix | Delete
parent = self.modules[pname]
[192] Fix | Delete
assert parent is caller
[193] Fix | Delete
self.msgout(4, "determine_parent ->", parent)
[194] Fix | Delete
return parent
[195] Fix | Delete
if pname.count(".") < level:
[196] Fix | Delete
raise ImportError("relative importpath too deep")
[197] Fix | Delete
pname = ".".join(pname.split(".")[:-level])
[198] Fix | Delete
parent = self.modules[pname]
[199] Fix | Delete
self.msgout(4, "determine_parent ->", parent)
[200] Fix | Delete
return parent
[201] Fix | Delete
if caller.__path__:
[202] Fix | Delete
parent = self.modules[pname]
[203] Fix | Delete
assert caller is parent
[204] Fix | Delete
self.msgout(4, "determine_parent ->", parent)
[205] Fix | Delete
return parent
[206] Fix | Delete
if '.' in pname:
[207] Fix | Delete
i = pname.rfind('.')
[208] Fix | Delete
pname = pname[:i]
[209] Fix | Delete
parent = self.modules[pname]
[210] Fix | Delete
assert parent.__name__ == pname
[211] Fix | Delete
self.msgout(4, "determine_parent ->", parent)
[212] Fix | Delete
return parent
[213] Fix | Delete
self.msgout(4, "determine_parent -> None")
[214] Fix | Delete
return None
[215] Fix | Delete
[216] Fix | Delete
def find_head_package(self, parent, name):
[217] Fix | Delete
self.msgin(4, "find_head_package", parent, name)
[218] Fix | Delete
if '.' in name:
[219] Fix | Delete
i = name.find('.')
[220] Fix | Delete
head = name[:i]
[221] Fix | Delete
tail = name[i+1:]
[222] Fix | Delete
else:
[223] Fix | Delete
head = name
[224] Fix | Delete
tail = ""
[225] Fix | Delete
if parent:
[226] Fix | Delete
qname = "%s.%s" % (parent.__name__, head)
[227] Fix | Delete
else:
[228] Fix | Delete
qname = head
[229] Fix | Delete
q = self.import_module(head, qname, parent)
[230] Fix | Delete
if q:
[231] Fix | Delete
self.msgout(4, "find_head_package ->", (q, tail))
[232] Fix | Delete
return q, tail
[233] Fix | Delete
if parent:
[234] Fix | Delete
qname = head
[235] Fix | Delete
parent = None
[236] Fix | Delete
q = self.import_module(head, qname, parent)
[237] Fix | Delete
if q:
[238] Fix | Delete
self.msgout(4, "find_head_package ->", (q, tail))
[239] Fix | Delete
return q, tail
[240] Fix | Delete
self.msgout(4, "raise ImportError: No module named", qname)
[241] Fix | Delete
raise ImportError("No module named " + qname)
[242] Fix | Delete
[243] Fix | Delete
def load_tail(self, q, tail):
[244] Fix | Delete
self.msgin(4, "load_tail", q, tail)
[245] Fix | Delete
m = q
[246] Fix | Delete
while tail:
[247] Fix | Delete
i = tail.find('.')
[248] Fix | Delete
if i < 0: i = len(tail)
[249] Fix | Delete
head, tail = tail[:i], tail[i+1:]
[250] Fix | Delete
mname = "%s.%s" % (m.__name__, head)
[251] Fix | Delete
m = self.import_module(head, mname, m)
[252] Fix | Delete
if not m:
[253] Fix | Delete
self.msgout(4, "raise ImportError: No module named", mname)
[254] Fix | Delete
raise ImportError("No module named " + mname)
[255] Fix | Delete
self.msgout(4, "load_tail ->", m)
[256] Fix | Delete
return m
[257] Fix | Delete
[258] Fix | Delete
def ensure_fromlist(self, m, fromlist, recursive=0):
[259] Fix | Delete
self.msg(4, "ensure_fromlist", m, fromlist, recursive)
[260] Fix | Delete
for sub in fromlist:
[261] Fix | Delete
if sub == "*":
[262] Fix | Delete
if not recursive:
[263] Fix | Delete
all = self.find_all_submodules(m)
[264] Fix | Delete
if all:
[265] Fix | Delete
self.ensure_fromlist(m, all, 1)
[266] Fix | Delete
elif not hasattr(m, sub):
[267] Fix | Delete
subname = "%s.%s" % (m.__name__, sub)
[268] Fix | Delete
submod = self.import_module(sub, subname, m)
[269] Fix | Delete
if not submod:
[270] Fix | Delete
raise ImportError("No module named " + subname)
[271] Fix | Delete
[272] Fix | Delete
def find_all_submodules(self, m):
[273] Fix | Delete
if not m.__path__:
[274] Fix | Delete
return
[275] Fix | Delete
modules = {}
[276] Fix | Delete
# 'suffixes' used to be a list hardcoded to [".py", ".pyc"].
[277] Fix | Delete
# But we must also collect Python extension modules - although
[278] Fix | Delete
# we cannot separate normal dlls from Python extensions.
[279] Fix | Delete
suffixes = []
[280] Fix | Delete
suffixes += importlib.machinery.EXTENSION_SUFFIXES[:]
[281] Fix | Delete
suffixes += importlib.machinery.SOURCE_SUFFIXES[:]
[282] Fix | Delete
suffixes += importlib.machinery.BYTECODE_SUFFIXES[:]
[283] Fix | Delete
for dir in m.__path__:
[284] Fix | Delete
try:
[285] Fix | Delete
names = os.listdir(dir)
[286] Fix | Delete
except OSError:
[287] Fix | Delete
self.msg(2, "can't list directory", dir)
[288] Fix | Delete
continue
[289] Fix | Delete
for name in names:
[290] Fix | Delete
mod = None
[291] Fix | Delete
for suff in suffixes:
[292] Fix | Delete
n = len(suff)
[293] Fix | Delete
if name[-n:] == suff:
[294] Fix | Delete
mod = name[:-n]
[295] Fix | Delete
break
[296] Fix | Delete
if mod and mod != "__init__":
[297] Fix | Delete
modules[mod] = mod
[298] Fix | Delete
return modules.keys()
[299] Fix | Delete
[300] Fix | Delete
def import_module(self, partname, fqname, parent):
[301] Fix | Delete
self.msgin(3, "import_module", partname, fqname, parent)
[302] Fix | Delete
try:
[303] Fix | Delete
m = self.modules[fqname]
[304] Fix | Delete
except KeyError:
[305] Fix | Delete
pass
[306] Fix | Delete
else:
[307] Fix | Delete
self.msgout(3, "import_module ->", m)
[308] Fix | Delete
return m
[309] Fix | Delete
if fqname in self.badmodules:
[310] Fix | Delete
self.msgout(3, "import_module -> None")
[311] Fix | Delete
return None
[312] Fix | Delete
if parent and parent.__path__ is None:
[313] Fix | Delete
self.msgout(3, "import_module -> None")
[314] Fix | Delete
return None
[315] Fix | Delete
try:
[316] Fix | Delete
fp, pathname, stuff = self.find_module(partname,
[317] Fix | Delete
parent and parent.__path__, parent)
[318] Fix | Delete
except ImportError:
[319] Fix | Delete
self.msgout(3, "import_module ->", None)
[320] Fix | Delete
return None
[321] Fix | Delete
[322] Fix | Delete
try:
[323] Fix | Delete
m = self.load_module(fqname, fp, pathname, stuff)
[324] Fix | Delete
finally:
[325] Fix | Delete
if fp:
[326] Fix | Delete
fp.close()
[327] Fix | Delete
if parent:
[328] Fix | Delete
setattr(parent, partname, m)
[329] Fix | Delete
self.msgout(3, "import_module ->", m)
[330] Fix | Delete
return m
[331] Fix | Delete
[332] Fix | Delete
def load_module(self, fqname, fp, pathname, file_info):
[333] Fix | Delete
suffix, mode, type = file_info
[334] Fix | Delete
self.msgin(2, "load_module", fqname, fp and "fp", pathname)
[335] Fix | Delete
if type == _PKG_DIRECTORY:
[336] Fix | Delete
m = self.load_package(fqname, pathname)
[337] Fix | Delete
self.msgout(2, "load_module ->", m)
[338] Fix | Delete
return m
[339] Fix | Delete
if type == _PY_SOURCE:
[340] Fix | Delete
co = compile(fp.read(), pathname, 'exec')
[341] Fix | Delete
elif type == _PY_COMPILED:
[342] Fix | Delete
try:
[343] Fix | Delete
data = fp.read()
[344] Fix | Delete
importlib._bootstrap_external._classify_pyc(data, fqname, {})
[345] Fix | Delete
except ImportError as exc:
[346] Fix | Delete
self.msgout(2, "raise ImportError: " + str(exc), pathname)
[347] Fix | Delete
raise
[348] Fix | Delete
co = marshal.loads(memoryview(data)[16:])
[349] Fix | Delete
else:
[350] Fix | Delete
co = None
[351] Fix | Delete
m = self.add_module(fqname)
[352] Fix | Delete
m.__file__ = pathname
[353] Fix | Delete
if co:
[354] Fix | Delete
if self.replace_paths:
[355] Fix | Delete
co = self.replace_paths_in_code(co)
[356] Fix | Delete
m.__code__ = co
[357] Fix | Delete
self.scan_code(co, m)
[358] Fix | Delete
self.msgout(2, "load_module ->", m)
[359] Fix | Delete
return m
[360] Fix | Delete
[361] Fix | Delete
def _add_badmodule(self, name, caller):
[362] Fix | Delete
if name not in self.badmodules:
[363] Fix | Delete
self.badmodules[name] = {}
[364] Fix | Delete
if caller:
[365] Fix | Delete
self.badmodules[name][caller.__name__] = 1
[366] Fix | Delete
else:
[367] Fix | Delete
self.badmodules[name]["-"] = 1
[368] Fix | Delete
[369] Fix | Delete
def _safe_import_hook(self, name, caller, fromlist, level=-1):
[370] Fix | Delete
# wrapper for self.import_hook() that won't raise ImportError
[371] Fix | Delete
if name in self.badmodules:
[372] Fix | Delete
self._add_badmodule(name, caller)
[373] Fix | Delete
return
[374] Fix | Delete
try:
[375] Fix | Delete
self.import_hook(name, caller, level=level)
[376] Fix | Delete
except ImportError as msg:
[377] Fix | Delete
self.msg(2, "ImportError:", str(msg))
[378] Fix | Delete
self._add_badmodule(name, caller)
[379] Fix | Delete
except SyntaxError as msg:
[380] Fix | Delete
self.msg(2, "SyntaxError:", str(msg))
[381] Fix | Delete
self._add_badmodule(name, caller)
[382] Fix | Delete
else:
[383] Fix | Delete
if fromlist:
[384] Fix | Delete
for sub in fromlist:
[385] Fix | Delete
fullname = name + "." + sub
[386] Fix | Delete
if fullname in self.badmodules:
[387] Fix | Delete
self._add_badmodule(fullname, caller)
[388] Fix | Delete
continue
[389] Fix | Delete
try:
[390] Fix | Delete
self.import_hook(name, caller, [sub], level=level)
[391] Fix | Delete
except ImportError as msg:
[392] Fix | Delete
self.msg(2, "ImportError:", str(msg))
[393] Fix | Delete
self._add_badmodule(fullname, caller)
[394] Fix | Delete
[395] Fix | Delete
def scan_opcodes(self, co):
[396] Fix | Delete
# Scan the code, and yield 'interesting' opcode combinations
[397] Fix | Delete
code = co.co_code
[398] Fix | Delete
names = co.co_names
[399] Fix | Delete
consts = co.co_consts
[400] Fix | Delete
opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code)
[401] Fix | Delete
if op != EXTENDED_ARG]
[402] Fix | Delete
for i, (op, oparg) in enumerate(opargs):
[403] Fix | Delete
if op in STORE_OPS:
[404] Fix | Delete
yield "store", (names[oparg],)
[405] Fix | Delete
continue
[406] Fix | Delete
if (op == IMPORT_NAME and i >= 2
[407] Fix | Delete
and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST):
[408] Fix | Delete
level = consts[opargs[i-2][1]]
[409] Fix | Delete
fromlist = consts[opargs[i-1][1]]
[410] Fix | Delete
if level == 0: # absolute import
[411] Fix | Delete
yield "absolute_import", (fromlist, names[oparg])
[412] Fix | Delete
else: # relative import
[413] Fix | Delete
yield "relative_import", (level, fromlist, names[oparg])
[414] Fix | Delete
continue
[415] Fix | Delete
[416] Fix | Delete
def scan_code(self, co, m):
[417] Fix | Delete
code = co.co_code
[418] Fix | Delete
scanner = self.scan_opcodes
[419] Fix | Delete
for what, args in scanner(co):
[420] Fix | Delete
if what == "store":
[421] Fix | Delete
name, = args
[422] Fix | Delete
m.globalnames[name] = 1
[423] Fix | Delete
elif what == "absolute_import":
[424] Fix | Delete
fromlist, name = args
[425] Fix | Delete
have_star = 0
[426] Fix | Delete
if fromlist is not None:
[427] Fix | Delete
if "*" in fromlist:
[428] Fix | Delete
have_star = 1
[429] Fix | Delete
fromlist = [f for f in fromlist if f != "*"]
[430] Fix | Delete
self._safe_import_hook(name, m, fromlist, level=0)
[431] Fix | Delete
if have_star:
[432] Fix | Delete
# We've encountered an "import *". If it is a Python module,
[433] Fix | Delete
# the code has already been parsed and we can suck out the
[434] Fix | Delete
# global names.
[435] Fix | Delete
mm = None
[436] Fix | Delete
if m.__path__:
[437] Fix | Delete
# At this point we don't know whether 'name' is a
[438] Fix | Delete
# submodule of 'm' or a global module. Let's just try
[439] Fix | Delete
# the full name first.
[440] Fix | Delete
mm = self.modules.get(m.__name__ + "." + name)
[441] Fix | Delete
if mm is None:
[442] Fix | Delete
mm = self.modules.get(name)
[443] Fix | Delete
if mm is not None:
[444] Fix | Delete
m.globalnames.update(mm.globalnames)
[445] Fix | Delete
m.starimports.update(mm.starimports)
[446] Fix | Delete
if mm.__code__ is None:
[447] Fix | Delete
m.starimports[name] = 1
[448] Fix | Delete
else:
[449] Fix | Delete
m.starimports[name] = 1
[450] Fix | Delete
elif what == "relative_import":
[451] Fix | Delete
level, fromlist, name = args
[452] Fix | Delete
if name:
[453] Fix | Delete
self._safe_import_hook(name, m, fromlist, level=level)
[454] Fix | Delete
else:
[455] Fix | Delete
parent = self.determine_parent(m, level=level)
[456] Fix | Delete
self._safe_import_hook(parent.__name__, None, fromlist, level=0)
[457] Fix | Delete
else:
[458] Fix | Delete
# We don't expect anything else from the generator.
[459] Fix | Delete
raise RuntimeError(what)
[460] Fix | Delete
[461] Fix | Delete
for c in co.co_consts:
[462] Fix | Delete
if isinstance(c, type(co)):
[463] Fix | Delete
self.scan_code(c, m)
[464] Fix | Delete
[465] Fix | Delete
def load_package(self, fqname, pathname):
[466] Fix | Delete
self.msgin(2, "load_package", fqname, pathname)
[467] Fix | Delete
newname = replacePackageMap.get(fqname)
[468] Fix | Delete
if newname:
[469] Fix | Delete
fqname = newname
[470] Fix | Delete
m = self.add_module(fqname)
[471] Fix | Delete
m.__file__ = pathname
[472] Fix | Delete
m.__path__ = [pathname]
[473] Fix | Delete
[474] Fix | Delete
# As per comment at top of file, simulate runtime __path__ additions.
[475] Fix | Delete
m.__path__ = m.__path__ + packagePathMap.get(fqname, [])
[476] Fix | Delete
[477] Fix | Delete
fp, buf, stuff = self.find_module("__init__", m.__path__)
[478] Fix | Delete
try:
[479] Fix | Delete
self.load_module(fqname, fp, buf, stuff)
[480] Fix | Delete
self.msgout(2, "load_package ->", m)
[481] Fix | Delete
return m
[482] Fix | Delete
finally:
[483] Fix | Delete
if fp:
[484] Fix | Delete
fp.close()
[485] Fix | Delete
[486] Fix | Delete
def add_module(self, fqname):
[487] Fix | Delete
if fqname in self.modules:
[488] Fix | Delete
return self.modules[fqname]
[489] Fix | Delete
self.modules[fqname] = m = Module(fqname)
[490] Fix | Delete
return m
[491] Fix | Delete
[492] Fix | Delete
def find_module(self, name, path, parent=None):
[493] Fix | Delete
if parent is not None:
[494] Fix | Delete
# assert path is not None
[495] Fix | Delete
fullname = parent.__name__+'.'+name
[496] Fix | Delete
else:
[497] Fix | Delete
fullname = name
[498] Fix | Delete
if fullname in self.excludes:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function