Format `buttons` parameter in `put_buttons()`, replace its value with its idx :param buttons: {label:, value:, } (label, value, ) single value, label=value :return: [{value:, label:, }, ...], values
(buttons)
| 709 | |
| 710 | |
| 711 | def _format_button(buttons): |
| 712 | """ |
| 713 | Format `buttons` parameter in `put_buttons()`, replace its value with its idx |
| 714 | :param buttons: |
| 715 | {label:, value:, } |
| 716 | (label, value, ) |
| 717 | single value, label=value |
| 718 | |
| 719 | :return: [{value:, label:, }, ...], values |
| 720 | """ |
| 721 | |
| 722 | btns = [] |
| 723 | values = [] |
| 724 | for idx, btn in enumerate(buttons): |
| 725 | btn = copy.deepcopy(btn) |
| 726 | if isinstance(btn, Mapping): |
| 727 | assert 'value' in btn and 'label' in btn, 'actions item must have value and label key' |
| 728 | elif isinstance(btn, (list, tuple)): |
| 729 | assert len(btn) == 2, 'actions item format error' |
| 730 | btn = dict(zip(('label', 'value'), btn)) |
| 731 | else: |
| 732 | btn = dict(value=btn, label=btn) |
| 733 | values.append(btn['value']) |
| 734 | btn['value'] = idx |
| 735 | btns.append(btn) |
| 736 | return btns, values |
| 737 | |
| 738 | |
| 739 | def put_buttons(buttons: List[Union[Dict[str, Any], Tuple[str, Any], List, str]], |
no test coverage detected
searching dependent graphs…