nest_messages.py 文件源码

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

项目:pbtk 作者: marin-m 项目源码 文件源码
def fix_naming(nested, new_path, prev_path, top_path,
               msg_to_referrers, msg_to_topmost, msg_to_newloc, msg_to_imports, msg_path_to_obj, newloc_to_msg):

    # Keep track of the original full name of the generated block, as
    # it's the one we'll use when processing further references from
    # msg_to_referrers and other objects.
    orig_path = newloc_to_msg.get(prev_path, prev_path)
    newloc_to_msg[new_path] = orig_path

    if orig_path != top_path:
        msg_to_topmost[orig_path] = top_path
    msg_to_newloc[orig_path] = new_path
    msg_path_to_obj[orig_path] = nested

    # Fix references.
    for field, referrer, _ in msg_to_referrers.get(orig_path, []):
        field = next((i for i in msg_path_to_obj[referrer].field if i.name == field), None)

        field.type_name = '.' + new_path

        # Fix imports in reference's files.
        referrer_top_path = msg_to_topmost.get(referrer, referrer)

        msg_to_imports[referrer_top_path].append(top_path)

    # Do the same with children.
    if isinstance(nested, DescriptorProto):
        for child in [*nested.nested_type, *nested.enum_type]:
            fix_naming(child, new_path + '.' + child.name, prev_path + '.' + child.name, top_path,
                       msg_to_referrers, msg_to_topmost, msg_to_newloc, msg_to_imports, msg_path_to_obj, newloc_to_msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号