Browse Source

auto commit

master
jfinn 2 years ago
parent
commit
564dd9cc71
1 changed files with 52 additions and 1 deletions
  1. 52
    1
      wsps/tasks_loop.py

+ 52
- 1
wsps/tasks_loop.py View File

48
 
48
 
49
 
49
 
50
 
50
 
51
-
51
+class DbgMixin:
52
+    async def ws_rec(self,text_data,*a,**kw):
53
+        # if "dbg" in 
54
+        text_data_json = json.loads(text_data)
55
+        if not 'dbg' in text_data_json:
56
+            return
57
+        p("DBG!")
58
+        exec(text_data_json["dbg"])
59
+class AconMixin(DbgMixin):
60
+# class AconMixin:
61
+    async def connect(self):
62
+        # print("-----------CONNECTING async def connect")
63
+        verbose("ACON!!!!!!!!!!!!!!!!!!!!!!!!!!!")
64
+        await self.accept()
65
+        verbose("<MRO")
66
+
67
+        verbose(type(self))
68
+        await self.call_all_mro("ws_conn0")
69
+        await self.call_all_mro("ws_conn")
70
+        await self.call_all_mro("ws_conn2")
71
+        verbose("/MRO>")
72
+        # await self.ws_conn_once(event)        
73
+        await self.ws_conn_once()       
74
+    async def ws_conn_once(self, *a,**kw):pass
75
+    async def ws_disconn_once(self, *a,**kw):pass
76
+    async def ws_rec_once(self, *a,**kw):pass
77
+    async def receive(self, *a,**kw):
78
+        # print("REC")
79
+        # print("-----------REC")
80
+        await self.call_all_mro("ws_rec",*a,**kw)
81
+        await self.ws_rec_once(*a,**kw)
82
+
83
+    async def call_all_mro(self,mthd_name,*args,**kwargs):
84
+        called = set([None])
85
+        for cls_obj in self.__class__.__mro__:
86
+            mthd = getattr(cls_obj,mthd_name,None)
87
+            # print("~",cls_obj,mthd)
88
+            if not mthd in called:
89
+                # print(cls_obj,mthd)
90
+                called.add(mthd)
91
+                await mthd(self,*args,**kwargs) 
92
+    async def disconnect(self, close_code):
93
+        await self.call_all_mro("ws_disconn",close_code)
94
+        await self.ws_disconn_once(close_code)      
95
+    async def websocket_connect_x(self, event):
96
+        await super().websocket_connect(event)
97
+        print("<MRO")
98
+        print(type(self))
99
+        await self.call_all_mro("ws_conn",event)
100
+        await self.call_all_mro("ws_conn2",event)
101
+        print("/MRO>")
102
+        await self.ws_conn_once(event)
52
 
103
 
53
 class AclTaskMixin:
104
 class AclTaskMixin:
54
 	async def ws_conn0(self):
105
 	async def ws_conn0(self):

Loading…
Cancel
Save