Skip to content
Snippets Groups Projects
Commit 6f83e07e authored by Vincent Texier's avatar Vincent Texier Committed by Vincent Texier
Browse files

[enh] #58 enhance client class

parent 32488928
No related branches found
No related tags found
2 merge requests!94Merge dev into master for release 0.56.0,!84#58: WS2P support
......@@ -82,23 +82,24 @@ async def parse_response(response: ClientResponse, schema: dict) -> Any:
class WSConnection:
"""
From the documentation of the aiohttp_library, the web socket connection
await ws_connection = session.ws_connect()
should return a ClientWebSocketResponse object...
https://docs.aiohttp.org/en/stable/client_quickstart.html#websockets
In fact, aiohttp.session.ws_connect() returns a aiohttp.client._WSRequestContextManager instance.
It must be used in a with statement to get the ClientWebSocketResponse instance from it (__aenter__).
At the end of the with statement, aiohttp.client._WSRequestContextManager.__aexit__ is called
and close the ClientWebSocketResponse in it.
await with ws_connection as ws:
await ws.receive_str()
"""
# From the documentation of the aiohttp_library, the web socket connection
#
# await ws_connection = session.ws_connect()
#
# should return a ClientWebSocketResponse object...
#
# https://docs.aiohttp.org/en/stable/client_quickstart.html#websockets
#
# In fact, aiohttp.session.ws_connect() returns a aiohttp.client._WSRequestContextManager instance.
# It must be used in a with statement to get the ClientWebSocketResponse instance from it (__aenter__).
# At the end of the with statement, aiohttp.client._WSRequestContextManager.__aexit__ is called
# and close the ClientWebSocketResponse in it.
#
# await with ws_connection as ws:
# await ws.receive_str()
#
def __init__(self, connection: _WSRequestContextManager) -> None:
"""
Init WSConnection instance
......@@ -155,8 +156,7 @@ class WSConnection:
async def init_connection(self):
"""
Mandatory for aiohttp library to avoid the use of the with statement
Mandatory for aiohttp library in order to avoid the usage of the 'with' statement
:return:
"""
self.connection = await self._connection.__aenter__()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment