Beispiel #1
0
        def func(*args, **kwargs):
            function_context = self._find_function_context(
                function_spec, context)
            parent_function_context = function_context.parent
            if parent_function_context is None:
                raise exceptions.NoFunctionRegisteredException(
                    function_spec.name)

            new_name = function_spec.name
            if self.with_name:
                new_name = args[0]
                args = args[1:]

            new_receiver = receiver
            if self.method is True:
                new_receiver = args[0]
                args = args[1:]
            elif self.method is False:
                new_receiver = utils.NO_VALUE

            if self.with_context:
                new_context = args[0]
                args = args[1:]
            else:
                new_context = context.create_child_context()

            return parent_function_context(new_name, engine, new_receiver,
                                           new_context)(*args, **kwargs)
Beispiel #2
0
def call(name, context, args, kwargs, engine, receiver=utils.NO_VALUE,
         data_context=None, use_convention=False, function_filter=None):

    if data_context is None:
        data_context = context

    if function_filter is None:
        function_filter = lambda fd, ctx: True

    if receiver is utils.NO_VALUE:
        predicate = lambda fd, ctx: fd.is_function and function_filter(fd, ctx)
    else:
        predicate = lambda fd, ctx: fd.is_method and function_filter(fd, ctx)

    all_overloads = context.collect_functions(
        name, predicate, use_convention=use_convention)

    if not all_overloads:
        if receiver is utils.NO_VALUE:
            raise exceptions.NoFunctionRegisteredException(name)
        else:
            raise exceptions.NoMethodRegisteredException(name, receiver)
    else:
        delegate = choose_overload(
            name, all_overloads, engine, receiver, data_context, args, kwargs)
        try:
            result = delegate()
            utils.limit_memory_usage(engine, (1, result))
            return result
        except StopIteration as e:
            six.reraise(
                exceptions.WrappedException,
                exceptions.WrappedException(e),
                sys.exc_info()[2])
Beispiel #3
0
 def _find_function_context(spec, context):
     while context is not None:
         if spec in context:
             return context
         context = context.parent
     raise exceptions.NoFunctionRegisteredException(spec.name)