131131from pywebio .output import _get_output_spec
132132from .io_ctrl import send_msg , single_input_kwargs , output_register_callback
133133from .session import next_client_event , chose_impl
134+ from .utils import check_dom_name_value
134135
135136_pin_name_chars = set (string .ascii_letters + string .digits + '_-' )
136137
137138__all__ = ['put_input' , 'put_textarea' , 'put_select' , 'put_checkbox' , 'put_radio' , 'put_slider' , 'put_actions' ,
138139 'pin' , 'pin_update' , 'pin_wait_change' , 'pin_on_change' ]
139140
140141
141- def check_name (name ):
142- assert all (i in _pin_name_chars for i in name ), "pin `name` can only contain letters, digits, " \
143- "minus sign and underscore"
144142
145143
146144def _pin_output (single_input_return , scope , position ):
@@ -153,7 +151,7 @@ def put_input(name, type='text', *, label='', value=None, placeholder=None, read
153151 help_text = None , scope = None , position = OutputPosition .BOTTOM ) -> Output :
154152 """Output an input widget. Refer to: `pywebio.input.input()`"""
155153 from pywebio .input import input
156- check_name (name )
154+ check_dom_name_value (name , 'pin `name`' )
157155 single_input_return = input (name = name , label = label , value = value , type = type , placeholder = placeholder ,
158156 readonly = readonly , datalist = datalist , help_text = help_text )
159157 return _pin_output (single_input_return , scope , position )
@@ -163,7 +161,7 @@ def put_textarea(name, *, label='', rows=6, code=None, maxlength=None, minlength
163161 readonly = None , help_text = None , scope = None , position = OutputPosition .BOTTOM ) -> Output :
164162 """Output a textarea widget. Refer to: `pywebio.input.textarea()`"""
165163 from pywebio .input import textarea
166- check_name (name )
164+ check_dom_name_value (name , 'pin `name`' )
167165 single_input_return = textarea (
168166 name = name , label = label , rows = rows , code = code , maxlength = maxlength ,
169167 minlength = minlength , value = value , placeholder = placeholder , readonly = readonly , help_text = help_text )
@@ -174,7 +172,7 @@ def put_select(name, options=None, *, label='', multiple=None, value=None, help_
174172 scope = None , position = OutputPosition .BOTTOM ) -> Output :
175173 """Output a select widget. Refer to: `pywebio.input.select()`"""
176174 from pywebio .input import select
177- check_name (name )
175+ check_dom_name_value (name , 'pin `name`' )
178176 single_input_return = select (name = name , options = options , label = label , multiple = multiple ,
179177 value = value , help_text = help_text )
180178 return _pin_output (single_input_return , scope , position )
@@ -184,7 +182,7 @@ def put_checkbox(name, options=None, *, label='', inline=None, value=None, help_
184182 scope = None , position = OutputPosition .BOTTOM ) -> Output :
185183 """Output a checkbox widget. Refer to: `pywebio.input.checkbox()`"""
186184 from pywebio .input import checkbox
187- check_name (name )
185+ check_dom_name_value (name , 'pin `name`' )
188186 single_input_return = checkbox (name = name , options = options , label = label , inline = inline , value = value ,
189187 help_text = help_text )
190188 return _pin_output (single_input_return , scope , position )
@@ -194,7 +192,7 @@ def put_radio(name, options=None, *, label='', inline=None, value=None, help_tex
194192 scope = None , position = OutputPosition .BOTTOM ) -> Output :
195193 """Output a radio widget. Refer to: `pywebio.input.radio()`"""
196194 from pywebio .input import radio
197- check_name (name )
195+ check_dom_name_value (name , 'pin `name`' )
198196 single_input_return = radio (name = name , options = options , label = label , inline = inline , value = value ,
199197 help_text = help_text )
200198 return _pin_output (single_input_return , scope , position )
@@ -204,7 +202,7 @@ def put_slider(name, *, label='', value=0, min_value=0, max_value=100, step=1, r
204202 scope = None , position = OutputPosition .BOTTOM ) -> Output :
205203 """Output a slide widget. Refer to: `pywebio.input.slider()`"""
206204 from pywebio .input import slider
207- check_name (name )
205+ check_dom_name_value (name , 'pin `name`' )
208206 single_input_return = slider (name = name , label = label , value = value , min_value = min_value , max_value = max_value ,
209207 step = step , required = required , help_text = help_text )
210208 return _pin_output (single_input_return , scope , position )
@@ -220,7 +218,7 @@ def put_actions(name, *, label='', buttons=None, help_text=None,
220218 .. versionadded:: 1.4
221219 """
222220 from pywebio .input import actions
223- check_name (name )
221+ check_dom_name_value (name , 'pin `name`' )
224222 single_input_return = actions (name = name , label = label , buttons = buttons , help_text = help_text )
225223 input_kwargs = single_input_kwargs (single_input_return )
226224 for btn in input_kwargs ['item_spec' ]['buttons' ]:
@@ -329,7 +327,7 @@ def pin_update(name, **spec):
329327 :param spec: The pin widget parameters need to be updated.
330328 Note that those parameters can not be updated: ``type``, ``name``, ``code``, ``multiple``
331329 """
332- check_name (name )
330+ check_dom_name_value (name , 'pin `name`' )
333331 attributes = parse_input_update_spec (spec )
334332 send_msg ('pin_update' , spec = dict (name = name , attributes = attributes ))
335333
0 commit comments