当前位置: 首页>>代码示例>>Python>>正文


Python Sandbox.call方法代码示例

本文整理汇总了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)
开发者ID:vkt1992,项目名称:OnlineJudge,代码行数:28,代码来源:sandbox1.py

示例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
开发者ID:Roaming-Initiative,项目名称:python-libdeje,代码行数:27,代码来源:core.py

示例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)
开发者ID:yingted,项目名称:pysandbox,代码行数:16,代码来源:test_proxy.py

示例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)
开发者ID:charlierm,项目名称:pysandbox,代码行数:17,代码来源:test_misc.py

示例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)
开发者ID:vkt1992,项目名称:OnlineJudge,代码行数:19,代码来源:sandbox2.py

示例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)
开发者ID:ailling,项目名称:pysandbox,代码行数:26,代码来源:interpreter.py

示例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)

开发者ID:ailling,项目名称:pysandbox,代码行数:30,代码来源:test_proxy.py


注:本文中的sandbox.Sandbox.call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。