CheeseAPI 0.3.16__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. cheeseapi-0.4.0/CheeseAPI/__init__.py +7 -0
  2. cheeseapi-0.4.0/CheeseAPI/app.py +59 -0
  3. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/CheeseAPI/cors.py +2 -0
  4. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/CheeseAPI/exception.py +3 -3
  5. cheeseapi-0.4.0/CheeseAPI/file.py +31 -0
  6. cheeseapi-0.4.0/CheeseAPI/handle.py +743 -0
  7. cheeseapi-0.4.0/CheeseAPI/protocol.py +106 -0
  8. cheeseapi-0.4.0/CheeseAPI/request.py +70 -0
  9. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/CheeseAPI/response.py +68 -69
  10. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/CheeseAPI/route.py +11 -14
  11. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/CheeseAPI/server.py +12 -5
  12. cheeseapi-0.4.0/CheeseAPI/signal.py +58 -0
  13. cheeseapi-0.4.0/CheeseAPI/text.py +153 -0
  14. cheeseapi-0.4.0/CheeseAPI/websocket.py +23 -0
  15. cheeseapi-0.4.0/CheeseAPI/workspace.py +58 -0
  16. cheeseapi-0.4.0/PKG-INFO +168 -0
  17. cheeseapi-0.4.0/README.md +151 -0
  18. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/pyproject.toml +1 -1
  19. cheeseapi-0.3.16/CheeseAPI/__init__.py +0 -11
  20. cheeseapi-0.3.16/CheeseAPI/app.py +0 -125
  21. cheeseapi-0.3.16/CheeseAPI/file.py +0 -22
  22. cheeseapi-0.3.16/CheeseAPI/handle.py +0 -327
  23. cheeseapi-0.3.16/CheeseAPI/module.py +0 -36
  24. cheeseapi-0.3.16/CheeseAPI/protocol.py +0 -173
  25. cheeseapi-0.3.16/CheeseAPI/request.py +0 -60
  26. cheeseapi-0.3.16/CheeseAPI/signal.py +0 -50
  27. cheeseapi-0.3.16/CheeseAPI/websocket.py +0 -23
  28. cheeseapi-0.3.16/CheeseAPI/worker.py +0 -15
  29. cheeseapi-0.3.16/CheeseAPI/workspace.py +0 -31
  30. cheeseapi-0.3.16/PKG-INFO +0 -138
  31. cheeseapi-0.3.16/README.md +0 -121
  32. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/.gitignore +0 -0
  33. {cheeseapi-0.3.16 → cheeseapi-0.4.0}/LICENSE +0 -0
