Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/py_compile.py

    r2 r391  
    6262
    6363
    64 # Define an internal helper according to the platform
    65 if os.name == "mac":
    66     import MacOS
    67     def set_creator_type(file):
    68         MacOS.SetCreatorAndType(file, 'Pyth', 'PYC ')
    69 else:
    70     def set_creator_type(file):
    71         pass
    72 
    7364def wr_long(f, x):
    7465    """Internal; write a 32-bit int to a file in little-endian order."""
     
    113104
    114105    """
    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()
    124112    try:
    125113        codeobject = __builtin__.compile(codestring, dfile or file,'exec')
    126114    except Exception,err:
    127         py_exc = PyCompileError(err.__class__,err.args,dfile or file)
     115        py_exc = PyCompileError(err.__class__, err, dfile or file)
    128116        if doraise:
    129117            raise py_exc
     
    133121    if cfile is None:
    134122        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)
    144130
    145131def main(args=None):
     
    150136    in the normal manner.  This function does not search a directory
    151137    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.
    153140
    154141    """
     
    156143        args = sys.argv[1:]
    157144    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)
    165167    return rv
    166168
Note: See TracChangeset for help on using the changeset viewer.