__init__.py 文件源码

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

项目:edx-django-release-util 作者: edx 项目源码 文件源码
def dump_migration_session_state(raw):
    """
    Serialize a migration session state to yaml using nicer formatting

    Args:
        raw: object to serialize
    Returns: string (of yaml)

    Specifically, this forces the "output" member of state step dicts (e.g.
    state[0]['output']) to use block formatting. For example, rather than this:

    - migration: [app, migration_name]
      output: "line 1\nline2\nline3"

    You get this:

    - migration: [app, migration_name]
      output: |
        line 1
        line 2
        line 3
    """
    class BlockStyle(str): pass
    class SessionDumper(yaml.SafeDumper): pass
    def str_block_formatter(dumper, data):
        return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|')
    SessionDumper.add_representer(BlockStyle, str_block_formatter)

    raw = deepcopy(raw)
    for step in raw:
        step['output'] = BlockStyle(step['output'])
        step['traceback'] = BlockStyle(step['traceback'])
    return yaml.dump(raw, Dumper=SessionDumper)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号