/usr/share/pyshared/guppy/etc/ExecfileWithModuleInfo.py is in python-guppy 0.1.9-2ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #._cv_part guppy.etc.ExecfileWithModuleInfo
import sys, os, imp, md5
_VERBOSE = True
_RELOAD_ALWAYS = True # False
_MAGIC = '#._cv_part'
modsums = {}
def pyname(m):
fname = m.__file__
if not fname.endswith('.py'):
se = os.path.splitext(fname)
fname = se[0]+'.py'
return fname
def calc_stringsum(s):
return md5.md5(s).digest()
def calc_modsum(m):
return calc_stringsum(open(pyname(m)).read())
def execfile(filename, globs=None, locs=None):
if globs==None:
# Do this in an interior frame to not change caller's sys.exc_info()
def get_globs():
try:
1/0
except:
try:
typ, val, trb = sys.exc_info()
frame = trb.tb_frame.f_back.f_back
globs = frame.f_globals
finally:
del typ,val,trb
return globs
globs = get_globs()
file = open(filename)
text = file.read()
file.close()
if text.startswith(_MAGIC):
ix = len(_MAGIC)
else:
ix = text.find('\n'+_MAGIC)
if ix == -1:
code = compile(text, filename, 'exec')
exec code in globs, locs
return
ix = ix + len(_MAGIC) + 1
eix = text.find('\n', ix)
name = text[ix:eix]
name=name.strip()
m = sys.modules.get(name)
if m is None:
if _VERBOSE:
print '%s.execfile: importing'%__name__, name
__import__(name, globs, locs, [])
m = sys.modules[name]
msum = calc_modsum(m)
modsums[m.__name__] = msum
tsum = calc_stringsum(text)
else:
msum = modsums.get(m.__name__)
if msum != calc_modsum(m):
msum = ''
tsum = calc_stringsum(text)
if _RELOAD_ALWAYS or msum != tsum:
if _VERBOSE:
print '%s.execfile: reloading'%__name__, name
fname = pyname(m)
code = compile(text, fname, 'exec')
exec code in m.__dict__
modsums[m.__name__] = tsum
|