Changeset 391 for python/trunk/Lib/py_compile.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/py_compile.py
r2 r391 62 62 63 63 64 # Define an internal helper according to the platform65 if os.name == "mac":66 import MacOS67 def set_creator_type(file):68 MacOS.SetCreatorAndType(file, 'Pyth', 'PYC ')69 else:70 def set_creator_type(file):71 pass72 73 64 def wr_long(f, x): 74 65 """Internal; write a 32-bit int to a file in little-endian order.""" … … 113 104 114 105 """ 115 f = open(file, 'U') 116 try: 117 timestamp = long(os.fstat(f.fileno()).st_mtime) 118 except AttributeError: 119 timestamp = long(os.stat(file).st_mtime) 120 codestring = f.read() 121 f.close() 122 if codestring and codestring[-1] != '\n': 123 codestring = codestring + '\n' 106 with open(file, 'U') as f: 107 try: 108 timestamp = long(os.fstat(f.fileno()).st_mtime) 109 except AttributeError: 110 timestamp = long(os.stat(file).st_mtime) 111 codestring = f.read() 124 112 try: 125 113 codeobject = __builtin__.compile(codestring, dfile or file,'exec') 126 114 except Exception,err: 127 py_exc = PyCompileError(err.__class__, err.args,dfile or file)115 py_exc = PyCompileError(err.__class__, err, dfile or file) 128 116 if doraise: 129 117 raise py_exc … … 133 121 if cfile is None: 134 122 cfile = file + (__debug__ and 'c' or 'o') 135 fc = open(cfile, 'wb') 136 fc.write('\0\0\0\0') 137 wr_long(fc, timestamp) 138 marshal.dump(codeobject, fc) 139 fc.flush() 140 fc.seek(0, 0) 141 fc.write(MAGIC) 142 fc.close() 143 set_creator_type(cfile) 123 with open(cfile, 'wb') as fc: 124 fc.write('\0\0\0\0') 125 wr_long(fc, timestamp) 126 marshal.dump(codeobject, fc) 127 fc.flush() 128 fc.seek(0, 0) 129 fc.write(MAGIC) 144 130 145 131 def main(args=None): … … 150 136 in the normal manner. This function does not search a directory 151 137 structure to locate source files; it only compiles files named 152 explicitly. 138 explicitly. If '-' is the only parameter in args, the list of 139 files is taken from standard input. 153 140 154 141 """ … … 156 143 args = sys.argv[1:] 157 144 rv = 0 158 for filename in args: 159 try: 160 compile(filename, doraise=True) 161 except PyCompileError, err: 162 # return value to indicate at least one failure 163 rv = 1 164 sys.stderr.write(err.msg) 145 if args == ['-']: 146 while True: 147 filename = sys.stdin.readline() 148 if not filename: 149 break 150 filename = filename.rstrip('\n') 151 try: 152 compile(filename, doraise=True) 153 except PyCompileError as error: 154 rv = 1 155 sys.stderr.write("%s\n" % error.msg) 156 except IOError as error: 157 rv = 1 158 sys.stderr.write("%s\n" % error) 159 else: 160 for filename in args: 161 try: 162 compile(filename, doraise=True) 163 except PyCompileError as error: 164 # return value to indicate at least one failure 165 rv = 1 166 sys.stderr.write(error.msg) 165 167 return rv 166 168
Note:
See TracChangeset
for help on using the changeset viewer.