comparison tests/heredoctest.py @ 25032:1db2127d2373

heredoctest: 2to3 -w -f numliterals -f except -f print tests/heredoctest.py
author Augie Fackler <augie@google.com>
date Sun, 12 Apr 2015 15:34:17 -0400
parents 8d45a42b0c0f
children 4179d054b3e9
comparison
equal deleted inserted replaced
25031:0adc22a0b6b3 25032:1db2127d2373
3 globalvars = {} 3 globalvars = {}
4 lines = sys.stdin.readlines() 4 lines = sys.stdin.readlines()
5 while lines: 5 while lines:
6 l = lines.pop(0) 6 l = lines.pop(0)
7 if l.startswith('SALT'): 7 if l.startswith('SALT'):
8 print l[:-1] 8 print(l[:-1])
9 elif l.startswith('>>> '): 9 elif l.startswith('>>> '):
10 snippet = l[4:] 10 snippet = l[4:]
11 while lines and lines[0].startswith('... '): 11 while lines and lines[0].startswith('... '):
12 l = lines.pop(0) 12 l = lines.pop(0)
13 snippet += l[4:] 13 snippet += l[4:]
14 c = compile(snippet, '<heredoc>', 'single') 14 c = compile(snippet, '<heredoc>', 'single')
15 try: 15 try:
16 exec c in globalvars 16 exec(c, globalvars)
17 except Exception, inst: 17 except Exception as inst:
18 print repr(inst) 18 print(repr(inst))