def __call__(self,
client: Client,
datatype: str,
datavalue: Mapping[str, object]) -> object:
try:
type_ = datavalue['type']
except KeyError:
raise DatavalueError('no "type" specified', datavalue)
assert isinstance(type_, str)
if 'value' not in datavalue:
raise DatavalueError('no "value" field', datavalue)
method_name = '{}__{}'.format(datatype, type_).replace('-', '_')
method = getattr(self, method_name, None)
if callable(method):
return method(client, datavalue)
method_name = type_.replace('-', '_')
method = getattr(self, method_name, None)
if callable(method):
return method(client, datavalue)
raise DatavalueError('{!r} is unsupported type'.format(type_),
datavalue)
评论列表
文章目录