heredoctest.py
20 lines
| 510 B
| text/x-python
|
PythonLexer
/ tests / heredoctest.py
Gregory Szorc
|
r27297 | from __future__ import absolute_import | ||
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'): | ||||
Augie Fackler
|
r25032 | print(l[:-1]) | ||
Matt Mackall
|
r15434 | 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: | ||||
Augie Fackler
|
r25032 | exec(c, globalvars) | ||
except Exception as inst: | ||||
print(repr(inst)) | ||||