[Python-checkins] python/dist/src/Lib py_compile.py,1.21,1.22
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
Wed, 21 Aug 2002 13:23:25 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv3978
Modified Files:
py_compile.py
Log Message:
Refactor: Remove some code that was obsoleted when this module was
changed to use universal newlines.
Remove all imports from the compile() function; these are
now done at the top of the module ("Python normal form"),
and define a helper based on the platform instead of
testing the platform in the compile() function.
Index: py_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/py_compile.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** py_compile.py 1 Jun 2002 19:51:15 -0000 1.21
--- py_compile.py 21 Aug 2002 20:23:22 -0000 1.22
***************
*** 4,12 ****
--- 4,27 ----
"""
+ import __builtin__
import imp
+ import marshal
+ import os
+ import sys
+ import traceback
+
MAGIC = imp.get_magic()
__all__ = ["compile"]
+ # Define an internal helper according to the platform
+ if os.name == "mac":
+ import macfs
+ def set_creator_type(file):
+ macfs.FSSpec(file).SetCreatorType('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."""
***************
*** 44,48 ****
"""
- import os, marshal, __builtin__
f = open(file, 'U')
try:
--- 59,62 ----
***************
*** 51,59 ****
timestamp = long(os.stat(file).st_mtime)
codestring = f.read()
- # If parsing from a string, line breaks are \n (see parsetok.c:tok_nextc)
- # Replace will return original string if pattern is not found, so
- # we don't need to check whether it is found first.
- codestring = codestring.replace("\r\n","\n")
- codestring = codestring.replace("\r","\n")
f.close()
if codestring and codestring[-1] != '\n':
--- 65,68 ----
***************
*** 62,70 ****
codeobject = __builtin__.compile(codestring, dfile or file, 'exec')
except SyntaxError, detail:
- import traceback, sys
lines = traceback.format_exception_only(SyntaxError, detail)
for line in lines:
sys.stderr.write(line.replace('File "<string>"',
! 'File "%s"' % (dfile or file)))
return
if cfile is None:
--- 71,78 ----
codeobject = __builtin__.compile(codestring, dfile or file, 'exec')
except SyntaxError, detail:
lines = traceback.format_exception_only(SyntaxError, detail)
for line in lines:
sys.stderr.write(line.replace('File "<string>"',
! 'File "%s"' % (dfile or file)))
return
if cfile is None:
***************
*** 78,82 ****
fc.write(MAGIC)
fc.close()
! if os.name == 'mac':
! import macfs
! macfs.FSSpec(cfile).SetCreatorType('Pyth', 'PYC ')
--- 86,88 ----
fc.write(MAGIC)
fc.close()
! set_creator_type(cfile)