Beispiel #1
0
    def _startgen(self, chained):
        """
        Obtain a flow variant from the chain iterator and call the
        flow function. Note that a flow function is a generator if it
        contains a yield statement, and an ordinary function
        otherwise.

        @param chained True if this is a chained (second or
        subsequent) invocation.

        @return The result of the call to the flow function (an
        iterator or None).

        @throws TypeError When chained is false, node parameters that
        are neither matched by patterns nor accepted as arguments by
        the flow function cause a TypeError.
        """
        try:
            flow = next(self._flowiter)
        except StopIteration:
            return None
        function = flow.function
        kwargs = {}
        for key in self._attrs:
            if util.takesArgument(function, key):
                kwargs[key] = self._attrs[key]
            elif not chained and key not in flow.patterns:
                raise TypeError(
                    "{f}() got an unexpected keyword argument '{arg}'".format(
                        f=function.func_name, arg=key))
        with self:
            return function(self, **kwargs)
Beispiel #2
0
    def _startgen(self, chained):
        """
        Obtain a flow variant from the chain iterator and call the
        flow function. Note that a flow function is a generator if it
        contains a yield statement, and an ordinary function
        otherwise.

        @param chained True if this is a chained (second or
        subsequent) invocation.

        @return The result of the call to the flow function (an
        iterator or None).

        @throws TypeError When chained is false, node parameters that
        are neither matched by patterns nor accepted as arguments by
        the flow function cause a TypeError.
        """
        try:
            flow = next(self._flowiter)
        except StopIteration:
            return None
        function = flow.function
        kwargs = {}
        for key in self._attrs:
            if util.takesArgument(function, key):
                kwargs[key] = self._attrs[key]
            elif not chained and key not in flow.patterns:
                raise TypeError("{f}() got an unexpected keyword argument '{arg}'".format(f=function.func_name, arg=key))
        with self:
            return function(self, **kwargs)
Beispiel #3
0
    def _invoke(self, function, context):
        """
        Call a configuration function or method.

        @param function The configuration function or method.

        @param context The context which should provide values for the
        callable's keyword arguments.
        """
        if context is not currentContext():
            with context:
                return self._invoke(function, context)
        params = {}
        for key in context:
            if util.takesArgument(function, key):
                params[key] = context[key]
        return function(**params)
Beispiel #4
0
    def _invoke(self, function, context):
        """
        Call a configuration function or method.

        @param function The configuration function or method.

        @param context The context which should provide values for the
        callable's keyword arguments.
        """
        if context is not currentContext():
            with context:
                return self._invoke(function, context)
        params = {}
        for key in context:
            if util.takesArgument(function, key):
                params[key] = context[key]
        return function(**params)