當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。