Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
(cashost, casport, casprotocol)
'''
cashost = None
casport = None
casprotocol = None
if not os.path.isfile(path):
return cashost, casport, casprotocol
try:
from lupa import LuaRuntime
lua = LuaRuntime()
lua.eval('dofile("%s")' % path)
lg = lua.globals()
except ImportError:
import subprocess
import tempfile
lua_script = tempfile.TemporaryFile(mode='w')
lua_script.write('''
if arg[1] then
dofile(arg[1])
for name, value in pairs(_G) do
if name:match('cas') then
print(name .. ' ' .. tostring(value))
end
end
def test_redislua_with_command_error_call():
k = Keyspace()
lua_runtime = LuaRuntime(unpack_returned_tuples=True)
redis_lua = RedisLua(k, lua_runtime)
with pytest.raises(RedisScriptError) as exc:
redis_lua.call('cmd_not_found')
assert str(exc.value) == '@user_script: Unknown Redis command called from Lua script'
def test_redislua_with_error_call():
k = Keyspace()
lua_runtime = LuaRuntime(unpack_returned_tuples=True)
redis_lua = RedisLua(k, lua_runtime)
with pytest.raises(RedisScriptError) as exc:
redis_lua.call('GET')
assert str(exc.value) == "wrong number of arguments for 'get' command"
def test_redislua_with_command_error_pcall():
k = Keyspace()
lua_runtime = LuaRuntime(unpack_returned_tuples=True)
redis_lua = RedisLua(k, lua_runtime)
table = redis_lua.pcall('cmd_not_found')
assert table['err'] == '@user_script: Unknown Redis command called from Lua script'
def test_redislua_return_lua_types_pcall():
k = Keyspace()
lua_runtime = LuaRuntime(unpack_returned_tuples=True)
redis_lua = RedisLua(k, lua_runtime)
lua_script = """return {'test', true, false, 10, 20.3, {'another string'}, redis.call('ping')}"""
table = redis_lua.pcall('EVAL', lua_script, 0, [])
assert table[1] == 'test'
assert table[2] == 1
assert table[3] is False
assert table[4] == 10
assert table[5] == 20
assert table[6][1] == 'another string'
assert table[7] == 'PONG'
def test_redislua_with_error_pcall():
k = Keyspace()
lua_runtime = LuaRuntime(unpack_returned_tuples=True)
redis_lua = RedisLua(k, lua_runtime)
table = redis_lua.pcall('GET')
assert table['err'] == "wrong number of arguments for 'get' command"
def test_redislua_return_lua_types_call():
k = Keyspace()
lua_runtime = LuaRuntime(unpack_returned_tuples=True)
redis_lua = RedisLua(k, lua_runtime)
lua_script = """return {'test', true, false, 10, 20.3, {'another string'}, redis.call('ping')}"""
table = redis_lua.call('EVAL', lua_script, 0, [])
assert table[1] == 'test'
assert table[2] == 1
assert table[3] is False
assert table[4] == 10
assert table[5] == 20
assert table[6][1] == 'another string'
assert table[7] == 'PONG'
import requests
from runtime import base64
from runtime import json
from runtime import http
from runtime import mail
__all__ = """
base64
json
http
mail
""".split()
try:
lua = lupa.LuaRuntime()
except:
pass # for local debugging without lupa
def _export_globals():
d = dict()
for k in __all__:
d[k] = globals()[k]
return d
def make_table(dict):
return lua.eval("""
function(d)
local t = {}
for key, value in python.iterex(d.items()) do
t[key] = value
end
def luaInit(self):
self.lua = LuaRuntime()
############ FOR TEST ############
PROJPATH = ProjectController().path.replace(QDir.separator(),"/")
BUILDPATH = PROJPATH + u"/build/?.lua;"
BUILDPATH1 = PROJPATH + u"/build/scene/?.lua;"
BUILDPATH2 = PROJPATH + u"/build/module/?.lua;"
BUILDPATH = BUILDPATH.encode(os_encoding.cp())
BUILDPATH1 = BUILDPATH1.encode(os_encoding.cp())
BUILDPATH2 = BUILDPATH2.encode(os_encoding.cp())
self.lua.execute("package.path = \"\"")
self.lua.execute("function packagePath(path) package.path = package.path .. ';'..path end")
self.lua.globals().packagePath(BUILDPATH)
self.lua.globals().packagePath(BUILDPATH1)
self.lua.globals().packagePath(BUILDPATH2)
def init(self, func, *args):
# HACK: should not directly reference lupa here
import lupa
if lupa.lua_type(args) == 'table':
args = args.values()
print ('Expression: ', func, args)
self.func = func
self.args = list(args)
self.output = Signal()
# Workaround for list event bug
self.input = self.args[0]