File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -37,13 +37,23 @@ def _user_from_conn(conn):
37
37
return model .User (session_id = '05' + hexlify (conn .pubkey ).decode ())
38
38
39
39
40
+ def _maybe_serialize (data ):
41
+ """maybe bt encode data, if data is a bytes dont encode,
42
+ if data is a string turn it into bytes and dont encode, otherwise bt encode"""
43
+ if isinstance (data , bytes ):
44
+ return data
45
+ if isinstance (data , str ):
46
+ return data .encode ()
47
+ return bt_serialize (data )
48
+
49
+
40
50
def _propagate_event (eventname , * args ):
41
51
""" propagate an event to everyone who cares about it """
42
52
assert event_name_valid (eventname )
43
53
global omq , _pools
44
54
sent = 0
45
55
for conn in _pools [eventname ]:
46
- omq .send (conn , f'sogs.event.{ eventname } ' , * (bt_serialize (a ) for a in args ))
56
+ omq .send (conn , f'sogs.event.{ eventname } ' , * (_maybe_serialize (a ) for a in args ))
47
57
sent += 1
48
58
if sent :
49
59
app .logger .info (f"sent { eventname } to { sent } subscribers" )
You can’t perform that action at this time.
0 commit comments