heredoctest.py
18 lines
| 470 B
| text/x-python
|
PythonLexer
/ tests / heredoctest.py
|
r15434 | import sys | ||
|
r15247 | |||
|
r15434 | globalvars = {} | ||
lines = sys.stdin.readlines() | ||||
while lines: | ||||
l = lines.pop(0) | ||||
if l.startswith('SALT'): | ||||
|
r25032 | print(l[:-1]) | ||
|
r15434 | elif l.startswith('>>> '): | ||
snippet = l[4:] | ||||
while lines and lines[0].startswith('... '): | ||||
l = lines.pop(0) | ||||
|
r22565 | snippet += l[4:] | ||
|
r15434 | c = compile(snippet, '<heredoc>', 'single') | ||
try: | ||||
|
r25032 | exec(c, globalvars) | ||
except Exception as inst: | ||||
print(repr(inst)) | ||||