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