Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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"])
Beispiel #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"])
Beispiel #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)
Beispiel #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)
Beispiel #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))
Beispiel #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))
Beispiel #10
0
 def assertSurvivesConversion(self, obj):
     lua_obj = python2lua(self.lua, obj)
     py_obj = lua2python(self.lua, lua_obj)
     self.assertEqual(obj, py_obj)
Beispiel #11
0
 def wrapper(self, *args, **kwargs):
     res = meth(self, *args, **kwargs)
     return python2lua(self.lua, res)
Beispiel #12
0
 def python2lua(self, obj, **kwargs):
     return python2lua(self.lua, obj, **kwargs)
Beispiel #13
0
 def python2lua(self, obj, **kwargs):
     return python2lua(self.lua, obj, **kwargs)
Beispiel #14
0
 def python2lua(self, *args, **kwargs):
     return python2lua(self._lua, *args, **kwargs)
Beispiel #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__)
Beispiel #16
0
 def wrapper(self, *args, **kwargs):
     res = meth(self, *args, **kwargs)
     return python2lua(self.lua, res)
Beispiel #17
0
 def test_dict_recursive(self):
     dct = {}
     dct["x"] = dct
     with pytest.raises(ValueError):
         python2lua(self.lua, dct)
Beispiel #18
0
 def assertSurvivesConversion(self, obj):
     lua_obj = python2lua(self.lua, obj)
     py_obj = lua2python(self.lua, lua_obj)
     self.assertEqual(obj, py_obj)
Beispiel #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__)
Beispiel #20
0
 def python2lua(self, *args, **kwargs):
     return python2lua(self._lua, *args, **kwargs)
Beispiel #21
0
 def test_dict_recursive(self):
     dct = {}
     dct["x"] = dct
     with pytest.raises(ValueError):
         python2lua(self.lua, dct)
Beispiel #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)
Beispiel #23
0
 def test_list_recursive(self):
     lst = []
     lst.append(lst)
     with pytest.raises(ValueError):
         python2lua(self.lua, lst)
Beispiel #24
0
 def test_list_recursive(self):
     lst = []
     lst.append(lst)
     with pytest.raises(ValueError):
         python2lua(self.lua, lst)