apps.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号