How to use the lupa.LuaError function in lupa

To help you get started, we’ve selected a few lupa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tenrec-Builders / pi-scan / src / camera_chdk.py View on Github external
def search():
  result = []
  try:
    devices = chdkptp.list_devices()
    if devices is not None:
      for info in chdkptp.list_devices():
        if info.chdk_api[0] != -1 or info.chdk_api[1] != -1:
          result.append(info)
  except LuaError as e:
    errorlog.write('Failed to search: LuaError: ' + str(e.args) + '\nTraceback: ' + traceback.format_exc())
  except chdkptp.PTPError as e:
    errorlog.write('Failed to search: PTPError: ' + str(e.args) + '\n' + traceback.format_exc() + '\nPTP Traceback:\n' + e.traceback)
  except Exception as e:
    errorlog.write('Failed to search: ' + str(e.args) + '\n' + traceback.format_exc())
  return result
github jamesls / fakeredis / fakeredis / _server.py View on Github external
ARGV = argv
            end
            """
        )
        expected_globals = set()
        set_globals(
            lua_runtime.table_from(keys_and_args[:numkeys]),
            lua_runtime.table_from(keys_and_args[numkeys:]),
            functools.partial(self._lua_redis_call, lua_runtime, expected_globals),
            functools.partial(self._lua_redis_pcall, lua_runtime, expected_globals)
        )
        expected_globals.update(lua_runtime.globals().keys())

        try:
            result = lua_runtime.execute(script)
        except LuaError as ex:
            raise redis.ResponseError(str(ex))

        self._check_for_lua_globals(lua_runtime, expected_globals)

        return self._convert_lua_result(result, nested=False)
github rjgtav / tos-database / tos-parser / src / utils / luautil.py View on Github external
line = re.sub(r'\[\"(\w*?)\"\]', r"['\1']", line)  # Replace double quote with single quote
                            line = re.sub(r'local \w+ = require[ (]["\']\w+["\'][ )]*', '', line)  # Remove require statements
                            line = re.sub(r'function (\w+):(\w+)\((.*)\)', r'function \1.\2(\3)', line)  # Replace function a:b with function a.b

                            if len(line) == 0:
                                continue

                            if bool(re.match(r'(local\s+)?function\s+[\w.:]+\(.*?\)', line)):
                                lua_function_load(lua_function)
                                lua_function = []

                            lua_function.append(line)

                        lua_function_load(lua_function)

                    except LuaError as error:
                        # logging.warn('Failed to load %s, error: %s...', file_path, error)
                        continue
github scrapinghub / splash / splash / lua.py View on Github external
def is_supported():
    """ Return True if Lua scripting is supported """
    global _supported
    if _supported is not None:
        return _supported

    try:
        import lupa
    except ImportError:
        log.msg("WARNING: Lua scripting is not available because 'lupa' Python package is not installed")
        _supported = False
        return False

    try:
        lua = lupa.LuaRuntime()
    except lupa.LuaError as e:
        log.msg("WARNING: Lua scripting is not available: %r" % e)
        _supported = False
        return False

    _supported = True
    return True
github scrapinghub / splash / splash / kernel / kernel.py View on Github external
# line numbers to be displayed properly!
                lua_source = 'local repr = require("repr"); function main(splash) return repr(%s) end' % code
                main_coro = self._get_main(lua_source)
            except lupa.LuaSyntaxError:
                try:
                    lines = code.splitlines(False)
                    lua_source = '''local repr = require("repr"); function main(splash) %s
                        return repr(%s)
                    end
                    ''' % ("\n".join(lines[:-1]), lines[-1])
                    main_coro = self._get_main(lua_source)
                except lupa.LuaSyntaxError:
                    lua_source = "function main(splash) %s end" % code
                    main_coro = self._get_main(lua_source)

        except (lupa.LuaSyntaxError, lupa.LuaError) as e:
            d = defer.Deferred()
            d.addCallbacks(success, error)
            d.errback(e)
            return d
        except Exception:
            d = defer.Deferred()
            d.addCallbacks(success, error)
            d.errback()
            return d

        d = self.runner.run(main_coro)
        d.addCallbacks(success, error)
        return d
github jamesls / fakeredis / fakeredis_old.py View on Github external
ARGV = argv
            end
            """
        )
        expected_globals = set()
        set_globals(
            lua_runtime.table_from(keys_and_args[:numkeys]),
            lua_runtime.table_from(keys_and_args[numkeys:]),
            functools.partial(self._lua_redis_call, lua_runtime, expected_globals),
            functools.partial(self._lua_redis_pcall, lua_runtime, expected_globals)
        )
        expected_globals.update(lua_runtime.globals().keys())

        try:
            result = lua_runtime.execute(script)
        except LuaError as ex:
            raise ResponseError(ex)

        self._check_for_lua_globals(lua_runtime, expected_globals)

        return self._convert_lua_result(result, nested=False)
