diff options
author | Guido van Rossum <guido@python.org> | 1997-11-22 21:48:26 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-11-22 21:48:26 (GMT) |
commit | e6c128f428de3e6cb44549983644fa610082cb52 (patch) | |
tree | e98a26cdec49b48fbe95c730402f687efb2568e6 | |
parent | 8700fe62f808b0634d75ec43f89f83809616ffca (diff) | |
download | cpython-e6c128f428de3e6cb44549983644fa610082cb52.zip cpython-e6c128f428de3e6cb44549983644fa610082cb52.tar.gz cpython-e6c128f428de3e6cb44549983644fa610082cb52.tar.bz2 |
Use fstat if we can; write MAGIC into file last.
-rw-r--r-- | Lib/py_compile.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index e9e90ff..1adc3a2 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -14,16 +14,22 @@ def wr_long(f, x): def compile(file, cfile = None): import os, marshal, __builtin__ f = open(file) + try: + timestamp = os.fstat(file.fileno()) + except AttributeError: + timestamp = long(os.stat(file)[8]) codestring = f.read() f.close() - timestamp = long(os.stat(file)[8]) codeobject = __builtin__.compile(codestring, file, 'exec') if not cfile: cfile = file + (__debug__ and 'c' or 'o') fc = open(cfile, 'wb') - fc.write(MAGIC) + fc.write('\0\0\0\0') wr_long(fc, timestamp) marshal.dump(codeobject, fc) + fc.flush() + fc.seek(0, 0) + fc.write(MAGIC) fc.close() if os.name == 'mac': import macfs |