@@ -151,7 +151,7 @@ def __init__(
151
151
) -> None :
152
152
self ._dispatcher_fiber = dispatcher_fiber
153
153
self ._transport = transport
154
- self ._transport .on_message = lambda msg : self ._dispatch (msg )
154
+ self ._transport .on_message = lambda msg : self .dispatch (msg )
155
155
self ._waiting_for_object : Dict [str , Callable [[ChannelOwner ], None ]] = {}
156
156
self ._last_id = 0
157
157
self ._objects : Dict [str , ChannelOwner ] = {}
@@ -160,7 +160,7 @@ def __init__(
160
160
self ._is_sync = False
161
161
self ._child_ws_connections : List ["Connection" ] = []
162
162
self ._loop = loop
163
- self ._playwright_future : asyncio .Future ["Playwright" ] = loop .create_future ()
163
+ self .playwright_future : asyncio .Future ["Playwright" ] = loop .create_future ()
164
164
self ._error : Optional [BaseException ] = None
165
165
166
166
async def run_as_sync (self ) -> None :
@@ -172,15 +172,12 @@ async def run(self) -> None:
172
172
self ._root_object = RootChannelOwner (self )
173
173
174
174
async def init () -> None :
175
- self ._playwright_future .set_result (await self ._root_object .initialize ())
175
+ self .playwright_future .set_result (await self ._root_object .initialize ())
176
176
177
177
await self ._transport .connect ()
178
178
self ._loop .create_task (init ())
179
179
await self ._transport .run ()
180
180
181
- def get_playwright_future (self ) -> asyncio .Future :
182
- return self ._playwright_future
183
-
184
181
def stop_sync (self ) -> None :
185
182
self ._transport .request_stop ()
186
183
self ._dispatcher_fiber .switch ()
@@ -216,18 +213,18 @@ def _send_message_to_server(
216
213
if api_name :
217
214
metadata ["apiName" ] = api_name
218
215
219
- message = dict (
220
- id = id ,
221
- guid = guid ,
222
- method = method ,
223
- params = self ._replace_channels_with_guids (params , "params" ),
224
- metadata = metadata ,
225
- )
216
+ message = {
217
+ "id" : id ,
218
+ " guid" : guid ,
219
+ " method" : method ,
220
+ " params" : self ._replace_channels_with_guids (params ),
221
+ " metadata" : metadata ,
222
+ }
226
223
self ._transport .send (message )
227
224
self ._callbacks [id ] = callback
228
225
return callback
229
226
230
- def _dispatch (self , msg : ParsedMessagePayload ) -> None :
227
+ def dispatch (self , msg : ParsedMessagePayload ) -> None :
231
228
id = msg .get ("id" )
232
229
if id :
233
230
callback = self ._callbacks .pop (id )
@@ -280,35 +277,36 @@ def _create_remote_object(
280
277
self ._waiting_for_object .pop (guid )(result )
281
278
return result
282
279
283
- def _replace_channels_with_guids (self , payload : Any , param_name : str ) -> Any :
280
+ def _replace_channels_with_guids (
281
+ self ,
282
+ payload : Any ,
283
+ ) -> Any :
284
284
if payload is None :
285
285
return payload
286
286
if isinstance (payload , Path ):
287
287
return str (payload )
288
288
if isinstance (payload , list ):
289
- return list (
290
- map (lambda p : self ._replace_channels_with_guids (p , "index" ), payload )
291
- )
289
+ return list (map (self ._replace_channels_with_guids , payload ))
292
290
if isinstance (payload , Channel ):
293
291
return dict (guid = payload ._guid )
294
292
if isinstance (payload , dict ):
295
293
result = {}
296
- for key in payload :
297
- result [key ] = self ._replace_channels_with_guids (payload [ key ], key )
294
+ for key , value in payload . items () :
295
+ result [key ] = self ._replace_channels_with_guids (value )
298
296
return result
299
297
return payload
300
298
301
299
def _replace_guids_with_channels (self , payload : Any ) -> Any :
302
300
if payload is None :
303
301
return payload
304
302
if isinstance (payload , list ):
305
- return list (map (lambda p : self ._replace_guids_with_channels ( p ) , payload ))
303
+ return list (map (self ._replace_guids_with_channels , payload ))
306
304
if isinstance (payload , dict ):
307
305
if payload .get ("guid" ) in self ._objects :
308
306
return self ._objects [payload ["guid" ]]._channel
309
307
result = {}
310
- for key in payload :
311
- result [key ] = self ._replace_guids_with_channels (payload [ key ] )
308
+ for key , value in payload . items () :
309
+ result [key ] = self ._replace_guids_with_channels (value )
312
310
return result
313
311
return payload
314
312
0 commit comments