block_store.py 文件源码

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

项目:parsec-cloud 作者: Scille 项目源码 文件源码
def register_in_memory_block_store_api(app, prefix='/blockstore'):
    # Really, really simple stuff ;-)
    blocks = {}

    async def api_block_get(request):
        id = request.match_info['id']
        try:
            return web.Response(body=blocks[id], content_type='application/octet-stream')
        except KeyError:
            raise web.HTTPNotFound()

    async def api_block_post(request):
        id = request.match_info['id']
        if id in blocks:
            raise web.HTTPConflict()
        blocks[id] = await request.read()
        return web.Response()

    app.router.add_get(prefix + '/{id}', api_block_get)
    app.router.add_post(prefix + '/{id}', api_block_post)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号