parser.py 文件源码

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

项目:deb-python-pydotplus 作者: openstack 项目源码 文件源码
def parse_dot_data(data):
    global top_graphs

    top_graphs = list()

    if PY3:
        if isinstance(data, bytes):
            # this is extremely hackish
            try:
                idx = data.index(b'charset') + 7
                while data[idx] in b' \t\n\r=':
                    idx += 1
                fst = idx
                while data[idx] not in b' \t\n\r];,':
                    idx += 1
                charset = data[fst:idx].strip(b'"\'').decode('ascii')
                data = data.decode(charset)
            except:
                data = data.decode('utf-8')
    else:
        if data.startswith(codecs.BOM_UTF8):
            data = data.decode('utf-8')

    try:

        graphparser = graph_definition()

        if pyparsing_version >= '1.2':
            graphparser.parseWithTabs()

        tokens = graphparser.parseString(data)

        if len(tokens) == 1:
            return tokens[0]
        else:
            return [g for g in tokens]

    except ParseException:
        err = sys.exc_info()[1]
        print(err.line)
        print(" " * (err.column - 1) + "^")
        print(err)
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号