Skip to content

Commit d404dac

Browse files
committed
relax the restrictions of pin name
1 parent ef4957f commit d404dac

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pywebio/pin.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@
141141
def check_name(name):
142142
assert all(i in _pin_name_chars for i in name), "pin `name` can only contain letters, digits, " \
143143
"minus sign and underscore"
144-
assert name != 'use_strict', "'use_strict' is a reserve name, can't use as pin widget name"
145-
assert name != '_strict', "'_strict' is a reserve name, can't use as pin widget name"
146144

147145

148146
def _pin_output(single_input_return, scope, position):
@@ -254,28 +252,28 @@ def use_strict(self):
254252
Enable strict mode for getting pin widget value.
255253
An AssertionError will be raised when try to get value of pin widgets that are currently not in the page.
256254
"""
257-
self._strict = True
255+
object.__setattr__(self, '_strict', True)
258256

259257
def __getattr__(self, name):
260258
"""__getattr__ is only invoked if the attribute wasn't found the usual ways"""
261-
check_name(name)
262-
return get_pin_value(name, self._strict)
259+
if name.startswith('__'):
260+
raise AttributeError('Pin object has no attribute %r' % name)
261+
return self.__getitem__(name)
263262

264263
def __getitem__(self, name):
265-
return self.__getattr__(name)
264+
check_name(name)
265+
return get_pin_value(name, self._strict)
266266

267267
def __setattr__(self, name, value):
268268
"""
269269
__setattr__ will be invoked regardless of whether the attribute be found
270270
"""
271-
if name == '_strict':
272-
return object.__setattr__(self, name, value)
273-
271+
assert name != 'use_strict', "'use_strict' is a reserve name, can't use as pin widget name"
274272
check_name(name)
275-
send_msg('pin_update', spec=dict(name=name, attributes={"value": value}))
273+
self.__setitem__(name, value)
276274

277275
def __setitem__(self, name, value):
278-
self.__setattr__(name, value)
276+
send_msg('pin_update', spec=dict(name=name, attributes={"value": value}))
279277

280278

281279
# pin widgets value getter (and setter).

0 commit comments

Comments
 (0)