• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sandbox.Sandbox类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sandbox.Sandbox的典型用法代码示例。如果您正苦于以下问题:Python Sandbox类的具体用法?Python Sandbox怎么用?Python Sandbox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Sandbox类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: executeTests

 def executeTests(self, commandLine):
     log.debug("JUnitTestLoader.executeTests() with commandLine=%s", commandLine)
     # Initialize our state.
     start = time.time()
     sb = Sandbox(SBROOT)
     sb.set_last_test_date(start)
     global _timeout_monitor
     _timeout_monitor = None
     testOutput = ""
     err = 0
     try:
         # Start up a thread that will force us to exit if we hang.
         pabrt = _ProcAbort()
         _timeout_monitor = timeout_monitor.start(sb.get_test_timeout_seconds(), killfunc=pabrt)
         # Always run tests in alphabetical order, for predictability
         # and ease of explanation.
         proc = subprocess.Popen(commandLine,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
         _timeout_monitor.last_status = time.time()
         pabrt.proc = proc
         testOutput, stderr = proc.communicate()
         err = proc.returncode
     except Exception as e:
         log.debug("JUnitTestLoader.executeTests(): Got exception: %s", str(e))
         err = 1
     finally:
         if _timeout_monitor:
             _timeout_monitor.stop()
     if "[junit] '-classpath" in testOutput and 'BUILD FAILED' in testOutput:
         err = 0
         log.debug("JUnitTestLoader.executeTests(): Actually it's JUnit test failed, all is fine.")
     if err != 0:
         raise Exception("Building compiled test suite failed!")
     return testOutput
开发者ID:perfectsearch,项目名称:sandman,代码行数:35,代码来源:JUnitTestLoader.py


示例2: Interpreter

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,代码行数:25,代码来源:core.py


示例3: main

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,代码行数:26,代码来源:sandbox1.py


示例4: test_subprocess_series

def test_subprocess_series():
    profile = Profile({'max_processes': 5})
    s = Sandbox()
    s.clone_bin("sh")
    s.clone_bin("echo")
    s.clone_bin("cat")

    with s.open("/sandbox_content.txt", 'w') as f:
        f.write('\n'.join([
            'hello',
            ''
        ]))

    with s.open("/sandbox_subprocess.sh", 'w') as f:
        f.write('\n'.join([
            '#!/bin/sh',
        ]))

        for i in range(0, 10):
            f.write('\n'.join([
                '#!/bin/sh',
                'cat /sandbox_content.txt &',
            ]))

    feedback = s.process(["sh", "/sandbox_subprocess.sh"], profile=profile, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout = feedback.stdout.read()
    assert len(stdout.split('hello')) <= (5 + 1)
    assert feedback.ended_correctly
    assert feedback.return_code != 0

    del s

    return True
开发者ID:INSA-4IF-SpecIFic,项目名称:elif,代码行数:33,代码来源:test_sandbox.py


示例5: test_open

 def test_open(self):
     s = Sandbox(self.task[0])
     s.policy = SelectiveOpenPolicy(s, set([(b"/dev/zero", O_RDONLY), ]))
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_OK)
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:7,代码来源:test_trace.py


示例6: test_clone

 def test_clone(self):
     s = Sandbox(self.task[2])
     s.policy = MinimalPolicy()
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RF)
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:7,代码来源:test_trace.py


示例7: test_subprocess

def test_subprocess():
    profile = Profile({'max_processes': 32})
    s = Sandbox()
    s.clone_bin("sh")
    s.clone_bin("echo")
    s.clone_bin("cat")

    with s.open("/sandbox_subprocess.sh", 'w') as f:
        f.write('\n'.join([
            '#!/bin/sh',
            'echo "visible";',
            'cat $0;',
            'echo "hidden";'
        ]))

    feedback = s.process(["sh", "/sandbox_subprocess.sh"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout = feedback.stdout.read()
    assert 'visible' in stdout
    assert 'hidden' not in stdout
    assert 'fork' in feedback.stderr.read()
    assert feedback.ended_correctly
    assert feedback.return_code != 0

    feedback = s.process(["sh", "/sandbox_subprocess.sh"], profile=profile, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout = feedback.stdout.read()
    assert 'visible' in stdout
    assert 'hidden' in stdout
    assert 'fork' not in feedback.stderr.read()
    assert feedback.ended_correctly
    assert feedback.return_code == 0

    del s

    return True
开发者ID:INSA-4IF-SpecIFic,项目名称:elif,代码行数:34,代码来源:test_sandbox.py


示例8: execute_child

def execute_child():
    input_filename = sys.argv[1]
    output_filename = sys.argv[2]
    output = open(output_filename, "wb")
    base_exception = BaseException
    try:
        with open(input_filename, 'rb') as input_file:
            input_data = pickle.load(input_file)
        code = input_data['code']
        config = input_data['config']
        locals = input_data['locals']
        globals = input_data['globals']
        set_process_limits(config)

        sandbox = Sandbox(config)
        result = sandbox._execute(code, globals, locals)

        output_data = {'result': result}
        if input_data['globals'] is not None:
            del globals['__builtins__']
            output_data['globals'] = globals
        if 'locals' in input_data:
            output_data['locals'] = locals
    except base_exception, err:
        output_data = {'error': err}
开发者ID:kantale,项目名称:pysandbox,代码行数:25,代码来源:subprocess_child.py


示例9: test_rlimit_cpu

 def test_rlimit_cpu(self):
     s = Sandbox(self.task[6])
     s.policy = AllowResLimitPolicy(s)
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RT)
     d = s.probe(False)
     self.assertEqual(d['signal_info'], (SIGXCPU, SI_KERNEL))
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_signal.py


示例10: test_sigtrap_user

 def test_sigtrap_user(self):
     s = Sandbox(self.task[4])
     s.policy = KillerPolicy(s, SIGTRAP)
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RT)
     d = s.probe(False)
     self.assertEqual(d['signal_info'], (SIGTRAP, SI_USER))
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_signal.py


示例11: test_sigkill

 def test_sigkill(self):
     s = Sandbox(self.task[4])
     s.policy = KillerPolicy(s, SIGKILL)
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RT)
     d = s.probe(False)
     self.assertEqual(d['signal_info'][0], SIGKILL)
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_signal.py


