Returns a subcomponent of component by consuming an arg from args. Given a starting component and args, this function gets a member from that component, consuming one arg in the process. Args: component: The component from which to get a member. args: Args from which to consume in th
(component, args)
| 620 | |
| 621 | |
| 622 | def _GetMember(component, args): |
| 623 | """Returns a subcomponent of component by consuming an arg from args. |
| 624 | |
| 625 | Given a starting component and args, this function gets a member from that |
| 626 | component, consuming one arg in the process. |
| 627 | |
| 628 | Args: |
| 629 | component: The component from which to get a member. |
| 630 | args: Args from which to consume in the search for the next component. |
| 631 | Returns: |
| 632 | component: The component that was found by consuming an arg. |
| 633 | consumed_args: The args that were consumed by getting this member. |
| 634 | remaining_args: The remaining args that haven't been consumed yet. |
| 635 | Raises: |
| 636 | FireError: If we cannot consume an argument to get a member. |
| 637 | """ |
| 638 | members = dir(component) |
| 639 | arg = args[0] |
| 640 | arg_names = [ |
| 641 | arg, |
| 642 | arg.replace('-', '_'), # treat '-' as '_'. |
| 643 | ] |
| 644 | |
| 645 | for arg_name in arg_names: |
| 646 | if arg_name in members: |
| 647 | return getattr(component, arg_name), [arg], args[1:] |
| 648 | |
| 649 | raise FireError('Could not consume arg:', arg) |
| 650 | |
| 651 | |
| 652 | def _CallAndUpdateTrace(component, args, component_trace, treatment='class', |