Пример #1
0
 def run(self, entry_point, args, expected):
     exe = compile(entry_point)
     from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
     proc = SimpleIOSandboxedProc([exe] + args)
     output, error = proc.communicate()
     assert error == ''
     assert output == expected
Пример #2
0
 def run(self, entry_point, args, expected):
     exe = compile(entry_point)
     from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
     proc = SimpleIOSandboxedProc([exe] + args)
     output, error = proc.communicate()
     assert error == ''
     assert output == expected
Пример #3
0
 def run(self, entry_point, args, expected):
     t = Translation(entry_point, backend='c', standalone=True,
                     sandbox=True)
     exe = t.compile()
     from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
     proc = SimpleIOSandboxedProc([exe] + args)
     output, error = proc.communicate()
     assert error == ''
     assert output == expected
Пример #4
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 == ""
Пример #5
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 == ""
Пример #6
0
#! /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 pypy.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()