當前位置: 首頁>>代碼示例>>Python>>正文


Python WSMsgType.CLOSED屬性代碼示例

本文整理匯總了Python中aiohttp.WSMsgType.CLOSED屬性的典型用法代碼示例。如果您正苦於以下問題:Python WSMsgType.CLOSED屬性的具體用法?Python WSMsgType.CLOSED怎麽用?Python WSMsgType.CLOSED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在aiohttp.WSMsgType的用法示例。


在下文中一共展示了WSMsgType.CLOSED屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: websocket_msg_handler

# 需要導入模塊: from aiohttp import WSMsgType [as 別名]
# 或者: from aiohttp.WSMsgType import CLOSED [as 別名]
def websocket_msg_handler(self):
        """Handle active websocket connection, returning upon close"""
        async for msg in self.websocket:
            LOGGER.debug("Websocket message: %s, %s", msg.type, msg.data)
            if msg.type in (WSMsgType.CLOSED, WSMsgType.ERROR):
                return None

            if msg.data == 'refresh-cache':
                await self._refresh_cache()
                msg = f"refreshed {BaseHandler.db_cache.dbchange['exported']}"
                if self.websocket:
                    await self.websocket.send_str(msg)
                else:
                    self.websocket_response_queue.add(msg)
            else:
                LOGGER.warning("Unhandled websocket message %s", msg.data) 
開發者ID:RedHatInsights,項目名稱:vmaas,代碼行數:18,代碼來源:app.py

示例2: receive

# 需要導入模塊: from aiohttp import WSMsgType [as 別名]
# 或者: from aiohttp.WSMsgType import CLOSED [as 別名]
def receive(self):
        msg = await self.ws.receive()
        if msg.type == WSMsgType.TEXT:
            return msg.data
        elif msg.type == WSMsgType.ERROR:
            raise ConnectionClosedException()
        elif msg.type == WSMsgType.CLOSING:
            raise ConnectionClosedException()
        elif msg.type == WSMsgType.CLOSED:
            raise ConnectionClosedException() 
開發者ID:graphql-python,項目名稱:graphql-ws,代碼行數:12,代碼來源:aiohttp.py

示例3: test_receive_closed

# 需要導入模塊: from aiohttp import WSMsgType [as 別名]
# 或者: from aiohttp.WSMsgType import CLOSED [as 別名]
def test_receive_closed(self, mock_ws):
        mock_ws.receive.return_value.type = WSMsgType.CLOSED
        connection_context = AiohttpConnectionContext(ws=mock_ws)
        with pytest.raises(ConnectionClosedException):
            await connection_context.receive() 
開發者ID:graphql-python,項目名稱:graphql-ws,代碼行數:7,代碼來源:test_aiohttp.py

示例4: _ws_handler

# 需要導入模塊: from aiohttp import WSMsgType [as 別名]
# 或者: from aiohttp.WSMsgType import CLOSED [as 別名]
def _ws_handler(self, request, group):
        """
        Handle websocket connections.

        This includes:
            * new connections
            * closed connections
            * messages
        """
        ws_client = web.WebSocketResponse()
        await ws_client.prepare(request)

        session = None
        if self.websockets[group]["authenticated"]:
            session = await get_session(request)
            if session.new:
                self.logger.debug('websocket: not logged in')
                if asyncio.iscoroutinefunction(ws_client.send_str):
                    await ws_client.send_str(json.dumps({'status': 401, 'text': "Unauthorized"}))
                else:
                    ws_client.send_str(json.dumps({'status': 401, 'text': "Unauthorized"}))
                ws_client.close()
                return ws_client

        ws_client.cirrina = CirrinaWSContext(request, session)
        self.websockets[group]["connections"].append(ws_client)
        try:
            await self.websockets[group]["connect"](ws_client)
        except Exception as exc:
            self.logger.error("websocket: error in connect event handler")
            self.logger.exception(exc)

        while True:
            try:
                msg = await ws_client.receive()
                if msg.type == WSMsgType.CLOSE or msg.type == WSMsgType.CLOSED:
                    self.logger.info('websocket closed')
                    break

                self.logger.debug("websocket got: %s", msg)
                if msg.type == WSMsgType.TEXT:
                    await self.websockets[group]["handler"](ws_client, msg.data)
                elif msg.type == WSMsgType.ERROR:
                    self.logger.info('websocket closed with exception %s', ws_client.exception())
            except futures._base.CancelledError:
                pass
            except Exception as exc:
                self.logger.exception(exc)

        self.websockets[group]["connections"].remove(ws_client)
        try:
            await self.websockets[group]["disconnect"](ws_client)
        except Exception as exc:
            self.logger.error("websocket: error in disconnect event handler")
            self.logger.exception(exc)

        return ws_client

    # JRPC protocol 
開發者ID:neolynx,項目名稱:cirrina,代碼行數:61,代碼來源:server.py


注:本文中的aiohttp.WSMsgType.CLOSED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。