tests/heredoctest.py
author Anton Shestakov <av6@dwimlabs.net>
Sat, 27 Feb 2016 19:53:18 +0800
changeset 28268 3643b66d7f71
parent 27297 4179d054b3e9
child 29485 6a98f9408a50
permissions -rw-r--r--
hgweb: add index template to json/map This template allows showing the list of all repos in an hgweb instance (in hgwebdir mode) as json. The test has "lastchange" globbed because hgweb uses here file modification time and not the last commit time.

from __future__ import absolute_import

import sys

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