def extract_aspects_from_section(section): """ Extract aspects settings from a section into an AspectList. Note that the section is assumed to already have valid and complete aspects related setting. This checking could be done by :meth:`coalib.settings.ConfigurationGathering.validate_aspect_config`. :param section: Section object. :return: AspectList containing aspectclass instance with user-defined tastes. """ ASPECT_TASTE_DELIMITER = ':' aspects = section.get('aspects') language = section.language aspect_instances = AspectList(exclude=section.get('excludes')) for aspect in AspectList(aspects): # Search all related tastes in section. tastes = {name.split(ASPECT_TASTE_DELIMITER)[-1]: value for name, value in section.contents.items() if name.lower().startswith(aspect.__name__.lower())} aspect_instances.append(aspect(language, **tastes)) return aspect_instances
def extract_aspects_from_section(section): """ Extract aspects settings from a section into an AspectList. Note that the section is assumed to already have valid and complete aspects related setting. This checking could be done by :meth:`coalib.settings.ConfigurationGathering.validate_aspect_config`. :param section: Section object. :return: AspectList containing aspectclass instance with user-defined tastes. """ ASPECT_TASTE_DELIMITER = ':' aspects = section.get('aspects') language = section.language aspect_instances = AspectList(exclude=section.get('excludes')) for aspect in AspectList(aspects): # Search all related tastes in section. tastes = { name.split(ASPECT_TASTE_DELIMITER)[-1]: value for name, value in section.contents.items() if name.lower().startswith(aspect.__name__.lower()) } aspect_instances.append(aspect(language, **tastes)) return aspect_instances
def extract_aspects_from_section(section): """ Extracts aspects and their related settings from a section and create an AspectList from it. :param section: Section object. :return: AspectList containing aspectclass instance with user-defined tastes. """ aspects = section.get('aspects') language = section.get('language') # Skip aspects initialization if not configured in section if not len(aspects): return None if not len(language): raise AttributeError('Language was not found in configuration file. ' 'Usage of aspect-based configuration must ' 'include language information.') aspect_instances = AspectList(exclude=section.get('excludes')) for aspect in AspectList(aspects): # Search all related tastes in section. tastes = { name.split('.')[-1]: value for name, value in section.contents.items() if name.lower().startswith(aspect.__name__.lower()) } aspect_instances.append(aspect(language, **tastes)) return aspect_instances