Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: modulefinder.py
tell which names are imported when "from module import *" is done
[500] Fix | Delete
with an extension module, short of actually importing it.
[501] Fix | Delete
"""
[502] Fix | Delete
missing = []
[503] Fix | Delete
maybe = []
[504] Fix | Delete
for name in self.badmodules:
[505] Fix | Delete
if name in self.excludes:
[506] Fix | Delete
continue
[507] Fix | Delete
i = name.rfind(".")
[508] Fix | Delete
if i < 0:
[509] Fix | Delete
missing.append(name)
[510] Fix | Delete
continue
[511] Fix | Delete
subname = name[i+1:]
[512] Fix | Delete
pkgname = name[:i]
[513] Fix | Delete
pkg = self.modules.get(pkgname)
[514] Fix | Delete
if pkg is not None:
[515] Fix | Delete
if pkgname in self.badmodules[name]:
[516] Fix | Delete
# The package tried to import this module itself and
[517] Fix | Delete
# failed. It's definitely missing.
[518] Fix | Delete
missing.append(name)
[519] Fix | Delete
elif subname in pkg.globalnames:
[520] Fix | Delete
# It's a global in the package: definitely not missing.
[521] Fix | Delete
pass
[522] Fix | Delete
elif pkg.starimports:
[523] Fix | Delete
# It could be missing, but the package did an "import *"
[524] Fix | Delete
# from a non-Python module, so we simply can't be sure.
[525] Fix | Delete
maybe.append(name)
[526] Fix | Delete
else:
[527] Fix | Delete
# It's not a global in the package, the package didn't
[528] Fix | Delete
# do funny star imports, it's very likely to be missing.
[529] Fix | Delete
# The symbol could be inserted into the package from the
[530] Fix | Delete
# outside, but since that's not good style we simply list
[531] Fix | Delete
# it missing.
[532] Fix | Delete
missing.append(name)
[533] Fix | Delete
else:
[534] Fix | Delete
missing.append(name)
[535] Fix | Delete
missing.sort()
[536] Fix | Delete
maybe.sort()
[537] Fix | Delete
return missing, maybe
[538] Fix | Delete
[539] Fix | Delete
def replace_paths_in_code(self, co):
[540] Fix | Delete
new_filename = original_filename = os.path.normpath(co.co_filename)
[541] Fix | Delete
for f, r in self.replace_paths:
[542] Fix | Delete
if original_filename.startswith(f):
[543] Fix | Delete
new_filename = r + original_filename[len(f):]
[544] Fix | Delete
break
[545] Fix | Delete
[546] Fix | Delete
if self.debug and original_filename not in self.processed_paths:
[547] Fix | Delete
if new_filename != original_filename:
[548] Fix | Delete
self.msgout(2, "co_filename %r changed to %r" \
[549] Fix | Delete
% (original_filename,new_filename,))
[550] Fix | Delete
else:
[551] Fix | Delete
self.msgout(2, "co_filename %r remains unchanged" \
[552] Fix | Delete
% (original_filename,))
[553] Fix | Delete
self.processed_paths.append(original_filename)
[554] Fix | Delete
[555] Fix | Delete
consts = list(co.co_consts)
[556] Fix | Delete
for i in range(len(consts)):
[557] Fix | Delete
if isinstance(consts[i], type(co)):
[558] Fix | Delete
consts[i] = self.replace_paths_in_code(consts[i])
[559] Fix | Delete
[560] Fix | Delete
return types.CodeType(co.co_argcount, co.co_kwonlyargcount,
[561] Fix | Delete
co.co_nlocals, co.co_stacksize, co.co_flags,
[562] Fix | Delete
co.co_code, tuple(consts), co.co_names,
[563] Fix | Delete
co.co_varnames, new_filename, co.co_name,
[564] Fix | Delete
co.co_firstlineno, co.co_lnotab, co.co_freevars,
[565] Fix | Delete
co.co_cellvars)
[566] Fix | Delete
[567] Fix | Delete
[568] Fix | Delete
def test():
[569] Fix | Delete
# Parse command line
[570] Fix | Delete
import getopt
[571] Fix | Delete
try:
[572] Fix | Delete
opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:")
[573] Fix | Delete
except getopt.error as msg:
[574] Fix | Delete
print(msg)
[575] Fix | Delete
return
[576] Fix | Delete
[577] Fix | Delete
# Process options
[578] Fix | Delete
debug = 1
[579] Fix | Delete
domods = 0
[580] Fix | Delete
addpath = []
[581] Fix | Delete
exclude = []
[582] Fix | Delete
for o, a in opts:
[583] Fix | Delete
if o == '-d':
[584] Fix | Delete
debug = debug + 1
[585] Fix | Delete
if o == '-m':
[586] Fix | Delete
domods = 1
[587] Fix | Delete
if o == '-p':
[588] Fix | Delete
addpath = addpath + a.split(os.pathsep)
[589] Fix | Delete
if o == '-q':
[590] Fix | Delete
debug = 0
[591] Fix | Delete
if o == '-x':
[592] Fix | Delete
exclude.append(a)
[593] Fix | Delete
[594] Fix | Delete
# Provide default arguments
[595] Fix | Delete
if not args:
[596] Fix | Delete
script = "hello.py"
[597] Fix | Delete
else:
[598] Fix | Delete
script = args[0]
[599] Fix | Delete
[600] Fix | Delete
# Set the path based on sys.path and the script directory
[601] Fix | Delete
path = sys.path[:]
[602] Fix | Delete
path[0] = os.path.dirname(script)
[603] Fix | Delete
path = addpath + path
[604] Fix | Delete
if debug > 1:
[605] Fix | Delete
print("path:")
[606] Fix | Delete
for item in path:
[607] Fix | Delete
print(" ", repr(item))
[608] Fix | Delete
[609] Fix | Delete
# Create the module finder and turn its crank
[610] Fix | Delete
mf = ModuleFinder(path, debug, exclude)
[611] Fix | Delete
for arg in args[1:]:
[612] Fix | Delete
if arg == '-m':
[613] Fix | Delete
domods = 1
[614] Fix | Delete
continue
[615] Fix | Delete
if domods:
[616] Fix | Delete
if arg[-2:] == '.*':
[617] Fix | Delete
mf.import_hook(arg[:-2], None, ["*"])
[618] Fix | Delete
else:
[619] Fix | Delete
mf.import_hook(arg)
[620] Fix | Delete
else:
[621] Fix | Delete
mf.load_file(arg)
[622] Fix | Delete
mf.run_script(script)
[623] Fix | Delete
mf.report()
[624] Fix | Delete
return mf # for -i debugging
[625] Fix | Delete
[626] Fix | Delete
[627] Fix | Delete
if __name__ == '__main__':
[628] Fix | Delete
try:
[629] Fix | Delete
mf = test()
[630] Fix | Delete
except KeyboardInterrupt:
[631] Fix | Delete
print("\n[interrupted]")
[632] Fix | Delete
[633] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function