mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
Use fstat if we can; write MAGIC into file last.
This commit is contained in:
parent
8700fe62f8
commit
e6c128f428
1 changed files with 8 additions and 2 deletions
|
@ -14,16 +14,22 @@ def wr_long(f, x):
|
||||||
def compile(file, cfile = None):
|
def compile(file, cfile = None):
|
||||||
import os, marshal, __builtin__
|
import os, marshal, __builtin__
|
||||||
f = open(file)
|
f = open(file)
|
||||||
|
try:
|
||||||
|
timestamp = os.fstat(file.fileno())
|
||||||
|
except AttributeError:
|
||||||
|
timestamp = long(os.stat(file)[8])
|
||||||
codestring = f.read()
|
codestring = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
timestamp = long(os.stat(file)[8])
|
|
||||||
codeobject = __builtin__.compile(codestring, file, 'exec')
|
codeobject = __builtin__.compile(codestring, file, 'exec')
|
||||||
if not cfile:
|
if not cfile:
|
||||||
cfile = file + (__debug__ and 'c' or 'o')
|
cfile = file + (__debug__ and 'c' or 'o')
|
||||||
fc = open(cfile, 'wb')
|
fc = open(cfile, 'wb')
|
||||||
fc.write(MAGIC)
|
fc.write('\0\0\0\0')
|
||||||
wr_long(fc, timestamp)
|
wr_long(fc, timestamp)
|
||||||
marshal.dump(codeobject, fc)
|
marshal.dump(codeobject, fc)
|
||||||
|
fc.flush()
|
||||||
|
fc.seek(0, 0)
|
||||||
|
fc.write(MAGIC)
|
||||||
fc.close()
|
fc.close()
|
||||||
if os.name == 'mac':
|
if os.name == 'mac':
|
||||||
import macfs
|
import macfs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue