diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-03-18 21:58:43 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-03-18 21:58:43 (GMT) |
commit | 32ca4547a4557428c3232eb3abe4a36a66546d55 (patch) | |
tree | 92b91ed7b93939804f3ea44f1fd84188b52ed1e6 /Lib | |
parent | cb6dbe579003e313e66a5a2aeb5c1ce43028dc34 (diff) | |
download | cpython-32ca4547a4557428c3232eb3abe4a36a66546d55.zip cpython-32ca4547a4557428c3232eb3abe4a36a66546d55.tar.gz cpython-32ca4547a4557428c3232eb3abe4a36a66546d55.tar.bz2 |
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
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/py_compile.py | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index cce5ac1..10af1bb 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -62,15 +62,6 @@ class PyCompileError(Exception): return self.msg -# Define an internal helper according to the platform -if os.name == "mac": - import MacOS - def set_creator_type(file): - MacOS.SetCreatorAndType(file, 'Pyth', 'PYC ') -else: - def set_creator_type(file): - pass - def wr_long(f, x): """Internal; write a 32-bit int to a file in little-endian order.""" f.write(bytes([x & 0xff, @@ -129,13 +120,12 @@ def compile(file, cfile=None, dfile=None, doraise=False): """ encoding = read_encoding(file, "utf-8") - f = open(file, 'U', encoding=encoding) - try: - timestamp = int(os.fstat(f.fileno()).st_mtime) - except AttributeError: - timestamp = int(os.stat(file).st_mtime) - codestring = f.read() - f.close() + with open(file, encoding=encoding) as f: + try: + timestamp = int(os.fstat(f.fileno()).st_mtime) + except AttributeError: + timestamp = int(os.stat(file).st_mtime) + codestring = f.read() if codestring and codestring[-1] != '\n': codestring = codestring + '\n' try: @@ -149,15 +139,13 @@ def compile(file, cfile=None, dfile=None, doraise=False): return if cfile is None: cfile = file + (__debug__ and 'c' or 'o') - fc = open(cfile, 'wb') - fc.write(b'\0\0\0\0') - wr_long(fc, timestamp) - marshal.dump(codeobject, fc) - fc.flush() - fc.seek(0, 0) - fc.write(MAGIC) - fc.close() - set_creator_type(cfile) + with open(cfile, 'wb') as fc: + fc.write(b'\0\0\0\0') + wr_long(fc, timestamp) + marshal.dump(codeobject, fc) + fc.flush() + fc.seek(0, 0) + fc.write(MAGIC) def main(args=None): """Compile several source files. |