pylib/mercurial-support/heredoctest.py
author Gregory Szorc <gps@mozilla.com>
Tue, 12 Jan 2016 15:07:29 -0800
changeset 362099 64bc74f4b91a7730c7d03c4fcbe9f4a723813a75
parent 359313 534e49b0f148557b4c0eb9a1eaceac42bae1be3a
permissions -rw-r--r--
mozreview: copy more read-only processing code (bug 1229468); r=smacleod, dminor This is basically copying a lot of code from pushhooks.py. We don't yet make any database modification as part of this code. This just proves that a rough 1:1 copy continues to work.

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)