-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonLoaderCore.py
More file actions
41 lines (34 loc) · 1.33 KB
/
PythonLoaderCore.py
File metadata and controls
41 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import socket, json, importlib.util, sys
class KitX():
def __init__(self, host: str, port: int) -> None:
self.host = host
self.port = port
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.client.connect((self.host, self.port))
def SendMessage(self, message):
if isinstance(message, str):
self.client.sendall(message.encode("utf-8"))
else:
self.client.sendall(json.dumps(message).encode("utf-8"))
def __del__(self):
self.client.shutdown(socket.SHUT_RDWR)
self.client.close()
print("KitX socket closed.")
class Plugin():
def __init__(self, host: str, port: int, path: str, name:str) -> None:
self.path = path
self.name = name
self.KitX = KitX(host, port)
self.__load_module()
def __load_module(self):
if self.name is None:
self.name = self.path.replace('/', '_').replace('\\', '_').replace('.', '_')
spec = importlib.util.spec_from_file_location(self.name, self.path)
self.module = importlib.util.module_from_spec(spec) # type: ignore
sys.modules[self.name] = self.module
spec.loader.exec_module(self.module)
self.OnLoad()
def OnLoad(self):
self.module.OnLoad(self.KitX)
def OnUnLoad(self):
pass