예제 #1
0
 def run(self, entry_point, args, expected):
     exe = compile(entry_point)
     from rpython.translator.sandbox.sandlib import SimpleIOSandboxedProc
     proc = SimpleIOSandboxedProc([exe] + args)
     output, error = proc.communicate()
     assert error == ''
     assert output == expected
예제 #2
0
def test_simpleio():
    def entry_point(argv):
        print "Please enter a number:"
        buf = ""
        while True:
            t = os.read(0, 1)    # 1 character from stdin
            if not t:
                raise EOFError
            if t == '\n':
                break
            buf += t
        num = int(buf)
        print "The double is:", num * 2
        return 0
    exe = compile(entry_point)

    proc = SimpleIOSandboxedProc([exe, 'x1', 'y2'])
    output, error = proc.communicate("21\n")
    assert output == "Please enter a number:\nThe double is: 42\n"
    assert error == ""
예제 #3
0
def test_simpleio():
    def entry_point(argv):
        print "Please enter a number:"
        buf = ""
        while True:
            t = os.read(0, 1)    # 1 character from stdin
            if not t:
                raise EOFError
            if t == '\n':
                break
            buf += t
        num = int(buf)
        print "The double is:", num * 2
        return 0
    exe = compile(entry_point)

    proc = SimpleIOSandboxedProc([exe, 'x1', 'y2'])
    output, error = proc.communicate("21\n")
    assert output == "Please enter a number:\nThe double is: 42\n"
    assert error == ""
예제 #4
0
파일: interact.py 프로젝트: sbw111/lab4
#! /usr/bin/env python

"""Interacts with a subprocess translated with --sandbox.
The subprocess is only allowed to use stdin/stdout/stderr.

Usage:
    interact.py <executable> <args...>
"""

import sys
from rpython.translator.sandbox.sandlib import SimpleIOSandboxedProc

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print >> sys.stderr, __doc__
        sys.exit(2)
    SimpleIOSandboxedProc(sys.argv[1:]).interact()