Browse Source

deep copy parameters `options` and `buttons` of input functions

wangweimin 3 years ago
parent
commit
81d57ba46b
1 changed files with 3 additions and 1 deletions
  1. 3 1
      pywebio/input.py

+ 3 - 1
pywebio/input.py

@@ -75,6 +75,7 @@ Functions doc
 import os.path
 import os.path
 import logging
 import logging
 from collections.abc import Mapping
 from collections.abc import Mapping
+import copy
 
 
 from .io_ctrl import single_input, input_control, output_register_callback, send_msg, single_input_kwargs
 from .io_ctrl import single_input, input_control, output_register_callback, send_msg, single_input_kwargs
 from .session import get_current_session, get_current_task_id
 from .session import get_current_session, get_current_task_id
@@ -299,6 +300,7 @@ def _parse_select_options(options):
     # value (label same as value)
     # value (label same as value)
     opts_res = []
     opts_res = []
     for opt in options:
     for opt in options:
+        opt = copy.deepcopy(opt)
         if isinstance(opt, Mapping):
         if isinstance(opt, Mapping):
             assert 'value' in opt and 'label' in opt, 'options item must have value and label key'
             assert 'value' in opt and 'label' in opt, 'options item must have value and label key'
         elif isinstance(opt, (list, tuple)):
         elif isinstance(opt, (list, tuple)):
@@ -306,7 +308,6 @@ def _parse_select_options(options):
             opt = dict(zip(('label', 'value', 'selected', 'disabled'), opt))
             opt = dict(zip(('label', 'value', 'selected', 'disabled'), opt))
         else:
         else:
             opt = dict(value=opt, label=opt)
             opt = dict(value=opt, label=opt)
-        opt['value'] = opt['value']
         opts_res.append(opt)
         opts_res.append(opt)
 
 
     return opts_res
     return opts_res
@@ -430,6 +431,7 @@ def _parse_action_buttons(buttons):
     """
     """
     act_res = []
     act_res = []
     for act in buttons:
     for act in buttons:
+        act = copy.deepcopy(act)
         if isinstance(act, Mapping):
         if isinstance(act, Mapping):
             assert 'label' in act, 'actions item must have label key'
             assert 'label' in act, 'actions item must have label key'
             assert 'value' in act or act.get('type', 'submit') != 'submit' or act.get('disabled'), \
             assert 'value' in act or act.get('type', 'submit') != 'submit' or act.get('disabled'), \