Python yaml 模块,parser() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用yaml.parser()

项目:arthur-redshift-etl    作者:harrystech    | 项目源码 | 文件源码
def load_table_design(stream, table_name):
    """
    Load table design from stream (usually, an open file).
    The table design is validated before being returned.
    """
    try:
        table_design = yaml.safe_load(stream)
    except yaml.parser.ParserError as exc:
        raise TableDesignParseError(exc) from exc

    # BEGIN -- Support of DEPRECATED format of specifying constraints
    # This rewrites the format from v0.23.1 and earlier to v0.24.0 -- I would prefer to drop this soon.
    etl.config.validate_with_schema(table_design, "table_design.schema")
    constraints = table_design.get("constraints")
    if isinstance(constraints, dict):
        table_design["constraints"] = [{constraint_type: constraints[constraint_type]}
                                       for constraint_type in sorted(constraints)]
    # END -- Support of DEPRECATED format of specifying constraints

    return validate_table_design(table_design, table_name)