pbimport.py 文件源码

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

项目:protofuzz 作者: trailofbits 项目源码 文件源码
def from_file(proto_file):
    '''
    Take a filename |protoc_file|, compile it via the Protobuf
    compiler, and import the module.

    Return the module if successfully compiled, otherwise raise either
    a ProtocNotFound or BadProtobuf exception.
    '''
    if not proto_file.endswith('.proto'):
        raise BadProtobuf()

    dest = tempfile.mkdtemp()
    full_path = os.path.abspath(proto_file)
    _compile_proto(full_path, dest)

    filename = os.path.split(full_path)[-1]
    name = re.search(r'^(.*)\.proto$', filename).group(1)
    target = os.path.join(dest, name+'_pb2.py')

    return _load_module(target)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号