__init__.py 文件源码

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

项目:analytics-platform-ops 作者: ministryofjustice 项目源码 文件源码
def represent_stringish(dumper, data):
        # Will crash on bytestrings with weird chars in them,
        #  because we can't tell if it's supposed to be e.g. utf-8 readable string
        #  or an arbitrary binary buffer, and former one *must* be pretty-printed
        # PyYAML's Representer.represent_str does the guesswork and !!binary or !!python/str
        # Explicit crash on any bytes object might be more sane, but also annoying
        # Use something like base64 to encode such buffer values instead
        # Having such binary stuff pretty much everywhere on unix (e.g. paths) kinda sucks
        data = unicode(data) # read the comment above

        # Try to use '|' style for multiline data,
        #  quoting it with 'literal' if lines are too long anyway,
        #  not sure if Emitter.analyze_scalar can also provide useful info here
        style = dumper.pyaml_string_val_style
        if not style:
            style = 'plain'
            if '\n' in data or not data or data == '-' or data[0] in '!&*[':
                style = 'literal'
                if '\n' in data[:-1]:
                    for line in data.splitlines():
                        if len(line) > dumper.best_width: break
                    else: style = '|'

        return yaml.representer.ScalarNode('tag:yaml.org,2002:str', data, style=style)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号