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


Python Sandbox.enable_protections方法代码示例

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


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

示例1: Player

# 需要导入模块: from sandbox import Sandbox [as 别名]
# 或者: from sandbox.Sandbox import enable_protections [as 别名]
class Player(greenlet):
    def __init__(self, robot_controller):
        super(Player, self).__init__()
        self.robot_controller = robot_controller

        config = SandboxConfig(use_subprocess=False)
        config.enable('traceback')
        config.enable('stdout')
        config.enable('stderr')
        config.enable('time')

        # TODO need to allow *all* imports from team package
        config.allowModule(robot_controller.robot.team + '.player', 'RobotPlayer')

        # TODO need a better method for override the sys_path
        config.sys_path = config.sys_path + (os.getcwd(),)

        # add additional builtins to the config
        #   - increment_clock
        this = self
        def increment_clock(amt):
            Scheduler.instance().increment_bytecode(amt)

        # TODO need a better method to add builtins additions
        config._builtins_additions = {
            'increment_clock': increment_clock,
        }

        self.sandbox = Sandbox(config)
        self.running = False

    def resume(self, throw=False):
        return self.switch(throw)

    def pause(self):
        # break out of the sandbox
        self.sandbox.disable_protections()
        # return execution to the scheduler
        throw = self.parent.switch()
        if throw:
            raise RobotDeathException('killed by engine')
        # re-enable sandbox protections
        self.sandbox.enable_protections()

    def run(self, *args):
        statement = LOADER_CODE.format(team=self.robot_controller.robot.team)
        safelocals = { 'rc': self.robot_controller }
        self.running = True
        self.sandbox.execute(statement, globals={}, locals=safelocals)
开发者ID:trun,项目名称:redux,代码行数:51,代码来源:scheduler.py


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