本文整理汇总了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)