MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / _format_button

Function _format_button

pywebio/output.py:711–736  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

709
710
711def _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
739def put_buttons(buttons: List[Union[Dict[str, Any], Tuple[str, Any], List, str]],

Callers 1

put_buttonsFunction · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…