diff options
Diffstat (limited to 'Tools/scripts/pindent.py')
-rwxr-xr-x | Tools/scripts/pindent.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/Tools/scripts/pindent.py b/Tools/scripts/pindent.py index 3333420..6e40d60 100755 --- a/Tools/scripts/pindent.py +++ b/Tools/scripts/pindent.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python3 +#! /usr/bin/env python # This file contains a class and a main program that perform three # related (though complimentary) formatting operations on Python @@ -76,6 +76,8 @@ # - realign comments # - optionally do much more thorough reformatting, a la C indent +from __future__ import print_function + # Defaults STEPSIZE = 8 TABSIZE = 8 @@ -186,7 +188,7 @@ class PythonIndenter: stack.append((kw, kw)) continue # end if - if kw in next and stack: + if next.has_key(kw) and stack: self.putline(line, len(stack)-1) kwa, kwb = stack[-1] stack[-1] = kwa, kw @@ -247,7 +249,7 @@ class PythonIndenter: m = self.kwprog.match(line) if m: thiskw = m.group('kw') - if thiskw not in next: + if not next.has_key(thiskw): thiskw = '' # end if if thiskw in ('def', 'class'): @@ -347,24 +349,24 @@ def reformat_filter(input = sys.stdin, output = sys.stdout, # end def reformat_filter def complete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS): - input = io.StringIO(source) - output = io.StringIO() + input = io.BytesIO(source) + output = io.BytesIO() pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs) pi.complete() return output.getvalue() # end def complete_string def delete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS): - input = io.StringIO(source) - output = io.StringIO() + input = io.BytesIO(source) + output = io.BytesIO() pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs) pi.delete() return output.getvalue() # end def delete_string def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS): - input = io.StringIO(source) - output = io.StringIO() + input = io.BytesIO(source) + output = io.BytesIO() pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs) pi.reformat() return output.getvalue() @@ -376,13 +378,13 @@ def make_backup(filename): if os.path.lexists(backup): try: os.remove(backup) - except OSError: + except os.error: print("Can't remove backup %r" % (backup,), file=sys.stderr) # end try # end if try: os.rename(filename, backup) - except OSError: + except os.error: print("Can't rename %r to %r" % (filename, backup), file=sys.stderr) # end try # end def make_backup @@ -454,7 +456,7 @@ def test(): import getopt try: opts, args = getopt.getopt(sys.argv[1:], 'cdrs:t:e') - except getopt.error as msg: + except getopt.error, msg: sys.stderr.write('Error: %s\n' % msg) sys.stderr.write(usage) sys.exit(2) |