Beispiel #1
0
def register_module(class_path, *modules, **kwds):
    module = sys.modules[class_path]
    registry = Registry(class_path, class_path=class_path, **kwds)

    for sub in modules:
        if isinstance(sub, six.string_types):
            registry.register(sub, sub.lower())
        else:
            registry.register(sub[1], sub[0].lower())

    return registry
Beispiel #2
0
def register_module(class_path, *modules, **kwds):
    module = sys.modules[class_path]
    registry = Registry(class_path, class_path=class_path, **kwds)

    for sub in modules:
        if isinstance(sub, six.string_types):
            registry.register(sub, sub.lower())
        else:
            registry.register(sub[1], sub[0].lower())

    return registry
Beispiel #3
0
class _SystemFunction(object):
    def __init__(self, function_maker, is_constant, needs_element):
        self.function = None
        self.function_maker = function_maker
        self.is_constant = is_constant
        self.needs_element = needs_element

    def prepare(self):
        if not self.function:
            self.function = self.function_maker()

    def evaluate(self, element):
        return self.function(element) if self.needs_element else self.function


_REGISTRY = Registry('System functions')


def register(name, function, is_constant, needs_element=False):
    _REGISTRY.register(_SystemFunction(function, is_constant, needs_element),
                       name)


def _elapsed(element):
    return element.elapsed_time()


def _level():
    from echomesh.sound import Level
    return Level.input_level()
Beispiel #4
0
from __future__ import absolute_import, division, print_function, unicode_literals

from echomesh.expression.parse import Functions
import echomesh.expression.parse.System
from echomesh.util import Call
from echomesh.util.registry.Registry import Registry

_REGISTRY = Registry('expression values')

def _get_value_function(value):
    parts = value.split('.')
    if len(parts) == 1:
        cmd = 'function'
    else:
        cmd = parts.pop(0)
    return _REGISTRY.function(cmd), parts

def is_constant(value, element):
    value_class, parts = _get_value_function(value)
    return value_class.is_constant(parts, element)

def evaluate(value, evaluator, element):
    value_class, parts = _get_value_function(value)
    return value_class.evaluate(parts, evaluator, element)

class ValueException(Exception):
    pass

class ValueRoot(object):
    def _get_function(self, parts, element):
        element = self._get_element(parts, element)
Beispiel #5
0
from __future__ import absolute_import, division, print_function, unicode_literals

from echomesh.expression.parse import Functions
import echomesh.expression.parse.System
from echomesh.util import Call
from echomesh.util.registry.Registry import Registry

_REGISTRY = Registry('expression values')


def _get_value_function(value):
    parts = value.split('.')
    if len(parts) == 1:
        cmd = 'function'
    else:
        cmd = parts.pop(0)
    return _REGISTRY.function(cmd), parts


def is_constant(value, element):
    value_class, parts = _get_value_function(value)
    return value_class.is_constant(parts, element)


def evaluate(value, evaluator, element):
    value_class, parts = _get_value_function(value)
    return value_class.evaluate(parts, evaluator, element)


class ValueException(Exception):
    pass