コード例 #1
0
def get_resource_or_410(request: web.Request) -> Resource:
    try:
        resource = get_resource(request)
        if not get_resource_path(
            config=get_config(request), match_info=request.match_info, uid=resource.uid
        ).exists():
            raise IOError(f"{resource.uid} does not exist")
    except IOError:
        logger.warning(
            "Attempt to continue upload of removed resource",
            extra={"file_name" "resource_uid": resource.uid},
        )
        raise web.HTTPGone(text="")
    return resource
コード例 #2
0
async def show_image(i):
    if i is None:
        return web.HTTPNotFound(body='Not found, image is None',
                                headers={'content-type': 'text/html'})
    im_data = i['data']
    if im_data == None:
        return web.HTTPGone(body='This image has been removed',
                            headers={'content-type': 'text/html'})

    asyncio.get_event_loop().create_task(add_one_view(i['_id']))

    if not 'content-type' in i:
        return web.Response(text='No content type found')
    return web.Response(body=im_data,
                        content_type=i['content-type'],
                        headers={'Cache-Control': 'max-age=86400'})
コード例 #3
0
async def view_image(request):
    im_hash = request.match_info['hex']
    if '.' in im_hash:
        im_hash, _ = im_hash.split('.', 1)
    i = await db.images.find_one({'_id': im_hash})
    if i is None:
        return web.HTTPNotFound(body='Not found',
                                headers={'content-type': 'text/html'})
    im_data = i['data']
    if im_data == None:
        return web.HTTPGone(body='This image has been removed',
                            headers={'content-type': 'text/html'})

    return web.Response(body=await load_template('view.html',
                                                 id=im_hash,
                                                 pic=i),
                        headers={'content-type': 'text/html'})
コード例 #4
0
ファイル: conftest.py プロジェクト: hh-h/aiohttp_apiset
 async def retrieve(self, request):
     raise web.HTTPGone()
コード例 #5
0
def non_500_error(request):
    raise web.HTTPGone()