github scrapinghub / splash / splash / lua_runner.py View on Github external
except lupa.LuaError as lua_ex:
                    # Error converting result to Python
                    # This may happen e.g. if conversion hit sandbox limits
                    self.log("[lua_runner] caught LuaError %r" % lua_ex)
                    info = parse_error_message(lua_ex.args[0])
                    error = info.get('error', '?')
                    raise ScriptError({
                        "type": ScriptError.LUA_CONVERT_ERROR,
                        "error": error,
                        "message": "Lua error: {!s}".format(error)
                    })

                self._print_instructions_used()
                self.on_result(res)
                return
            except lupa.LuaError as lua_ex:
                # import traceback
                # print(traceback.format_exc())

                # Lua script raised an error
                self._print_instructions_used()
                self.log("[lua_runner] caught LuaError %r" % lua_ex)

                # this can raise a ScriptError
                self.on_lua_error(lua_ex)

                # ScriptError is not raised, construct it ourselves
                info = parse_error_message(lua_ex.args[0])
                info.update({
                    "type": ScriptError.LUA_ERROR,
                    "message": "Lua error: {!s}".format(lua_ex)
                })
github rjgtav / tos-database / tos-parser / src / parserr / parser_items_equipment.py View on Github external
item_grade = equipment_grade_ratios[int(row['ItemGrade'])]
        item_type_equipment = TOSEquipmentType.value_of(row['ClassType'].upper())
        obj = globals.equipment[int(row['ClassID'])]

        # Calculate all properties using in-game formulas
        tooltip_script = row['RefreshScp']
        tooltip_script = 'SCR_REFRESH_ACC' if not tooltip_script and 'Accessory_' in row['MarketCategory'] else tooltip_script
        tooltip_script = 'SCR_REFRESH_ARMOR' if not tooltip_script and 'Armor_' in row['MarketCategory'] else tooltip_script
        tooltip_script = 'SCR_REFRESH_HAIRACC' if not tooltip_script and 'HairAcc_' in row['MarketCategory'] else tooltip_script
        tooltip_script = 'SCR_REFRESH_WEAPON' if not tooltip_script and ('Weapon_' in row['MarketCategory'] or 'ChangeEquip_' in row['MarketCategory']) else tooltip_script

        if tooltip_script:
            try:
                LUA_RUNTIME[tooltip_script](row)
            except LuaError as error:
                if row['ClassID'] not in ['11130', '635061']:
                    logging.error('LUA error when processing item ClassID: %s', row['ClassID'])
                    raise error

        # Add additional fields
        obj['AnvilATK'] = []
        obj['AnvilDEF'] = []
        obj['AnvilPrice'] = []
        obj['Bonus'] = []
        obj['Durability'] = int(row['MaxDur']) / 100
        obj['Durability'] = -1 if obj['Durability'] <= 0 else obj['Durability']
        obj['Grade'] = TOSEquipmentGrade.value_of(int(row['ItemGrade']))
        obj['Level'] = int(row['ItemLv']) if int(row['ItemLv']) > 0 else int(row['UseLv'])
        obj['Material'] = TOSEquipmentMaterial.value_of(row['Material'])
        obj['Potential'] = int(row['MaxPR'])
        obj['RequiredClass'] = '%s%s%s%s%s' % (

lupa

Python wrapper around Lua and LuaJIT

MIT
Latest version published 6 months ago

Package Health Score

80 / 100
Full package analysis

Similar packages