mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
clean up files correctly
This commit is contained in:
parent
5a4c0f5cc2
commit
f56813997f
1 changed files with 13 additions and 15 deletions
|
@ -103,13 +103,12 @@ def compile(file, cfile=None, dfile=None, doraise=False):
|
||||||
directories).
|
directories).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
f = open(file, 'U')
|
with open(file, 'U') as f:
|
||||||
try:
|
try:
|
||||||
timestamp = long(os.fstat(f.fileno()).st_mtime)
|
timestamp = long(os.fstat(f.fileno()).st_mtime)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
timestamp = long(os.stat(file).st_mtime)
|
timestamp = long(os.stat(file).st_mtime)
|
||||||
codestring = f.read()
|
codestring = f.read()
|
||||||
f.close()
|
|
||||||
if codestring and codestring[-1] != '\n':
|
if codestring and codestring[-1] != '\n':
|
||||||
codestring = codestring + '\n'
|
codestring = codestring + '\n'
|
||||||
try:
|
try:
|
||||||
|
@ -123,14 +122,13 @@ def compile(file, cfile=None, dfile=None, doraise=False):
|
||||||
return
|
return
|
||||||
if cfile is None:
|
if cfile is None:
|
||||||
cfile = file + (__debug__ and 'c' or 'o')
|
cfile = file + (__debug__ and 'c' or 'o')
|
||||||
fc = open(cfile, 'wb')
|
with open(cfile, 'wb') as fc:
|
||||||
fc.write('\0\0\0\0')
|
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.flush()
|
||||||
fc.seek(0, 0)
|
fc.seek(0, 0)
|
||||||
fc.write(MAGIC)
|
fc.write(MAGIC)
|
||||||
fc.close()
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
"""Compile several source files.
|
"""Compile several source files.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue