def _raise_exception(self, errval): if isinstance(errval, (basestring, numbers.Number)): raise lupa.LuaError(errval) elif errval['etype'] == 'ptp': raise PTPError(errval) else: raise lupa.LuaError(parse_table(errval))
def _execute_in_sandbox(lua, script): """ Execute ``script`` in ``lua`` runtime using ``sandbox``. Return a (sandboxed) global environment for the executed script. "sandbox" module should be importable in the environment. It should provide ``sandbox.run(untrusted_code)`` method and ``sandbox.env`` table with a global environment. See ``splash/lua_modules/sandbox.lua``. """ sandbox = lua.eval("require('sandbox')") result = sandbox.run(script) if result is not True: ok, res = result raise lupa.LuaError(res) return sandbox.env
def execute_in_sandbox(lua, script, sandbox=None): """ Execute ``script`` in ``lua`` runtime using ``sandbox``. Return a (sandboxed) global environment for the executed script. ``sandbox`` script should provide a ``run(untrusted_code)`` Lua function and ``env`` table with a global environment. By default, a sandbox from ``splash/scripts/sandbox.lua`` is used. """ if sandbox is None: sandbox = get_script_source("sandbox.lua") lua.execute(sandbox) run = lua.globals()["run"] result = run(script) if result is not True: ok, res = result raise lupa.LuaError(res) return lua.globals()["env"]