@@ -0,0 +1,7 @@
1
+ from CheeseAPI.app import app
2
+ from CheeseAPI.file import File
3
+ from CheeseAPI.request import Request
4
+ from CheeseAPI.response import Response, JsonResponse, FileResponse, BaseResponse
5
+ from CheeseAPI.route import Route
6
+ from CheeseAPI.websocket import WebsocketServer
7
+ from CheeseAPI.signal import Signal
@@ -0,0 +1,59 @@
1
+ import multiprocessing, os
2
+ from typing import Dict, Any, List
3
+
4
+ from CheeseAPI.text import Text
5
+ from CheeseAPI.server import Server
6
+ from CheeseAPI.workspace import Workspace
7
+ from CheeseAPI.handle import Handle
8
+ from CheeseAPI.signal import _Signal
9
+ from CheeseAPI.route import Route, RouteBus
10
+ from CheeseAPI.cors import Cors
11
+
12
+ class App:
13
+ def __init__(self):
14
+ self.server: Server = Server(self)
15
+ self.workspace: Workspace = Workspace(self)
16
+ self.signal: _Signal = _Signal(self)
17
+ self.managers: Dict[str, Any] = {}
18
+ self.g: Dict[str, Any] = {
19
+ 'startTime': None
20
+ }
21
+ self.route: Route = Route()
22
+ self.routeBus: RouteBus = RouteBus()
23
+ self.cors: Cors = Cors()
24
+
25
+ self.modules: List[str] = []
26
+ self.localModules: List[str] = []
27
+ self.exclude_localModules: List[str] = []
28
+ self.preferred_localModules: List[str] = []
29
+
30
+ self._text: Text = Text(self)
31
+ self._managers: Dict[str, Any] = {
32
+ 'server.workers': multiprocessing.Value('i', 0),
33
+ 'lock': multiprocessing.Lock()
34
+ }
35
+ self._handle: Handle = Handle(self)
36
+
37
+ # 初始化本地模块
38
+ for foldername in os.listdir(self.workspace.base):
39
+ if foldername[0] == '.' or foldername == '__pycache__':
40
+ continue
41
+
42
+ folderPath = os.path.join(self.workspace.base, foldername)
43
+ if not os.path.isdir(folderPath):
44
+ continue
45
+
46
+ staticPath = os.path.join(self.workspace.base, self.workspace.static)
47
+ if self.workspace.static and os.path.exists(staticPath) and os.path.samefile(folderPath, staticPath):
48
+ continue
49
+
50
+ logPath = os.path.join(self.workspace.base, self.workspace.log)
51
+ if self.workspace.log and os.path.exists(logPath) and os.path.samefile(folderPath, logPath):
52
+ continue
53
+
54
+ self.localModules.append(foldername)
55
+
56
+ def run(self):
57
+ self._handle.server_start()
58
+
59
+ app: App = App()
@@ -4,5 +4,7 @@ from typing import Set, Literal
4
4
  class Cors:
5
5
  def __init__(self):
6
6
  self.origin: Set[str] | Literal['*'] = '*'
7
+ self.exclude_origin: Set[str] = set()
7
8
  self.methods: Set[http.HTTPMethod] = set([ method for method in http.HTTPMethod ])
9
+ self.exclude_methods: Set[http.HTTPMethod] = set()
8
10
  self.headers: Set[str] | Literal['*'] = '*'
@@ -2,11 +2,11 @@ import sys, traceback, threading
2
2
 
3
3
  from CheeseLog import logger
4
4
 
5
- def sysExceptionHandle(*args, **kwargs):
5
+ def sysExceptionHandle(*args):
6
6
  try:
7
7
  raise args[1]
8
8
  except:
9
- logger.error(f'''The server exited with an error:
9
+ logger.error(f'''
10
10
  {logger.encode(traceback.format_exc()[:-1])}''')
11
11
 
12
12
  sys.excepthook = sysExceptionHandle
@@ -15,7 +15,7 @@ def threadException(*args, **kwargs):
15
15
  try:
16
16
  raise args[0][1]
17
17
  except:
18
- logger.danger(f'''The error occured in the {threading.currentThread().getName()}:
18
+ logger.danger(f'''
19
19
  {logger.encode(traceback.format_exc()[:-1])}''')
20
20
 
21
21
  threading.excepthook = threadException
@@ -0,0 +1,31 @@
1
+ import os
2
+ from typing import overload
3
+
4
+ class File:
5
+ @overload
6
+ def __init__(self, filePath: str):
7
+ ...
8
+
9
+ @overload
10
+ def __init__(self, name: str, data: bytes | str):
11
+ ...
12
+
13
+ def __init__(self, arg0: str, arg1: bytes | None = None):
14
+ from CheeseAPI.app import app
15
+
16
+ self.name: str
17
+ self.data: bytes
18
+
19
+ if arg1:
20
+ self.name = arg0
21
+ self.data = arg1
22
+ else:
23
+ self.name = arg0.split('/')[-1]
24
+ with open(arg0 if arg0[0] == '/' else os.path.join(app.workspace.base, arg0), 'rb') as f:
25
+ self.data = f.read()
26
+
27
+ def save(self, filePath: str):
28
+ from CheeseAPI.app import app
29
+
30
+ with open(filePath if filePath[0] == '/' else os.path.join(app.workspace.base, filePath), 'w') as f:
31
+ f.write(self.data)