示例12: test_sigfpe_intdiv

 def test_sigfpe_intdiv(self):
     s = Sandbox(self.task[1])
     s.policy = MinimalPolicy()
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RT)
     d = s.probe(False)
     self.assertEqual(d['signal_info'], (SIGFPE, FPE_INTDIV))
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_signal.py


示例13: __init__

 def __init__(self, *args, **kwds):
     # initialize table of system call rules
     self.sc_table = [self._KILL_RF, ] * 1024
     for scno in MiniSandbox.sc_safe[self.machine]:
         self.sc_table[scno] = self._CONT
     # initialize as a polymorphic sandbox-and-policy object
     SandboxPolicy.__init__(self)
     Sandbox.__init__(self, *args, **kwds)
     self.policy = self
开发者ID:fannix,项目名称:judge,代码行数:9,代码来源:judge_sandbox.py


示例14: test_ol_file_write

 def test_ol_file_write(self):
     s = Sandbox(self.task[0], quota=dict(wallclock=60000, cpu=2000, disk=5))
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_OL)
     with open(self.fout[0], "rb") as f:
         self.assertEqual(f.read(), b"Hello")
         f.close()
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_quota.py


示例15: test_sigsegv_accerr

 def test_sigsegv_accerr(self):
     s = Sandbox(self.task[3])
     s.policy = MinimalPolicy()
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RT)
     d = s.probe(False)
     self.assertEqual(d['signal_info'], (SIGSEGV, SEGV_ACCERR))
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_signal.py


示例16: test_sigbus_adraln

 def test_sigbus_adraln(self):
     s = Sandbox(self.task[0])
     s.policy = MinimalPolicy()
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RT)
     d = s.probe(False)
     self.assertEqual(d['signal_info'], (SIGBUS, BUS_ADRALN))
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:9,代码来源:test_signal.py


示例17: test_int80_fork

 def test_int80_fork(self):
     # syscall #2: (fork, i686) vs (open, x86_64)
     s = Sandbox(self.task[1])
     s.policy = MinimalPolicy()
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RF)
     d = s.probe(False)
     self.assertEqual(d['syscall_info'], (2, 1))
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:10,代码来源:test_trace.py


示例18: main

def main():
    config, argv = parseOptions()
    config.allowModule('sys', 'argv')

    with open(argv[0], "rb") as fp:
        content = fp.read()

    sys.argv = list(argv)
    sandbox = Sandbox(config)
    sandbox.execute(content)
开发者ID:ailling,项目名称:pysandbox,代码行数:10,代码来源:execfile.py


示例19: test_ml_static

 def test_ml_static(self):
     s = Sandbox(self.task[0], quota=dict(wallclock=60000, cpu=2000, memory=2 ** 24))
     s.policy = MinimalPolicy()
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_ML)
     d = s.probe(False)
     mem = d['mem_info'][1] * 1024
     self.assertLess(s.quota[Sandbox.S_QUOTA_MEMORY], mem)
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:10,代码来源:test_quota.py


示例20: test_kill_ppid

 def test_kill_ppid(self):
     s = Sandbox(self.task[0])
     s.policy = AllowSelfKillPolicy(s)
     s.run()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_RF)
     d = s.probe(False)
     sc = d['syscall_info'] if machine() == 'x86_64' else d['syscall_info'][0]
     self.assertTrue(sc in AllowSelfKillPolicy.SC_kill)
     pass
开发者ID:krishkoushik,项目名称:CVGWebsite,代码行数:10,代码来源:test_signal.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python layers_powered.LayersPowered类代码示例发布时间:2022-05-27
下一篇:
Python client.Client类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap