当前位置: 首页>>代码示例>>Python>>正文


Python web.HTTPNotFound方法代码示例

本文整理汇总了Python中aiohttp.web.HTTPNotFound方法的典型用法代码示例。如果您正苦于以下问题:Python web.HTTPNotFound方法的具体用法?Python web.HTTPNotFound怎么用?Python web.HTTPNotFound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.web的用法示例。


在下文中一共展示了web.HTTPNotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tus_session_headers

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def tus_session_headers(request, params):
    folder_path = (request.app['VFOLDER_MOUNT'] / params['host'] /
                   request.app['VFOLDER_FSPREFIX'] / params['folder'])
    upload_base = folder_path / ".upload"
    base_file = upload_base / params['session_id']
    if not Path(base_file).exists():
        raise web.HTTPNotFound()
    headers = {}
    headers["Access-Control-Allow-Origin"] = "*"
    headers["Access-Control-Allow-Headers"] = \
        "Tus-Resumable, Upload-Length, Upload-Metadata, Upload-Offset, Content-Type"
    headers["Access-Control-Expose-Headers"] = \
        "Tus-Resumable, Upload-Length, Upload-Metadata, Upload-Offset, Content-Type"
    headers["Access-Control-Allow-Methods"] = "*"
    headers["Cache-Control"] = "no-store"
    headers["Tus-Resumable"] = "1.0.0"
    headers['Upload-Offset'] = str(Path(base_file).stat().st_size)
    headers['Upload-Length'] = str(params['size'])
    return headers 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:21,代码来源:vfolder.py

示例2: update_operation

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def update_operation(self, op_id, state=None, autonomous=None, obfuscator=None):
        async def validate(op):
            try:
                if not len(op):
                    raise web.HTTPNotFound
                elif await op[0].is_finished():
                    raise web.HTTPBadRequest(body='This operation has already finished.')
                elif state not in op[0].states.values():
                    raise web.HTTPBadRequest(body='state must be one of {}'.format(op[0].states.values()))
            except Exception as e:
                self.log.error(repr(e))
        operation = await self.get_service('data_svc').locate('operations', match=dict(id=op_id))
        if state:
            await validate(operation)
            operation[0].state = state
            if state == operation[0].states['FINISHED']:
                operation[0].finish = self.get_current_timestamp()
            self.log.debug('Changing operation=%s state to %s' % (op_id, state))
        if autonomous:
            operation[0].autonomous = 0 if operation[0].autonomous else 1
            self.log.debug('Toggled operation=%s autonomous to %s' % (op_id, bool(operation[0].autonomous)))
        if obfuscator:
            operation[0].obfuscator = obfuscator
            self.log.debug('Updated operation=%s obfuscator to %s' % (op_id, operation[0].obfuscator)) 
开发者ID:mitre,项目名称:caldera,代码行数:26,代码来源:rest_svc.py

示例3: http_get

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def http_get(client, url):
    async with client.get(url) as res:
        if res.status == 200:
            ctype = res.headers.get('Content-type', '').lower()
            if 'json' in ctype or url.endswith('json'):
                data = await res.json()
            else:
                data = await res.read()
            return data

        elif res.status == 404:
            raise web.HTTPNotFound()
        else:
            raise aiohttp.errors.HttpProcessingError(
                code=res.status, message=res.reason,
                headers=res.headers) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:18,代码来源:flags3_await.py

示例4: download_one

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def download_one(client, cc, base_url, semaphore, verbose):
    try:
        async with semaphore:
            image = await get_flag(client, base_url, cc)
        async with semaphore:
            country = await get_country(client, base_url, cc)
    except web.HTTPNotFound:
        status = HTTPStatus.not_found
        msg = 'not found'
    except Exception as exc:
        raise FetchError(cc) from exc
    else:
        country = country.replace(' ', '_')
        filename = '{}-{}.gif'.format(country, cc)
        client.loop.run_in_executor(None, save_flag, image, filename)
        status = HTTPStatus.ok
        msg = 'OK'

    if verbose and msg:
        print(cc, msg)

    return Result(status, cc) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:24,代码来源:flags3_await.py

示例5: download_one

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def download_one(client, cc, base_url, semaphore, verbose):
    try:
        async with semaphore:
            image = await get_flag(client, base_url, cc)
    except web.HTTPNotFound:
        status = HTTPStatus.not_found
        msg = 'not found'
    except Exception as exc:
        raise FetchError(cc) from exc
    else:
        save_flag(image, cc.lower() + '.gif')
        status = HTTPStatus.ok
        msg = 'OK'

    if verbose and msg:
        print(cc, msg)

    return Result(status, cc) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:20,代码来源:flags2_await.py

示例6: download_one

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def download_one(client, cc, base_url, semaphore, verbose):
    try:
        async with semaphore:
            image = await get_flag(client, base_url, cc)
    except web.HTTPNotFound:
        status = HTTPStatus.not_found
        msg = 'not found'
    except Exception as exc:
        raise FetchError(cc) from exc
    else:
        client.loop.run_in_executor(None, save_flag, image,
                                    cc.lower() + '.gif')
        status = HTTPStatus.ok
        msg = 'OK'

    if verbose and msg:
        print(cc, msg)

    return Result(status, cc) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:21,代码来源:flags2_await_executor.py

示例7: getguild

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def getguild(self, request: web.Request):
        guild = int(request.match_info['guild'])
        req = f"""SELECT info FROM guilddata WHERE UUID = $1"""
        async with self.bot.db._conn.acquire() as connection:
            response = await connection.fetchval(req, guild)
        if response:
            data = json.loads(response)

            fdata = data
            if request.match_info['tail']:
                for item in request.match_info['tail'].split("/"):
                    if not item:
                        continue
                    try:
                        key = unquote(item)
                        if isinstance(fdata, list):
                            key = int(key)
                        fdata = fdata[key]
                    except:
                        raise web.HTTPNotFound()

            return web.json_response(fdata)
        raise web.HTTPForbidden()

    # @server.route("/", methods=["GET"]) 
开发者ID:henry232323,项目名称:RPGBot,代码行数:27,代码来源:server.py

示例8: get_registry

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def get_registry(request: web.BaseRequest):
    """
    Request handler to get a revocation registry by identifier.

    Args:
        request: aiohttp request object

    Returns:
        The revocation registry

    """
    context = request.app["request_context"]

    registry_id = request.match_info["rev_reg_id"]

    try:
        revoc = IndyRevocation(context)
        revoc_registry = await revoc.get_issuer_rev_reg_record(registry_id)
    except StorageNotFoundError as err:
        raise web.HTTPNotFound(reason=err.roll_up) from err

    return web.json_response({"result": revoc_registry.serialize()}) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:routes.py

示例9: get_active_registry

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def get_active_registry(request: web.BaseRequest):
    """
    Request handler to get an active revocation registry by cred def id.

    Args:
        request: aiohttp request object

    Returns:
        The revocation registry identifier

    """
    context = request.app["request_context"]

    cred_def_id = request.match_info["cred_def_id"]

    try:
        revoc = IndyRevocation(context)
        revoc_registry = await revoc.get_active_issuer_rev_reg_record(cred_def_id)
    except StorageNotFoundError as err:
        raise web.HTTPNotFound(reason=err.roll_up) from err

    return web.json_response({"result": revoc_registry.serialize()}) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:routes.py

示例10: get_tails_file

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def get_tails_file(request: web.BaseRequest) -> web.FileResponse:
    """
    Request handler to download the tails file of the revocation registry.

    Args:
        request: aiohttp request object

    Returns:
        The tails file in FileResponse

    """
    context = request.app["request_context"]

    registry_id = request.match_info["rev_reg_id"]

    try:
        revoc = IndyRevocation(context)
        revoc_registry = await revoc.get_issuer_rev_reg_record(registry_id)
    except StorageNotFoundError as err:
        raise web.HTTPNotFound(reason=err.roll_up) from err

    return web.FileResponse(path=revoc_registry.tails_local_path, status=200) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:routes.py

示例11: test_create_registry_no_such_cred_def

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def test_create_registry_no_such_cred_def(self):
        CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default"
        request = async_mock.MagicMock()
        request.app = self.app
        request.json = async_mock.CoroutineMock(
            return_value={
                "max_cred_num": "1000",
                "credential_definition_id": CRED_DEF_ID,
            }
        )

        with async_mock.patch.object(
            self.storage, "search_records", autospec=True
        ) as mock_search, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_search.return_value.fetch_all = async_mock.CoroutineMock(
                return_value=False
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.revocation_create_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:25,代码来源:test_routes.py

示例12: test_get_registry_not_found

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def test_get_registry_not_found(self):
        REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
            self.test_did, self.test_did
        )
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"rev_reg_id": REV_REG_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_issuer_rev_reg_record=async_mock.CoroutineMock(
                    side_effect=test_module.StorageNotFoundError(error_code="dummy")
                )
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.get_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例13: test_get_active_registry_not_found

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def test_get_active_registry_not_found(self):
        CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default"
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"cred_def_id": CRED_DEF_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_active_issuer_rev_reg_record=async_mock.CoroutineMock(
                    side_effect=test_module.StorageNotFoundError(error_code="dummy")
                )
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.get_active_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:22,代码来源:test_routes.py

示例14: test_get_tails_file_not_found

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def test_get_tails_file_not_found(self):
        REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
            self.test_did, self.test_did
        )
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"rev_reg_id": REV_REG_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "FileResponse", async_mock.Mock()
        ) as mock_file_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_issuer_rev_reg_record=async_mock.CoroutineMock(
                    side_effect=test_module.StorageNotFoundError(error_code="dummy")
                )
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.get_tails_file(request)
            mock_file_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例15: connections_send_message

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPNotFound [as 别名]
def connections_send_message(request: web.BaseRequest):
    """
    Request handler for sending a basic message to a connection.

    Args:
        request: aiohttp request object

    """
    context = request.app["request_context"]
    connection_id = request.match_info["conn_id"]
    outbound_handler = request.app["outbound_message_router"]
    params = await request.json()

    try:
        connection = await ConnectionRecord.retrieve_by_id(context, connection_id)
    except StorageNotFoundError as err:
        raise web.HTTPNotFound(reason=err.roll_up) from err

    if connection.is_ready:
        msg = BasicMessage(content=params["content"])
        await outbound_handler(msg, connection_id=connection_id)

    return web.json_response({}) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:25,代码来源:routes.py


注:本文中的aiohttp.web.HTTPNotFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。