tests/heredoctest.py
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 16 Jan 2013 14:26:19 +0100
branchstable
changeset 1201 6f2f7246e4be
parent 1110 d5b3404b82ce
permissions -rw-r--r--
get-with-headers: add a --headeronly switch In some case we do not care about the actual rendering. [ original upstream message ]

import sys

globalvars = {}
localvars = {}
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)
            snippet += "\n" + l[4:]
        c = compile(snippet, '<heredoc>', 'single')
        try:
            exec c in globalvars, localvars
        except Exception, inst:
            print repr(inst)