def _readMacros(xmlCtx, section, valueName='value'): result = {} name = resource_helper.readItemName(xmlCtx, section) macros = _readItemMacros(xmlCtx, section) subCtx, subSection = resource_helper.getSubSection(xmlCtx, section, valueName) for nextCtx, nextSection in resource_helper.getIterator(subCtx, subSection): item = resource_helper.readItem(nextCtx, nextSection) if not item.name: raise resource_helper.ResourceError(nextCtx, '{0}: name is required in each item'.format(name)) result[item.name] = item.value return resource_helper.ResourceItem('macros', name, _MacrosValue(macros, result))
def _readConfig(ctx, root, parentTag, childTag, itemClass): ctx, section = resource_helper.getSubSection(ctx, root, parentTag, safe=True) if not section: return {} config = {} for xmlCtx, subSection in resource_helper.getIterator(ctx, section): item = resource_helper.readItem(xmlCtx, subSection, childTag) if not item.type == _ITEM_TYPE.DICT: raise AssertionError('Type of value should be dict') name = item.name raise name in config and resource_helper.ResourceError(xmlCtx, 'Item {0} is duplicated.'.format(name)) config[name] = itemClass(**item.value) return config
def _readConfig(ctx, root, parentTag, childTag, itemClass): ctx, section = resource_helper.getSubSection(ctx, root, parentTag, safe=True) if not section: return {} config = {} for xmlCtx, subSection in resource_helper.getIterator(ctx, section): item = resource_helper.readItem(xmlCtx, subSection, childTag) name = item.name if name in config: raise resource_helper.ResourceError( xmlCtx, 'Item {0} is duplicated.'.format(name)) config[name] = itemClass(**item.value) return config