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


Python web_response.Response方法代码示例

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


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

示例1: response

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def response(  # pylint: disable=unused-argument
        req: Request, code: int, text: str = None, encoding: str = None
    ) -> Response:
        """
        Formats an aiohttp Response

        :param req: The original aoihttp Request
        :param code: The HTTP result code to return
        :param text: The text to return
        :param encoding: The text encoding.  Defaults to utf-8
        :return: The aoihttp Response
        """

        response = Response(status=code)

        if text:
            response.content_type = "text/plain"
            response.body = text.encode(encoding=encoding if encoding else "utf-8")

        return response 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:22,代码来源:slack_helper.py

示例2: post

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def post(self, request):
        data = await request.json()
        group, _created = get_or_create(session, DomainGroup, name=data['name'])
        domains = []
        if data.get('domains'):
            for domain_el in data.get('domains'):
                domain, _domain_created = get_or_create(session, Domain, domain=domain_el)
                domains.append({'id': domain.id, 'domain': domain_el, 'created': _domain_created})

        return Response(
            status=200,
            body=self.resource.encode({
                'id': group.id,
                'name': group.name,
                'domains': domains,
                'created': _created
            }), content_type='application/json') 
开发者ID:Haikson,项目名称:sitemap-generator,代码行数:19,代码来源:rest.py

示例3: message_data

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def message_data(request):
    """
    As an example of aiohttp providing a non-html response, we load the actual messages for the "messages" view above
    via ajax using this endpoint to get data. see static/message_display.js for details of rendering.
    """
    json_str = await request.app['pg'].fetchval(
        """
        select coalesce(array_to_json(array_agg(row_to_json(t))), '[]')
        from (
          select username, timestamp, message
          from messages
          order by timestamp desc
        ) t
        """
    )
    return Response(text=json_str, content_type='application/json') 
开发者ID:aio-libs,项目名称:aiohttp-devtools,代码行数:18,代码来源:views.py

示例4: _write_upnp_headers

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def _write_upnp_headers(self, result: typing.Union[Response, StreamResponse]) -> typing.NoReturn:
        result.headers.setdefault("Content-Type", "video/mp4")
        result.headers.setdefault("Access-Control-Allow-Origin", "*")
        result.headers.setdefault("Access-Control-Allow-Methods", "GET, OPTIONS")
        result.headers.setdefault("Access-Control-Allow-Headers", "Content-Type")
        result.headers.setdefault("transferMode.dlna.org", "Streaming")
        result.headers.setdefault("TimeSeekRange.dlna.org", "npt=0.00-")
        result.headers.setdefault("contentFeatures.dlna.org", "DLNA.ORG_OP=01;DLNA.ORG_CI=0;")

    # noinspection PyUnusedLocal 
开发者ID:andrew-ld,项目名称:smart-tv-telegram,代码行数:12,代码来源:http.py

示例5: _upnp_discovery_handler

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def _upnp_discovery_handler(self, request: Request) -> typing.Optional[Response]:
        result = Response(status=200)
        self._write_upnp_headers(result)
        return result 
开发者ID:andrew-ld,项目名称:smart-tv-telegram,代码行数:6,代码来源:http.py

示例6: get

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def get(self) -> Response:
        data = []

        domains = session.query(Domain).all()
        for instance in self.resource.collection.values():
            data.append(self.resource.render(instance))

        return Response(status=200, body=self.resource.encode({
            'domains': [
                {
                    'id': domain.id, 'title': domain.domain,
                    'groups': [{'id': group.id, 'name': group.name} for group in domain.groups]
                } for domain in session.query(Domain).all()
            ]}), content_type='application/json') 
开发者ID:Haikson,项目名称:sitemap-generator,代码行数:16,代码来源:rest.py

示例7: setUp

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def setUp(self):
        self.app = App()
        self.client = ClientSession()

        self.callback = callback = CoroutineMock()
        self.route_path = "/mock_handler"
        self.route_method = "GET"
        self.metrics = metrics = patch(
            "asyncworker.metrics.aiohttp_resources.metrics"
        ).start()

        @self.app.route(
            routes=[self.route_path],
            type=RouteTypes.HTTP,
            methods=[self.route_method],
        )
        async def handler(request):
            metrics.requests_in_progress.labels.assert_called_once_with(
                method=request.method, path=request.path
            )
            metrics.requests_in_progress.labels.return_value.inc.assert_called_once()
            metrics.requests_in_progress.labels.return_value.dec.assert_not_called()
            await callback(request)
            return Response(text="ok")

        await self.app.startup() 
开发者ID:b2wdigital,项目名称:async-worker,代码行数:28,代码来源:test_http_metrics.py

示例8: process

# 需要导入模块: from aiohttp import web_response [as 别名]
# 或者: from aiohttp.web_response import Response [as 别名]
def process(self, req: Request, logic: Callable) -> Response:
        """
        Accept an incoming webhook request and convert it into a TurnContext which can be processed by the bot's logic.

        :param req: The aoihttp Request object
        :param logic: The method to call for the resulting bot turn.
        :return: The aoihttp Response
        """
        if not req:
            raise Exception("Request is required")

        if not self.slack_logged_in:
            await self.slack_client.login_with_slack()
            self.slack_logged_in = True

        body = await req.text()
        slack_body = SlackHelper.deserialize_body(req.content_type, body)

        if slack_body.type == "url_verification":
            return SlackHelper.response(req, 200, slack_body.challenge)

        if not self.slack_client.verify_signature(req, body):
            text = "Rejected due to mismatched header signature"
            return SlackHelper.response(req, 401, text)

        if (
            not self.slack_client.options.slack_verification_token
            and slack_body.token != self.slack_client.options.slack_verification_token
        ):
            text = f"Rejected due to mismatched verificationToken:{body}"
            return SlackHelper.response(req, 403, text)

        if slack_body.payload:
            # handle interactive_message callbacks and block_actions
            activity = SlackHelper.payload_to_activity(slack_body.payload)
        elif slack_body.type == "event_callback":
            activity = await SlackHelper.event_to_activity(
                slack_body.event, self.slack_client
            )
        elif slack_body.command:
            activity = await SlackHelper.command_to_activity(
                slack_body, self.slack_client
            )
        else:
            raise Exception(f"Unknown Slack event type {slack_body.type}")

        context = TurnContext(self, activity)
        await self.run_pipeline(context, logic)

        return SlackHelper.response(req, 200) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:52,代码来源:slack_adapter.py


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