def _getpycodeobj(self): |
""" read the path and compile it to a code object. """ |
dotpy = self.check(ext='.py') |
if dotpy: |
my_magic = py.std.imp.get_magic() |
my_timestamp = int(self.mtime()) |
if __debug__: |
-> pycfile = self + 'c' |
else: |
pycfile = self + 'o' |
try: |
f = pycfile.open('rb') |
try: |
header = f.read(8) |
if len(header) == 8: |
magic, timestamp = py.std.struct.unpack('<4si', header) |
if magic == my_magic and timestamp == my_timestamp: |
co = py.std.marshal.load(f) |
path1 = co.co_filename |
path2 = str(self) |
if path1 == path2: |
return co |
try: |
if os.path.samefile(path1, path2): |
return co |
except (OSError, |
AttributeError): |
pass |
finally: |
f.close() |
except py.error.Error: |
pass |
s = self.read(mode='rU') + '\n' |
codeobj = compile(s, str(self), 'exec', generators.compiler_flag) |
if dotpy: |
try: |
f = pycfile.open('wb') |
f.write(py.std.struct.pack('<4si', 'TEMP', -1)) |
py.std.marshal.dump(codeobj, f) |
f.flush() |
f.seek(0) |
f.write(py.std.struct.pack('<4si', my_magic, my_timestamp)) |
f.close() |
except py.error.Error: |
pass |
return codeobj |