Call the component by consuming args from args, and update the FireTrace. The component could be a class, a routine, or a callable object. This function calls the component and adds the appropriate action to component_trace. Args: component: The component to call args: Args for calli
(component, args, component_trace, treatment='class',
target=None)
| 650 | |
| 651 | |
| 652 | def _CallAndUpdateTrace(component, args, component_trace, treatment='class', |
| 653 | target=None): |
| 654 | """Call the component by consuming args from args, and update the FireTrace. |
| 655 | |
| 656 | The component could be a class, a routine, or a callable object. This function |
| 657 | calls the component and adds the appropriate action to component_trace. |
| 658 | |
| 659 | Args: |
| 660 | component: The component to call |
| 661 | args: Args for calling the component |
| 662 | component_trace: FireTrace object that contains action trace |
| 663 | treatment: Type of treatment used. Indicating whether we treat the component |
| 664 | as a class, a routine, or a callable. |
| 665 | target: Target in FireTrace element, default is None. If the value is None, |
| 666 | the component itself will be used as target. |
| 667 | Returns: |
| 668 | component: The object that is the result of the callable call. |
| 669 | remaining_args: The remaining args that haven't been consumed yet. |
| 670 | """ |
| 671 | if not target: |
| 672 | target = component |
| 673 | filename, lineno = inspectutils.GetFileAndLine(component) |
| 674 | metadata = decorators.GetMetadata(component) |
| 675 | fn = component.__call__ if treatment == 'callable' else component |
| 676 | parse = _MakeParseFn(fn, metadata) |
| 677 | (varargs, kwargs), consumed_args, remaining_args, capacity = parse(args) |
| 678 | |
| 679 | # Call the function. |
| 680 | if inspectutils.IsCoroutineFunction(fn): |
| 681 | loop = asyncio.get_event_loop() |
| 682 | component = loop.run_until_complete(fn(*varargs, **kwargs)) |
| 683 | else: |
| 684 | component = fn(*varargs, **kwargs) |
| 685 | |
| 686 | if treatment == 'class': |
| 687 | action = trace.INSTANTIATED_CLASS |
| 688 | elif treatment == 'routine': |
| 689 | action = trace.CALLED_ROUTINE |
| 690 | else: |
| 691 | action = trace.CALLED_CALLABLE |
| 692 | component_trace.AddCalledComponent( |
| 693 | component, target, consumed_args, filename, lineno, capacity, |
| 694 | action=action) |
| 695 | |
| 696 | return component, remaining_args |
| 697 | |
| 698 | |
| 699 | def _MakeParseFn(fn, metadata): |
no test coverage detected