Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: modulefinder.py
self.msgout(3, "find_module -> Excluded", fullname)
[500] Fix | Delete
raise ImportError(name)
[501] Fix | Delete
[502] Fix | Delete
if path is None:
[503] Fix | Delete
if name in sys.builtin_module_names:
[504] Fix | Delete
return (None, None, ("", "", _C_BUILTIN))
[505] Fix | Delete
[506] Fix | Delete
path = self.path
[507] Fix | Delete
[508] Fix | Delete
return _find_module(name, path)
[509] Fix | Delete
[510] Fix | Delete
def report(self):
[511] Fix | Delete
"""Print a report to stdout, listing the found modules with their
[512] Fix | Delete
paths, as well as modules that are missing, or seem to be missing.
[513] Fix | Delete
"""
[514] Fix | Delete
print()
[515] Fix | Delete
print(" %-25s %s" % ("Name", "File"))
[516] Fix | Delete
print(" %-25s %s" % ("----", "----"))
[517] Fix | Delete
# Print modules found
[518] Fix | Delete
keys = sorted(self.modules.keys())
[519] Fix | Delete
for key in keys:
[520] Fix | Delete
m = self.modules[key]
[521] Fix | Delete
if m.__path__:
[522] Fix | Delete
print("P", end=' ')
[523] Fix | Delete
else:
[524] Fix | Delete
print("m", end=' ')
[525] Fix | Delete
print("%-25s" % key, m.__file__ or "")
[526] Fix | Delete
[527] Fix | Delete
# Print missing modules
[528] Fix | Delete
missing, maybe = self.any_missing_maybe()
[529] Fix | Delete
if missing:
[530] Fix | Delete
print()
[531] Fix | Delete
print("Missing modules:")
[532] Fix | Delete
for name in missing:
[533] Fix | Delete
mods = sorted(self.badmodules[name].keys())
[534] Fix | Delete
print("?", name, "imported from", ', '.join(mods))
[535] Fix | Delete
# Print modules that may be missing, but then again, maybe not...
[536] Fix | Delete
if maybe:
[537] Fix | Delete
print()
[538] Fix | Delete
print("Submodules that appear to be missing, but could also be", end=' ')
[539] Fix | Delete
print("global names in the parent package:")
[540] Fix | Delete
for name in maybe:
[541] Fix | Delete
mods = sorted(self.badmodules[name].keys())
[542] Fix | Delete
print("?", name, "imported from", ', '.join(mods))
[543] Fix | Delete
[544] Fix | Delete
def any_missing(self):
[545] Fix | Delete
"""Return a list of modules that appear to be missing. Use
[546] Fix | Delete
any_missing_maybe() if you want to know which modules are
[547] Fix | Delete
certain to be missing, and which *may* be missing.
[548] Fix | Delete
"""
[549] Fix | Delete
missing, maybe = self.any_missing_maybe()
[550] Fix | Delete
return missing + maybe
[551] Fix | Delete
[552] Fix | Delete
def any_missing_maybe(self):
[553] Fix | Delete
"""Return two lists, one with modules that are certainly missing
[554] Fix | Delete
and one with modules that *may* be missing. The latter names could
[555] Fix | Delete
either be submodules *or* just global names in the package.
[556] Fix | Delete
[557] Fix | Delete
The reason it can't always be determined is that it's impossible to
[558] Fix | Delete
tell which names are imported when "from module import *" is done
[559] Fix | Delete
with an extension module, short of actually importing it.
[560] Fix | Delete
"""
[561] Fix | Delete
missing = []
[562] Fix | Delete
maybe = []
[563] Fix | Delete
for name in self.badmodules:
[564] Fix | Delete
if name in self.excludes:
[565] Fix | Delete
continue
[566] Fix | Delete
i = name.rfind(".")
[567] Fix | Delete
if i < 0:
[568] Fix | Delete
missing.append(name)
[569] Fix | Delete
continue
[570] Fix | Delete
subname = name[i+1:]
[571] Fix | Delete
pkgname = name[:i]
[572] Fix | Delete
pkg = self.modules.get(pkgname)
[573] Fix | Delete
if pkg is not None:
[574] Fix | Delete
if pkgname in self.badmodules[name]:
[575] Fix | Delete
# The package tried to import this module itself and
[576] Fix | Delete
# failed. It's definitely missing.
[577] Fix | Delete
missing.append(name)
[578] Fix | Delete
elif subname in pkg.globalnames:
[579] Fix | Delete
# It's a global in the package: definitely not missing.
[580] Fix | Delete
pass
[581] Fix | Delete
elif pkg.starimports:
[582] Fix | Delete
# It could be missing, but the package did an "import *"
[583] Fix | Delete
# from a non-Python module, so we simply can't be sure.
[584] Fix | Delete
maybe.append(name)
[585] Fix | Delete
else:
[586] Fix | Delete
# It's not a global in the package, the package didn't
[587] Fix | Delete
# do funny star imports, it's very likely to be missing.
[588] Fix | Delete
# The symbol could be inserted into the package from the
[589] Fix | Delete
# outside, but since that's not good style we simply list
[590] Fix | Delete
# it missing.
[591] Fix | Delete
missing.append(name)
[592] Fix | Delete
else:
[593] Fix | Delete
missing.append(name)
[594] Fix | Delete
missing.sort()
[595] Fix | Delete
maybe.sort()
[596] Fix | Delete
return missing, maybe
[597] Fix | Delete
[598] Fix | Delete
def replace_paths_in_code(self, co):
[599] Fix | Delete
new_filename = original_filename = os.path.normpath(co.co_filename)
[600] Fix | Delete
for f, r in self.replace_paths:
[601] Fix | Delete
if original_filename.startswith(f):
[602] Fix | Delete
new_filename = r + original_filename[len(f):]
[603] Fix | Delete
break
[604] Fix | Delete
[605] Fix | Delete
if self.debug and original_filename not in self.processed_paths:
[606] Fix | Delete
if new_filename != original_filename:
[607] Fix | Delete
self.msgout(2, "co_filename %r changed to %r" \
[608] Fix | Delete
% (original_filename,new_filename,))
[609] Fix | Delete
else:
[610] Fix | Delete
self.msgout(2, "co_filename %r remains unchanged" \
[611] Fix | Delete
% (original_filename,))
[612] Fix | Delete
self.processed_paths.append(original_filename)
[613] Fix | Delete
[614] Fix | Delete
consts = list(co.co_consts)
[615] Fix | Delete
for i in range(len(consts)):
[616] Fix | Delete
if isinstance(consts[i], type(co)):
[617] Fix | Delete
consts[i] = self.replace_paths_in_code(consts[i])
[618] Fix | Delete
[619] Fix | Delete
return co.replace(co_consts=tuple(consts), co_filename=new_filename)
[620] Fix | Delete
[621] Fix | Delete
[622] Fix | Delete
def test():
[623] Fix | Delete
# Parse command line
[624] Fix | Delete
import getopt
[625] Fix | Delete
try:
[626] Fix | Delete
opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:")
[627] Fix | Delete
except getopt.error as msg:
[628] Fix | Delete
print(msg)
[629] Fix | Delete
return
[630] Fix | Delete
[631] Fix | Delete
# Process options
[632] Fix | Delete
debug = 1
[633] Fix | Delete
domods = 0
[634] Fix | Delete
addpath = []
[635] Fix | Delete
exclude = []
[636] Fix | Delete
for o, a in opts:
[637] Fix | Delete
if o == '-d':
[638] Fix | Delete
debug = debug + 1
[639] Fix | Delete
if o == '-m':
[640] Fix | Delete
domods = 1
[641] Fix | Delete
if o == '-p':
[642] Fix | Delete
addpath = addpath + a.split(os.pathsep)
[643] Fix | Delete
if o == '-q':
[644] Fix | Delete
debug = 0
[645] Fix | Delete
if o == '-x':
[646] Fix | Delete
exclude.append(a)
[647] Fix | Delete
[648] Fix | Delete
# Provide default arguments
[649] Fix | Delete
if not args:
[650] Fix | Delete
script = "hello.py"
[651] Fix | Delete
else:
[652] Fix | Delete
script = args[0]
[653] Fix | Delete
[654] Fix | Delete
# Set the path based on sys.path and the script directory
[655] Fix | Delete
path = sys.path[:]
[656] Fix | Delete
path[0] = os.path.dirname(script)
[657] Fix | Delete
path = addpath + path
[658] Fix | Delete
if debug > 1:
[659] Fix | Delete
print("path:")
[660] Fix | Delete
for item in path:
[661] Fix | Delete
print(" ", repr(item))
[662] Fix | Delete
[663] Fix | Delete
# Create the module finder and turn its crank
[664] Fix | Delete
mf = ModuleFinder(path, debug, exclude)
[665] Fix | Delete
for arg in args[1:]:
[666] Fix | Delete
if arg == '-m':
[667] Fix | Delete
domods = 1
[668] Fix | Delete
continue
[669] Fix | Delete
if domods:
[670] Fix | Delete
if arg[-2:] == '.*':
[671] Fix | Delete
mf.import_hook(arg[:-2], None, ["*"])
[672] Fix | Delete
else:
[673] Fix | Delete
mf.import_hook(arg)
[674] Fix | Delete
else:
[675] Fix | Delete
mf.load_file(arg)
[676] Fix | Delete
mf.run_script(script)
[677] Fix | Delete
mf.report()
[678] Fix | Delete
return mf # for -i debugging
[679] Fix | Delete
[680] Fix | Delete
[681] Fix | Delete
if __name__ == '__main__':
[682] Fix | Delete
try:
[683] Fix | Delete
mf = test()
[684] Fix | Delete
except KeyboardInterrupt:
[685] Fix | Delete
print("\n[interrupted]")
[686] Fix | Delete
[687] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function