本文整理汇总了Python中mpf.system.utility_functions.Util.event_config_to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Util.event_config_to_dict方法的具体用法?Python Util.event_config_to_dict怎么用?Python Util.event_config_to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpf.system.utility_functions.Util
的用法示例。
在下文中一共展示了Util.event_config_to_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_item
# 需要导入模块: from mpf.system.utility_functions import Util [as 别名]
# 或者: from mpf.system.utility_functions.Util import event_config_to_dict [as 别名]
def validate_item(self, item, validator, validation_failure_info):
try:
if item.lower() == 'none':
item = None
except AttributeError:
pass
if ':' in validator:
validator = validator.split(':')
# item could be str, list, or list of dicts
item = Util.event_config_to_dict(item)
return_dict = dict()
for k, v in item.iteritems():
return_dict[self.validate_item(k, validator[0],
validation_failure_info)] = (
self.validate_item(v, validator[1], validation_failure_info)
)
item = return_dict
elif '%' in validator:
if type(item) is str:
try:
item = eval(validator.replace('%', "'" + item + "'"))
except KeyError:
self.validation_error(item, validation_failure_info)
else:
item = None
elif validator == 'str':
if item is not None:
item = str(item)
else:
item = None
elif validator == 'float':
try:
item = float(item)
except (TypeError, ValueError):
# TODO error
pass
elif validator == 'int':
try:
item = int(item)
except (TypeError, ValueError):
# TODO error
pass
elif validator in ('bool', 'boolean'):
if type(item) is str:
if item.lower() in ['false', 'f', 'no', 'disable', 'off']:
item = False
elif not item:
item = False
else:
item = True
elif validator == 'ms':
item = Timing.string_to_ms(item)
elif validator == 'secs':
item = Timing.string_to_secs(item)
elif validator == 'ticks':
item = Timing.string_to_ticks(item)
elif validator == 'ticks_int':
item = int(Timing.string_to_ticks(item))
else:
self.log.error("Invalid Validator '%s' in config spec %s:%s",
validator,
validation_failure_info[0][0],
validation_failure_info[1])
sys.exit()
return item