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/Tools/scripts/reindent.py

    r2 r391  
    3636The backup file is a copy of the one that is being reindented. The ".bak"
    3737file is generated with shutil.copy(), but some corner cases regarding
    38 user/group and permissions could leave the backup file more readable that
     38user/group and permissions could leave the backup file more readable than
    3939you'd prefer. You can always use the --nobackup option to prevent this.
    4040"""
     
    4545import os, shutil
    4646import sys
     47import io
    4748
    4849verbose    = 0
     
    109110        print "checking", file, "...",
    110111    try:
    111         f = open(file)
     112        f = io.open(file)
    112113    except IOError, msg:
    113114        errprint("%s: I/O Error: %s" % (file, str(msg)))
     
    116117    r = Reindenter(f)
    117118    f.close()
     119
     120    newline = r.newlines
     121    if isinstance(newline, tuple):
     122        errprint("%s: mixed newlines detected; cannot process file" % file)
     123        return
     124
    118125    if r.run():
    119126        if verbose:
     
    127134                if verbose:
    128135                    print "backed up", file, "to", bak
    129             f = open(file, "w")
     136            f = io.open(file, "w", newline=newline)
    130137            r.write(f)
    131138            f.close()
     
    173180        # indeed, they're our headache!
    174181        self.stats = []
     182
     183        # Save the newlines found in the file so they can be used to
     184        #  create output without mutating the newlines.
     185        self.newlines = f.newlines
    175186
    176187    def run(self):
Note: See TracChangeset for help on using the changeset viewer.