<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
import os

from splash.lua import lua2python, python2lua, get_new_runtime


class SplashLuaRuntime(object):
    """
    Lua runtime wrapper, optionally with a sandbox.
    """
    def __init__(self, sandboxed, lua_package_path, lua_sandbox_allowed_modules):
        """
        :param bool sandboxed: whether the runtime 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._sandboxed = sandboxed
        self._lua = self._create_runtime(lua_package_path)
        self._setup_lua_sandbox(lua_sandbox_allowed_modules)
        self._allowed_object_attrs = {}

    def add_to_globals(self, name, value):
        code = "function(%s_) %s = %s_ end" % (name, name, name)
        self.eval(code)(value)

    def table_from(self, *args, **kwargs):
        return self._lua.table_from(*args, **kwargs)

    def eval(self, *args, **kwargs):<commit_msg>make life easier for GC<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import weakref

from splash.lua import lua2python, python2lua, get_new_runtime


class SplashLuaRuntime(object):
    """
    Lua runtime wrapper, optionally with a sandbox.
    """
    def __init__(self, sandboxed, lua_package_path, lua_sandbox_allowed_modules):
        """
        :param bool sandboxed: whether the runtime 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._sandboxed = sandboxed
        self._lua = self._create_runtime(lua_package_path)
        self._setup_lua_sandbox(lua_sandbox_allowed_modules)
        self._allowed_object_attrs = weakref.WeakKeyDictionary()

    def add_to_globals(self, name, value):
        code = "function(%s_) %s = %s_ end" % (name, name, name)
        self.eval(code)(value)

    def table_from(self, *args, **kwargs):
        return self._lua.table_from(*args, **kwargs)

    def eval(self, *args, **kwargs):
{'fraction_non_alphanumeric': 0.09521700620017715, 'fraction_numerical': 0.002657218777679362, 'mean_word_length': 3.262264150943396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4473408', 'n_tokens_mistral': 714, 'n_tokens_neox': 678, 'n_words': 188}