Example #1
0
    def __init__(self, tab, return_func, render_options, sandboxed,
                 lua_package_path,
                 lua_sandbox_allowed_modules):
        """
        :param splash.browser_tab.BrowserTab tab: BrowserTab object
        :param callable return_func: function that continues the script
        :param splash.render_options.RenderOptions render_options: arguments
        :param bool sandboxed: whether the script should be sandboxed
        :param str lua_package_path: paths to add to Lua package.path
        :param iterable lua_sandbox_allowed_modules: a list of modules allowed
            to be required from a sandbox
        """
        self.tab = tab
        self.sandboxed = sandboxed
        self.lua = self._create_runtime(lua_package_path)
        self._setup_lua_sandbox(lua_sandbox_allowed_modules)
        self._return = return_func

        self._exceptions = []
        self._command_ids = itertools.count()

        self.args = python2lua(self.lua, render_options.data)

        commands = {}
        for name in dir(self):
            value = getattr(self, name)
            if is_command(value):
                commands[name] = self.lua.table_from({
                    'is_async': getattr(value, '_is_async'),
                    'returns_error_flag': getattr(value, '_returns_error_flag', False),
                })
        self.commands = python2lua(self.lua, commands)
Example #2
0
    def __init__(self, tab, return_func, render_options, sandboxed,
                 lua_package_path, lua_sandbox_allowed_modules):
        """
        :param splash.browser_tab.BrowserTab tab: BrowserTab object
        :param callable return_func: function that continues the script
        :param splash.render_options.RenderOptions render_options: arguments
        :param bool sandboxed: whether the script should be sandboxed
        :param str lua_package_path: paths to add to Lua package.path
        :param iterable lua_sandbox_allowed_modules: a list of modules allowed
            to be required from a sandbox
        """
        self.tab = tab
        self.sandboxed = sandboxed
        self.lua = self._create_runtime(lua_package_path)
        self._setup_lua_sandbox(lua_sandbox_allowed_modules)
        self._return = return_func

        self._exceptions = []
        self._command_ids = itertools.count()

        self.args = python2lua(self.lua, render_options.data)

        commands = {}
        for name in dir(self):
            value = getattr(self, name)
            if is_command(value):
                commands[name] = self.lua.table_from({
                    'is_async':
                    getattr(value, '_is_async'),
                    'returns_error_flag':
                    getattr(value, '_returns_error_flag', False),
                })
        self.commands = python2lua(self.lua, commands)
Example #3
0
    def __init__(self, tab, return_func, render_options, sandboxed):
        """
        :param splash.browser_tab.BrowserTab tab: BrowserTab object
        :param callable return_func: function that continues the script
        :param splash.render_options.RenderOptions render_options: arguments
        :param bool sandboxed: whether the script should be sandboxed
        """
        self.lua = self._create_runtime()
        self.tab = tab
        self.sandboxed = sandboxed
        self._return = return_func
        self._exceptions = []
        self._command_ids = itertools.count()

        self.args = python2lua(self.lua, render_options.data)

        commands = {}
        for name in dir(self):
            value = getattr(self, name)
            if is_command(value):
                commands[name] = self.lua.table_from({
                    'is_async': getattr(value, '_is_async'),
                    'returns_error_flag': getattr(value, '_returns_error_flag', False),
                })
        self.commands = python2lua(self.lua, commands)
Example #4
0
 def test_list_modified_correct(self):
     func = self.lua.eval("""
     function (arr)
        table.insert(arr, "bar")
        return arr
     end
     """)
     arr = python2lua(self.lua, [3, 4])
     arr2 = func(arr)
     self.assertEqual(lua2python(self.lua, arr2), [3, 4, "bar"])
Example #5
0
 def test_list_modified_correct(self):
     func = self.lua.eval("""
     function (arr)
        table.insert(arr, "bar")
        return arr
     end
     """)
     arr = python2lua(self.lua, [3, 4])
     arr2 = func(arr)
     self.assertEqual(lua2python(self.lua, arr2), [3, 4, "bar"])
Example #6
0
 def test_list_modified_incorrect(self):
     func = self.lua.eval("""
     function (arr)
        arr["foo"] = "bar"
        return arr
     end
     """)
     arr = python2lua(self.lua, [3, 4])
     arr2 = func(arr)
     with pytest.raises(ValueError):
         lua2python(self.lua, arr2)
