@@ -92,10 +92,10 @@ def __init__(
92
92
headers : Optional [HeadersLike ] = None ,
93
93
ssl : Union [SSLContext , bool ] = False ,
94
94
init_payload : Dict [str , Any ] = {},
95
- connect_timeout : int = 10 ,
96
- close_timeout : int = 10 ,
97
- ack_timeout : int = 10 ,
98
- keep_alive_timeout : Optional [int ] = None ,
95
+ connect_timeout : Optional [ Union [ int , float ]] = 10 ,
96
+ close_timeout : Optional [ Union [ int , float ]] = 10 ,
97
+ ack_timeout : Optional [ Union [ int , float ]] = 10 ,
98
+ keep_alive_timeout : Optional [Union [ int , float ] ] = None ,
99
99
connect_args : Dict [str , Any ] = {},
100
100
) -> None :
101
101
"""Initialize the transport with the given parameters.
@@ -105,10 +105,11 @@ def __init__(
105
105
:param ssl: ssl_context of the connection. Use ssl=False to disable encryption
106
106
:param init_payload: Dict of the payload sent in the connection_init message.
107
107
:param connect_timeout: Timeout in seconds for the establishment
108
- of the websocket connection.
109
- :param close_timeout: Timeout in seconds for the close.
108
+ of the websocket connection. If None is provided this will wait forever.
109
+ :param close_timeout: Timeout in seconds for the close. If None is provided
110
+ this will wait forever.
110
111
:param ack_timeout: Timeout in seconds to wait for the connection_ack message
111
- from the server.
112
+ from the server. If None is provided this will wait forever.
112
113
:param keep_alive_timeout: Optional Timeout in seconds to receive
113
114
a sign of liveness from the server.
114
115
:param connect_args: Other parameters forwarded to websockets.connect
@@ -118,10 +119,10 @@ def __init__(
118
119
self .headers : Optional [HeadersLike ] = headers
119
120
self .init_payload : Dict [str , Any ] = init_payload
120
121
121
- self .connect_timeout : int = connect_timeout
122
- self .close_timeout : int = close_timeout
123
- self .ack_timeout : int = ack_timeout
124
- self .keep_alive_timeout : Optional [int ] = keep_alive_timeout
122
+ self .connect_timeout : Optional [ Union [ int , float ]] = connect_timeout
123
+ self .close_timeout : Optional [ Union [ int , float ]] = close_timeout
124
+ self .ack_timeout : Optional [ Union [ int , float ]] = ack_timeout
125
+ self .keep_alive_timeout : Optional [Union [ int , float ] ] = keep_alive_timeout
125
126
126
127
self .connect_args = connect_args
127
128
@@ -156,8 +157,7 @@ def __init__(
156
157
self .close_exception : Optional [Exception ] = None
157
158
158
159
async def _send (self , message : str ) -> None :
159
- """Send the provided message to the websocket connection and log the message
160
- """
160
+ """Send the provided message to the websocket connection and log the message"""
161
161
162
162
if not self .websocket :
163
163
raise TransportClosed (
@@ -172,8 +172,7 @@ async def _send(self, message: str) -> None:
172
172
raise e
173
173
174
174
async def _receive (self ) -> str :
175
- """Wait the next message from the websocket connection and log the answer
176
- """
175
+ """Wait the next message from the websocket connection and log the answer"""
177
176
178
177
# It is possible that the websocket has been already closed in another task
179
178
if self .websocket is None :
@@ -194,8 +193,7 @@ async def _receive(self) -> str:
194
193
return answer
195
194
196
195
async def _wait_ack (self ) -> None :
197
- """Wait for the connection_ack message. Keep alive messages are ignored
198
- """
196
+ """Wait for the connection_ack message. Keep alive messages are ignored"""
199
197
200
198
while True :
201
199
init_answer = await self ._receive ()
@@ -575,7 +573,7 @@ async def connect(self) -> None:
575
573
# Set the _connecting flag to False after in all cases
576
574
try :
577
575
self .websocket = await asyncio .wait_for (
578
- websockets .client .connect (self .url , ** connect_args , ),
576
+ websockets .client .connect (self .url , ** connect_args ),
579
577
self .connect_timeout ,
580
578
)
581
579
finally :
0 commit comments