tests/heredoctest.py
changeset 1111 df702ad9b314
parent 1110 d5b3404b82ce
equal deleted inserted replaced
1103:9459951761fb 1111:df702ad9b314
       
     1 import sys
       
     2 
       
     3 globalvars = {}
       
     4 localvars = {}
       
     5 lines = sys.stdin.readlines()
       
     6 while lines:
       
     7     l = lines.pop(0)
       
     8     if l.startswith('SALT'):
       
     9         print l[:-1]
       
    10     elif l.startswith('>>> '):
       
    11         snippet = l[4:]
       
    12         while lines and lines[0].startswith('... '):
       
    13             l = lines.pop(0)
       
    14             snippet += "\n" + l[4:]
       
    15         c = compile(snippet, '<heredoc>', 'single')
       
    16         try:
       
    17             exec c in globalvars, localvars
       
    18         except Exception, inst:
       
    19             print repr(inst)