def _get_loaded_template(self):
"""
Converts template document to dict replacing entities UIDs with objects
:return: dict -> loaded YAML document
"""
if hasattr(self, '_loaded_template'):
return self._loaded_template
preprocessed = self._get_preprocessed_template()
class CustomLoader(yaml.SafeLoader):
pass
class TemplateObject(yaml.YAMLObject):
yaml_tag = '!kd'
yaml_loader = CustomLoader
@classmethod
def from_yaml(cls, loader, node):
return self._entities_by_uid[loader.construct_scalar(node)]
patt = re.compile(r'^(?:{0})$'.format('|'.join(self._entities_by_uid)))
CustomLoader.add_implicit_resolver('!kd', patt, None)
try:
self._loaded_template = yaml.load(preprocessed,
Loader=CustomLoader)
except (yaml.scanner.ScannerError, yaml.parser.ParserError):
raise PredefinedAppExc.UnparseableTemplate
return self._loaded_template
评论列表
文章目录