<commit_before>#!/usr/bin/env python3

import sys
import copy
import json
import itertools
import copy
import os

#---------------------------------------------------
#            Imports and Variables                 -
#---------------------------------------------------
class standard:
    """
    Basic functionality built into the Udebs scripting language.
    None of the functions here can depend on any other Udebs module.
    """
    def _print(*args):
        print(*args)
        return True

    def logicif(cond, value, other):
        return value if cond else other

    def inside(before, after):
        return before in after

    def notin(before, after):
        return before not in after

    def equal(*args):
        x = args[0]
        for y in args:
            if y != x:
                return False
        return True

    def notequal(before, after):
        return before != after

    def gt(before, after):
        return before > after

    def lt(before, after):
        return before < after

    def gtequal(before, after):
        return before >= after

    def ltequal(before, after):
        return before <= after

    def plus(*args):
        return sum(args)

    def multiply(*args):
        i = 1
        for number in args:
            i *= number
        return i

    def logicor(*args):
        return any(args)

    def logicif(cond, value, other):
        return value if cond else other

    def mod(before, after):
        return before % after

    def setvar(storage, variable, value):
        storage[variable] = value
        return True

    #prefix functions
    def getvar(storage, variable):
        return storage[variable]

    def div(before, after):
        return before/after

    def logicnot(element):
        return not element

    def minus(before, element):
        return before - element

    def sub(before, after):
        return next(itertools.islice(before, int(after), None), 'empty')

    def length(list_):
        return len(list(list_))

    def quote(string):
        return UdebsStr(string)

class variables:
    modules = {
        1: [],
        2: [],
        "other": [],
    }
    env = {
        "__builtins__": {"abs": abs, "min": min, "max": max},
        "standard": standard,
        "storage": {},
    }
    default = {
        "f": "",
        "args": [],
        "kwargs": {},
        "all": False,
        "default": {},
         "string": [],
    }

    def keywords(version=1):
        found = {}
        for module in variables.modules[version]:
            found.update(module)

        for module in variables.modules["other"]:
            found.update(module)

        return found

def importModule(dicts={}, globs={}, version="other"):
    """
    Allows user to extend base variables available to the interpreter.
    Should be run before the instance object is created.
    """
    variables.modules[version].append(dicts)
    variables.env.update(globs)

def importSystemModule(name, globs={}):
    """Convenience script for import system keywords."""
    versions = [1,2]
    path = os.path.dirname(__file__)
    for version in versions:
        filename = "{}/keywords/{}-{}.json".format(path, name, str(version))
        with open(filename) as fp:
            importModule(json.load(fp), globs, version)

def _getEnv(local, glob=False):<commit_msg>Allow importModule to infer some names requireing less redundant input.<commit_after>#!/usr/bin/env python3

import sys
import copy
import json
import itertools
import os

#---------------------------------------------------
#            Imports and Variables                 -
#---------------------------------------------------
class standard:
    """
    Basic functionality built into the Udebs scripting language.
    None of the functions here can depend on any other Udebs module.
    """
    def _print(*args):
        print(*args)
        return True

    def logicif(cond, value, other):
        return value if cond else other

    def inside(before, after):
        return before in after

    def notin(before, after):
        return before not in after

    def equal(*args):
        x = args[0]
        for y in args:
            if y != x:
                return False
        return True

    def notequal(before, after):
        return before != after

    def gt(before, after):
        return before > after

    def lt(before, after):
        return before < after

    def gtequal(before, after):
        return before >= after

    def ltequal(before, after):
        return before <= after

    def plus(*args):
        return sum(args)

    def multiply(*args):
        i = 1
        for number in args:
            i *= number
        return i

    def logicor(*args):
        return any(args)

    def logicif(cond, value, other):
        return value if cond else other

    def mod(before, after):
        return before % after

    def setvar(storage, variable, value):
        storage[variable] = value
        return True

    #prefix functions
    def getvar(storage, variable):
        return storage[variable]

    def div(before, after):
        return before/after

    def logicnot(element):
        return not element

    def minus(before, element):
        return before - element

    def sub(before, after):
        return next(itertools.islice(before, int(after), None), 'empty')

    def length(list_):
        return len(list(list_))

    def quote(string):
        return UdebsStr(string)

class variables:
    modules = {
        1: [],
        2: [],
        "other": [],
    }
    env = {
        "__builtins__": {"abs": abs, "min": min, "max": max},
        "standard": standard,
        "storage": {},
    }
    default = {
        "f": "",
        "args": [],
        "kwargs": {},
        "all": False,
        "default": {},
         "string": [],
    }

    def keywords(version=1):
        found = {}
        for module in variables.modules[version]:
            found.update(module)

        for module in variables.modules["other"]:
            found.update(module)

        return found

def importModule(dicts={}, globs={}, version="other"):
    """
    Allows user to extend base variables available to the interpreter.
    Should be run before the instance object is created.    
    """
    if isinstance(globs, list):
        globs = {i.__name__: i for i in globs}
        
    elif not isinstance(globs, dict):
        globs = {globs.__name__: globs}
    
    variables.modules[version].append(dicts)
    variables.env.update(globs)

def importSystemModule(name, globs={}):
    """Convenience script for import system keywords."""
    versions = [1,2]
    path = os.path.dirname(__file__)
    for version in versions:
        filename = "{}/keywords/{}-{}.json".format(path, name, str(version))
        with open(filename) as fp:
            importModule(json.load(fp), globs, version)

def _getEnv(local, glob=False):
{'fraction_non_alphanumeric': 0.1371420348251547, 'fraction_numerical': 0.00230248956684415, 'mean_word_length': 1.9152684563758389, 'pattern_counts': {'":': 26, '<': 7, '<?xml version=': 0, '>': 7, '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': '5480317', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1861, 'n_words': 609}