本文整理汇总了Python中sandbox.Sandbox.call方法的典型用法代码示例。如果您正苦于以下问题:Python Sandbox.call方法的具体用法?Python Sandbox.call怎么用?Python Sandbox.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sandbox.Sandbox
的用法示例。
在下文中一共展示了Sandbox.call方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
def main():
filecpp=sys.argv[1]
filetxt=sys.argv[2]
filext=sys.argv[3]
cmd="./bash1.sh"+" "+filecpp+" "+filetxt+" "+filext
resource.setrlimit(resource.RLIMIT_CPU,(1,3))
#The maximum amount of processor time (in seconds) that a process can use.
soft, hard = 10**10, 10**10
resource.setrlimit(resource.RLIMIT_AS,(soft,hard))
#The maximum area (in bytes) of address space which may be taken by the process.
# we can provide more restriction by using these..
#resource.setrlimit(resource.RLIMIT_DATA,(s,h))
#The maximum size (in bytes) of the process s heap.
#resource.setrlimit(resource.RLIMIT_STACK(s,h))
#The maximum size (in bytes) of the call stack for the current process.
#resource.setrlimit(resource.RLIMIT_NPROC,(4,4))
#The maximum number of processes the current process may create.
sandbox=Sandbox()
sandbox.call(perform,cmd)
#executing the code in sandbox environment
signal.signal(signal.SIGXCPU,time_exceeded)
soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
示例2: Interpreter
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
class Interpreter(object):
def __init__(self, resource):
self.resource = resource
self.sandbox = Sandbox()
self._context = None
self.make_context()
def make_context(self):
raise NotImplementedError('Interpreter.make_context')
def _context_call(self, *args):
raise NotImplementedError('Interpreter._context_call')
def _context_eval(self, *args):
raise NotImplementedError('Interpreter._context_eval')
def call(self, *args):
return self.sandbox.call(self._context_call, *args)
def eval(self, *args):
return self.sandbox.call(self._context_eval, *args)
@property
def content(self):
return self.resource.content
示例3: test_proxy_module
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
def test_proxy_module():
def check_proxy_module():
from sys import modules
try:
modules['sys']
except SandboxError as err:
assert str(err) == "Unable to proxy a value of type <type 'module'>"
else:
assert False
config = createSandboxConfig()
config.allowModule('sys', 'modules')
sandbox = Sandbox(config)
sandbox.call(check_proxy_module)
示例4: test_crash
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
def test_crash():
if not createSandboxConfig.use_subprocess:
raise SkipTest("catching a crash is only supported with subprocess")
def crash():
import _sandbox
_sandbox._test_crash()
config = createSandboxConfig()
config.allowSafeModule("_sandbox", "_test_crash")
sand = Sandbox(config)
try:
sand.call(crash)
except SandboxError, err:
assert str(err) == 'subprocess killed by signal 11', str(err)
示例5: main
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
def main():
filecpp = sys.argv[1]
filetxt = sys.argv[2]
filext = sys.argv[3]
cmd = "./bash2.sh" + " " + filecpp + " " + filetxt + " " + filext
resource.setrlimit(resource.RLIMIT_CPU, (1, 3))
# The maximum amount of processor time (in seconds) that a process can use.
soft, hard = 10 ** 10, 10 ** 10
resource.setrlimit(resource.RLIMIT_AS, (soft, hard))
# The maximum area (in bytes) of address space which may be taken by the process.
sandbox = Sandbox()
sandbox.call(perform, cmd)
signal.signal(signal.SIGXCPU, time_exceeded)
soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
示例6: main
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
def main(self):
if not self.options.quiet:
print("pysandbox %s" % VERSION)
self.dumpConfig()
if 'help' in self.config.features:
# Import pydoc here because it uses a lot of modules
# blocked by the sandbox
import pydoc
if self.config.cpython_restricted:
# Import is blocked in restricted mode, so preload modules
import codecs
import encodings
import encodings.utf_8
import encodings.utf_16_be
if version_info >= (2, 6):
import encodings.utf_32_be
if sys.stdout.encoding:
codecs.lookup(sys.stdout.encoding)
codecs.lookup(ENCODING)
sys.ps1 = '\nsandbox>>> '
sys.ps2 = '.......... '
sys.displayhook = self.displayhook
sandbox = Sandbox(self.config)
sandbox.call(self.interact)
示例7: Person
# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import call [as 别名]
person = Person("haypo")
sandbox = createSandbox()
try:
sandbox.call(setDict, person)
except SandboxError, err:
assert str(err) == 'Read only object'
except RuntimeError, err:
assert str(err) == 'instance.__dict__ not accessible in restricted mode'
else:
assert False
setDict(person)
assert person.name == "victor"
def test_proxy_module():
def check_proxy_module():
from sys import modules
try:
modules['sys']
except SandboxError, err:
assert str(err) == "Unable to proxy a value of type <type 'module'>"
else:
assert False
config = createSandboxConfig()
config.allowModule('sys', 'modules')
sandbox = Sandbox(config)
sandbox.call(check_proxy_module)