Changeset 391 for python/trunk/Demo/scripts/pp.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/Demo/scripts/pp.py
r2 r391 23 23 24 24 import sys 25 import string26 25 import getopt 27 26 … … 37 36 optlist, ARGS = getopt.getopt(sys.argv[1:], 'acde:F:np') 38 37 except getopt.error, msg: 39 sys.stderr.write( sys.argv[0] + ': ' + msg + '\n')38 sys.stderr.write('%s: %s\n' % (sys.argv[0], msg)) 40 39 sys.exit(2) 41 40 … … 48 47 DFLAG = 1 49 48 elif option == '-e': 50 for line in string.splitfields(optarg,'\n'):49 for line in optarg.split('\n'): 51 50 SCRIPT.append(line) 52 51 elif option == '-F': … … 82 81 # Note that it is on purpose that AFLAG and PFLAG are 83 82 # tested dynamically each time through the loop 84 prologue = [ \85 'LINECOUNT = 0', \86 'for FILE in ARGS:', \87 ' \tif FILE == \'-\':', \88 ' \t \tFP = sys.stdin', \89 ' \telse:', \90 ' \t \tFP = open(FILE, \'r\')', \91 ' \tLINENO = 0', \92 ' \twhile 1:', \93 ' \t \tLINE = FP.readline()', \94 ' \t \tif not LINE: break', \95 ' \t \tLINENO = LINENO + 1', \96 ' \t \tLINECOUNT = LINECOUNT + 1', \97 ' \t \tL = LINE[:-1]', \98 ' \t \taflag = AFLAG', \99 ' \t \tif aflag:', \100 ' \t \t \tif FS: F = string.splitfields(L, FS)', \101 ' \t \t \telse: F = string.split(L)' \83 prologue = [ 84 'LINECOUNT = 0', 85 'for FILE in ARGS:', 86 ' \tif FILE == \'-\':', 87 ' \t \tFP = sys.stdin', 88 ' \telse:', 89 ' \t \tFP = open(FILE, \'r\')', 90 ' \tLINENO = 0', 91 ' \twhile 1:', 92 ' \t \tLINE = FP.readline()', 93 ' \t \tif not LINE: break', 94 ' \t \tLINENO = LINENO + 1', 95 ' \t \tLINECOUNT = LINECOUNT + 1', 96 ' \t \tL = LINE[:-1]', 97 ' \t \taflag = AFLAG', 98 ' \t \tif aflag:', 99 ' \t \t \tif FS: F = L.split(FS)', 100 ' \t \t \telse: F = L.split()' 102 101 ] 103 epilogue = [ \104 ' \t \tif not PFLAG: continue', \105 ' \t \tif aflag:', \106 ' \t \t \tif FS: print string.joinfields(F, FS)', \107 ' \t \t \telse: print string.join(F)', \108 ' \t \telse: print L', \102 epilogue = [ 103 ' \t \tif not PFLAG: continue', 104 ' \t \tif aflag:', 105 ' \t \t \tif FS: print FS.join(F)', 106 ' \t \t \telse: print \' \'.join(F)', 107 ' \t \telse: print L', 109 108 ] 110 109 else: … … 115 114 # used in 'command' will come out right after re-indentation. 116 115 117 program = string.joinfields(prologue, '\n') + '\n'116 program = '\n'.join(prologue) + '\n' 118 117 for line in SCRIPT: 119 program = program + (' \t \t' + line + '\n')120 program = program + (string.joinfields(epilogue, '\n') + '\n')118 program += ' \t \t' + line + '\n' 119 program += '\n'.join(epilogue) + '\n' 121 120 122 121 import tempfile … … 126 125 if DFLAG: 127 126 import pdb 128 pdb.run('execfile(%r)' % ( tfn,))127 pdb.run('execfile(%r)' % (fp.name,)) 129 128 else: 130 execfile( tfn)129 execfile(fp.name)
Note:
See TracChangeset
for help on using the changeset viewer.