Skip to content

Commit 32ca454

Browse files
committed
Merged revisions 78971-78972 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78971 | benjamin.peterson | 2010-03-14 22:00:35 -0500 (Sun, 14 Mar 2010) | 1 line remove mac 9 code ........ r78972 | benjamin.peterson | 2010-03-14 22:02:37 -0500 (Sun, 14 Mar 2010) | 1 line clean up files correctly ........
1 parent cb6dbe5 commit 32ca454

1 file changed

Lines changed: 13 additions & 25 deletions

File tree

Lib/py_compile.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ def __str__(self):
6262
return self.msg
6363

6464

65-
# Define an internal helper according to the platform
66-
if os.name == "mac":
67-
import MacOS
68-
def set_creator_type(file):
69-
MacOS.SetCreatorAndType(file, 'Pyth', 'PYC ')
70-
else:
71-
def set_creator_type(file):
72-
pass
73-
7465
def wr_long(f, x):
7566
"""Internal; write a 32-bit int to a file in little-endian order."""
7667
f.write(bytes([x & 0xff,
@@ -129,13 +120,12 @@ def compile(file, cfile=None, dfile=None, doraise=False):
129120
130121
"""
131122
encoding = read_encoding(file, "utf-8")
132-
f = open(file, 'U', encoding=encoding)
133-
try:
134-
timestamp = int(os.fstat(f.fileno()).st_mtime)
135-
except AttributeError:
136-
timestamp = int(os.stat(file).st_mtime)
137-
codestring = f.read()
138-
f.close()
123+
with open(file, encoding=encoding) as f:
124+
try:
125+
timestamp = int(os.fstat(f.fileno()).st_mtime)
126+
except AttributeError:
127+
timestamp = int(os.stat(file).st_mtime)
128+
codestring = f.read()
139129
if codestring and codestring[-1] != '\n':
140130
codestring = codestring + '\n'
141131
try:
@@ -149,15 +139,13 @@ def compile(file, cfile=None, dfile=None, doraise=False):
149139
return
150140
if cfile is None:
151141
cfile = file + (__debug__ and 'c' or 'o')
152-
fc = open(cfile, 'wb')
153-
fc.write(b'\0\0\0\0')
154-
wr_long(fc, timestamp)
155-
marshal.dump(codeobject, fc)
156-
fc.flush()
157-
fc.seek(0, 0)
158-
fc.write(MAGIC)
159-
fc.close()
160-
set_creator_type(cfile)
142+
with open(cfile, 'wb') as fc:
143+
fc.write(b'\0\0\0\0')
144+
wr_long(fc, timestamp)
145+
marshal.dump(codeobject, fc)
146+
fc.flush()
147+
fc.seek(0, 0)
148+
fc.write(MAGIC)
161149

162150
def main(args=None):
163151
"""Compile several source files.

0 commit comments

Comments
 (0)