66
77
88class SSEManager :
9- def __init__ (self , handlestate : callable (ld_eventsource .actions .Start ),
10- handleerror : callable (ld_eventsource .actions .Fault ),
11- handlemessage : callable (ld_eventsource .actions .Event )):
9+ def __init__ (
10+ self ,
11+ handlestate : callable (ld_eventsource .actions .Start ),
12+ handleerror : callable (ld_eventsource .actions .Fault ),
13+ handlemessage : callable (ld_eventsource .actions .Event ),
14+ ):
1215 self .client : ld_eventsource .SSEClient = None
1316 self .url = ""
1417 self .handlestate = handlestate
1518 self .handleerror = handleerror
1619 self .handlemessage = handlemessage
1720
18- self .read_thread = threading .Thread (target = self .read_events ,
19- args = (self .handlestate , self .handleerror , self .handlemessage ))
21+ self .read_thread = threading .Thread (
22+ target = self .read_events ,
23+ args = (self .handlestate , self .handleerror , self .handlemessage ),
24+ )
2025
21- def read_events (self ,
22- handlestate : callable (ld_eventsource .actions .Start ),
23- handleerror : callable (ld_eventsource .actions .Fault ),
24- handlemessage : callable (ld_eventsource .actions .Event )):
26+ def read_events (
27+ self ,
28+ handlestate : callable (ld_eventsource .actions .Start ),
29+ handleerror : callable (ld_eventsource .actions .Fault ),
30+ handlemessage : callable (ld_eventsource .actions .Event ),
31+ ):
2532 self .client .start ()
2633 for event in self .client .all :
2734 if isinstance (event , ld_eventsource .actions .Start ):
@@ -32,8 +39,8 @@ def read_events(self,
3239 handlemessage (event )
3340
3441 def update (self , config : dict ):
35- if self .use_new_config (config [' sse' ]):
36- self .url = config [' sse' ][ ' hostname' ] + config [' sse' ][ ' path' ]
42+ if self .use_new_config (config [" sse" ]):
43+ self .url = config [" sse" ][ " hostname" ] + config [" sse" ][ " path" ]
3744 if self .client is not None :
3845 self .client .close ()
3946 if self .read_thread .is_alive ():
@@ -42,12 +49,14 @@ def update(self, config: dict):
4249 connect = ld_eventsource .config .ConnectStrategy .http (self .url ),
4350 error_strategy = ld_eventsource .config .ErrorStrategy .CONTINUE ,
4451 )
45- self .read_thread = threading .Thread (target = self .read_events ,
46- args = (self .handlestate , self .handleerror , self .handlemessage ))
52+ self .read_thread = threading .Thread (
53+ target = self .read_events ,
54+ args = (self .handlestate , self .handleerror , self .handlemessage ),
55+ )
4756 self .read_thread .start ()
4857
4958 def use_new_config (self , config : dict ) -> bool :
50- new_url = config [' hostname' ] + config [' path' ]
59+ new_url = config [" hostname" ] + config [" path" ]
5160 if self .url == "" or self .url is None and new_url != "" :
5261 return True
5362 return self .url != new_url
0 commit comments