| 1 |
import sys |
| 2 |
|
| 3 |
|
| 4 |
def flush(): |
| 5 |
sys.stdout.flush() |
| 6 |
sys.stderr.flush() |
| 7 |
|
| 8 |
|
| 9 |
globalvars = {} |
| 10 |
lines = sys.stdin.readlines() |
| 11 |
while lines: |
| 12 |
l = lines.pop(0) |
| 13 |
if l.startswith('SALT'): |
| 14 |
print(l[:-1]) |
| 15 |
elif l.startswith('>>> '): |
| 16 |
snippet = l[4:] |
| 17 |
while lines and lines[0].startswith('... '): |
| 18 |
l = lines.pop(0) |
| 19 |
snippet += l[4:] |
| 20 |
c = compile(snippet, '<heredoc>', 'single') |
| 21 |
try: |
| 22 |
flush() |
| 23 |
exec(c, globalvars) |
| 24 |
flush() |
| 25 |
except Exception as inst: |
| 26 |
flush() |
| 27 |
print(repr(inst)) |