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