Example #7
0
 def test_list_modified_incorrect(self):
     func = self.lua.eval("""
     function (arr)
        arr["foo"] = "bar"
        return arr
     end
     """)
     arr = python2lua(self.lua, [3, 4])
     arr2 = func(arr)
     with pytest.raises(ValueError):
         lua2python(self.lua, arr2)
Example #8
0
    def test_sparse_list(self):
        func1 = self.lua.eval("""
        function (arr)
            arr[5] = "foo"
            return arr
        end
        """)
        func2 = self.lua.eval("""
        function (arr)
            arr[100000] = "foo"
            return arr
        end
        """)
        arr = python2lua(self.lua, [1, 2])
        arr1 = lua2python(self.lua, func1(arr))
        self.assertEqual(arr1, [1, 2, None, None, "foo"])

        with pytest.raises(ValueError):
            arr2 = lua2python(self.lua, func2(arr))
Example #9
0
    def test_sparse_list(self):
        func1 = self.lua.eval("""
        function (arr)
            arr[5] = "foo"
            return arr
        end
        """)
        func2 = self.lua.eval("""
        function (arr)
            arr[100000] = "foo"
            return arr
        end
        """)
        arr = python2lua(self.lua, [1, 2])
        arr1 = lua2python(self.lua, func1(arr))
        self.assertEqual(arr1, [1, 2, None, None, "foo"])

        with pytest.raises(ValueError):
            arr2 = lua2python(self.lua, func2(arr))
Example #10
0
 def assertSurvivesConversion(self, obj):
     lua_obj = python2lua(self.lua, obj)
     py_obj = lua2python(self.lua, lua_obj)
     self.assertEqual(obj, py_obj)
Example #11
0
 def wrapper(self, *args, **kwargs):
     res = meth(self, *args, **kwargs)
     return python2lua(self.lua, res)
Example #12
0
 def python2lua(self, obj, **kwargs):
     return python2lua(self.lua, obj, **kwargs)
Example #13
0
 def python2lua(self, obj, **kwargs):
     return python2lua(self.lua, obj, **kwargs)
Example #14
0
 def python2lua(self, *args, **kwargs):
     return python2lua(self._lua, *args, **kwargs)
Example #15
0
 def assertSurvivesConversion(self, obj, encoding='utf8'):
     lua_obj = python2lua(self.lua, obj, encoding=encoding)
     py_obj = lua2python(self.lua, lua_obj, encoding=encoding)
     self.assertEqual(obj, py_obj)
     self.assertEqual(obj.__class__, py_obj.__class__)
Example #16
0
 def wrapper(self, *args, **kwargs):
     res = meth(self, *args, **kwargs)
     return python2lua(self.lua, res)
Example #17
0
 def test_dict_recursive(self):
     dct = {}
     dct["x"] = dct
     with pytest.raises(ValueError):
         python2lua(self.lua, dct)
Example #18
0
 def assertSurvivesConversion(self, obj):
     lua_obj = python2lua(self.lua, obj)
     py_obj = lua2python(self.lua, lua_obj)
     self.assertEqual(obj, py_obj)
Example #19
0
 def assertSurvivesConversion(self, obj, encoding='utf8'):
     lua_obj = python2lua(self.lua, obj, encoding=encoding)
     py_obj = lua2python(self.lua, lua_obj, encoding=encoding)
     self.assertEqual(obj, py_obj)
     self.assertEqual(obj.__class__, py_obj.__class__)
Example #20
0
 def python2lua(self, *args, **kwargs):
     return python2lua(self._lua, *args, **kwargs)
Example #21
0
 def test_dict_recursive(self):
     dct = {}
     dct["x"] = dct
     with pytest.raises(ValueError):
         python2lua(self.lua, dct)
Example #22
0
 def wrapper(self, *args, **kwargs):
     res = meth(self, *args, **kwargs)
     if isinstance(res, tuple):
         return tuple(python2lua(self.lua, r) for r in res)
     else:
         return python2lua(self.lua, res)
Example #23
0
 def test_list_recursive(self):
     lst = []
     lst.append(lst)
     with pytest.raises(ValueError):
         python2lua(self.lua, lst)
Example #24
0
 def test_list_recursive(self):
     lst = []
     lst.append(lst)
     with pytest.raises(ValueError):
         python2lua(self.lua, lst)