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/Demo/scripts/pp.py

    r2 r391  
    2323
    2424import sys
    25 import string
    2625import getopt
    2726
     
    3736    optlist, ARGS = getopt.getopt(sys.argv[1:], 'acde:F:np')
    3837except getopt.error, msg:
    39     sys.stderr.write(sys.argv[0] + ': ' + msg + '\n')
     38    sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
    4039    sys.exit(2)
    4140
     
    4847        DFLAG = 1
    4948    elif option == '-e':
    50         for line in string.splitfields(optarg, '\n'):
     49        for line in optarg.split('\n'):
    5150            SCRIPT.append(line)
    5251    elif option == '-F':
     
    8281    # Note that it is on purpose that AFLAG and PFLAG are
    8382    # 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()'
    102101            ]
    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',
    109108            ]
    110109else:
     
    115114# used in 'command' will come out right after re-indentation.
    116115
    117 program = string.joinfields(prologue, '\n') + '\n'
     116program = '\n'.join(prologue) + '\n'
    118117for line in SCRIPT:
    119     program = program + ('   \t   \t' + line + '\n')
    120 program = program + (string.joinfields(epilogue, '\n') + '\n')
     118    program += '   \t   \t' + line + '\n'
     119program += '\n'.join(epilogue) + '\n'
    121120
    122121import tempfile
     
    126125if DFLAG:
    127126    import pdb
    128     pdb.run('execfile(%r)' % (tfn,))
     127    pdb.run('execfile(%r)' % (fp.name,))
    129128else:
    130     execfile(tfn)
     129    execfile(fp.name)
Note: See TracChangeset for help on using the changeset viewer.