mycookbooks.py 文件源码

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

项目:Railtrack 作者: JeevesTakesOver 项目源码 文件源码
def parse_config(filename):
    """ parses the YAML config file and expands any environment variables """

    pattern = re.compile(r'^\<%= ENV\[\'(.*)\'\] %\>(.*)$')
    yaml.add_implicit_resolver("!pathex", pattern)

    def pathex_constructor(loader, node):
        value = loader.construct_scalar(node)
        envVar, remainingPath = pattern.match(value).groups()
        return os.environ[envVar] + remainingPath

    yaml.add_constructor('!pathex', pathex_constructor)

    with open(filename) as f:
        return(
            yaml.load(f)
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号